This repository has been archived on 2020-04-18. You can view files and clone it, but cannot push or open issues or pull requests.
FediPotato/lib/src/account_mastodon.cpp

101 lines
2.6 KiB
C++

/* This file is part of FediPotato.
* Copyright © 2020 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "account_mastodon.hpp"
#include "version.hpp"
#include <exception>
#include <stdexcept>
namespace FediPotato
{
using std::logic_error;
using std::runtime_error;
MastodonAPI::MastodonAPI(const string_view application_name,
const string_view account_name,
const Config &globalconfig)
: _config{application_name, string{account_name} += ".json"}
, _instance{_config.get("instance"), _config.get("access_token")}
{
_instance.set_useragent(((string(application_name)
+= " (FediPotato/") += version) += ')');
_instance.set_proxy(globalconfig.get("proxy"));
}
void MastodonAPI::start_stream(const stream_type type,
const optional<string_view> id)
{
const string strid{get_stream_id(type, id)};
}
void MastodonAPI::stop_stream(const stream_type type,
const optional<string_view> id)
{
const string strid{get_stream_id(type, id)};
}
string MastodonAPI::get_stream_id(const stream_type type,
const optional<string_view> id)
{
switch (type)
{
case stream_type::home_tl:
{
return "home";
break;
}
case stream_type::instance_tl:
{
return "instance";
break;
}
case stream_type::federated_tl:
{
return "federated";
break;
}
case stream_type::conversations:
{
return "conversations";
break;
}
case stream_type::hashtag:
{
if (!id)
{
throw runtime_error{"No hashtag given."};
}
return string("hashtag_") += id.value();
break;
}
case stream_type::list:
{
if (!id)
{
throw runtime_error{"No list ID given."};
}
return string("list_") += id.value();
break;
}
}
throw logic_error{"Unhandled stream type."};
}
} // namespace FediPotato