2018-01-09 22:12:11 +01:00
|
|
|
/* This file is part of mastodon-cpp.
|
|
|
|
* Copyright © 2018 tastytea <tastytea@tastytea.de>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
2018-01-13 16:07:00 +01:00
|
|
|
#include "macros.hpp"
|
2018-01-09 22:12:11 +01:00
|
|
|
#include "mastodon-cpp.hpp"
|
|
|
|
|
|
|
|
using namespace Mastodon;
|
|
|
|
using std::cerr;
|
2018-02-26 07:57:30 +01:00
|
|
|
|
2018-04-02 01:47:44 +02:00
|
|
|
const uint_fast16_t API::get(const Mastodon::API::v1 &call,
|
|
|
|
const parametermap ¶meters, string &answer)
|
2018-01-09 22:12:11 +01:00
|
|
|
{
|
2018-01-10 18:19:19 +01:00
|
|
|
string strcall = "";
|
2018-04-19 00:20:43 +02:00
|
|
|
string strid = "";
|
|
|
|
|
|
|
|
// The ID is part of the path
|
|
|
|
const auto &it = parameters.find("id");
|
|
|
|
if (it != parameters.end())
|
|
|
|
{
|
|
|
|
strid = it->second[0];
|
|
|
|
}
|
|
|
|
|
2018-01-10 18:19:19 +01:00
|
|
|
switch (call)
|
2018-01-09 22:12:11 +01:00
|
|
|
{
|
|
|
|
case v1::accounts_verify_credentials:
|
2018-01-10 18:19:19 +01:00
|
|
|
strcall = "/api/v1/accounts/verify_credentials";
|
2018-01-09 22:12:11 +01:00
|
|
|
break;
|
2018-01-12 20:49:15 +01:00
|
|
|
case v1::blocks:
|
|
|
|
strcall = "/api/v1/blocks";
|
|
|
|
break;
|
|
|
|
case v1::domain_blocks:
|
|
|
|
strcall = "/api/v1/domain_blocks";
|
|
|
|
break;
|
|
|
|
case v1::favourites:
|
|
|
|
strcall = "/api/v1/favourites";
|
|
|
|
break;
|
|
|
|
case v1::follow_requests:
|
|
|
|
strcall = "/api/v1/follow_requests";
|
|
|
|
break;
|
|
|
|
case v1::instance:
|
|
|
|
strcall = "/api/v1/instance";
|
|
|
|
break;
|
|
|
|
case v1::custom_emojis:
|
|
|
|
strcall = "/api/v1/custom_emojis";
|
|
|
|
break;
|
|
|
|
case v1::lists:
|
|
|
|
strcall = "/api/v1/lists";
|
|
|
|
break;
|
|
|
|
case v1::mutes:
|
|
|
|
strcall = "/api/v1/mutes";
|
|
|
|
break;
|
|
|
|
case v1::notifications:
|
|
|
|
strcall = "/api/v1/notifications";
|
|
|
|
break;
|
|
|
|
case v1::reports:
|
|
|
|
strcall = "/api/v1/reports";
|
|
|
|
break;
|
|
|
|
case v1::timelines_home:
|
|
|
|
strcall = "/api/v1/timelines/home";
|
|
|
|
break;
|
|
|
|
case v1::timelines_public:
|
|
|
|
strcall = "/api/v1/timelines/public";
|
|
|
|
break;
|
2018-03-13 15:07:14 +01:00
|
|
|
case v1::accounts_relationships:
|
|
|
|
strcall = "/api/v1/accounts/relationships";
|
|
|
|
break;
|
2018-01-09 22:12:11 +01:00
|
|
|
case v1::accounts_id:
|
2018-04-19 00:20:43 +02:00
|
|
|
strcall = "/api/v1/accounts/" + strid;
|
2018-01-09 22:12:11 +01:00
|
|
|
break;
|
|
|
|
case v1::accounts_id_followers:
|
2018-04-19 00:20:43 +02:00
|
|
|
strcall = "/api/v1/accounts/" + strid + "/followers";
|
2018-01-09 22:12:11 +01:00
|
|
|
break;
|
|
|
|
case v1::accounts_id_following:
|
2018-04-19 00:20:43 +02:00
|
|
|
strcall = "/api/v1/accounts/" + strid + "/following";
|
2018-01-09 22:12:11 +01:00
|
|
|
break;
|
|
|
|
case v1::accounts_id_statuses:
|
2018-04-19 00:20:43 +02:00
|
|
|
strcall = "/api/v1/accounts/" + strid + "/statuses";
|
2018-01-09 22:12:11 +01:00
|
|
|
break;
|
|
|
|
case v1::accounts_search:
|
2018-04-19 00:20:43 +02:00
|
|
|
strcall = "/api/v1/accounts/search";
|
2018-01-09 22:12:11 +01:00
|
|
|
break;
|
2018-01-12 20:49:15 +01:00
|
|
|
case v1::accounts_id_lists:
|
2018-04-19 00:20:43 +02:00
|
|
|
strcall = "/api/v1/accounts/" + strid + "/lists";
|
2018-01-12 20:49:15 +01:00
|
|
|
break;
|
|
|
|
case v1::lists_id_accounts:
|
2018-04-19 00:20:43 +02:00
|
|
|
strcall = "/api/v1/lists/" + strid + "/accounts";
|
2018-01-12 20:49:15 +01:00
|
|
|
break;
|
|
|
|
case v1::lists_id:
|
2018-04-19 00:20:43 +02:00
|
|
|
strcall = "/api/v1/lists/" + strid;
|
2018-01-12 20:49:15 +01:00
|
|
|
break;
|
|
|
|
case v1::notifications_id:
|
2018-04-19 00:20:43 +02:00
|
|
|
strcall = "/api/v1/notifications/" + strid;
|
2018-01-12 20:49:15 +01:00
|
|
|
break;
|
|
|
|
case v1::search:
|
2018-04-19 00:20:43 +02:00
|
|
|
strcall = "/api/v1/search";
|
2018-01-12 20:49:15 +01:00
|
|
|
break;
|
|
|
|
case v1::statuses_id:
|
2018-04-19 00:20:43 +02:00
|
|
|
strcall = "/api/v1/statuses/" + strid;
|
2018-01-12 20:49:15 +01:00
|
|
|
break;
|
|
|
|
case v1::statuses_id_context:
|
2018-04-19 00:20:43 +02:00
|
|
|
strcall = "/api/v1/statuses/" + strid + "/context";
|
2018-01-12 20:49:15 +01:00
|
|
|
break;
|
|
|
|
case v1::statuses_id_card:
|
2018-04-19 00:20:43 +02:00
|
|
|
strcall = "/api/v1/statuses/" + strid + "/card";
|
2018-01-12 20:49:15 +01:00
|
|
|
break;
|
|
|
|
case v1::statuses_id_reblogged_by:
|
2018-04-19 00:20:43 +02:00
|
|
|
strcall = "/api/v1/statuses/" + strid + "/reblogged_by";
|
2018-01-12 20:49:15 +01:00
|
|
|
break;
|
|
|
|
case v1::statuses_id_favourited_by:
|
2018-04-19 00:20:43 +02:00
|
|
|
strcall = "/api/v1/statuses/" + strid + "/favourited_by";
|
2018-01-12 20:49:15 +01:00
|
|
|
break;
|
|
|
|
case v1::timelines_tag_hashtag:
|
2018-04-19 00:20:43 +02:00
|
|
|
{
|
|
|
|
// The hashtag is part of the path
|
|
|
|
const auto &it = parameters.find("hashtag");
|
|
|
|
if (it != parameters.end())
|
|
|
|
{
|
|
|
|
strcall = "/api/v1/timelines/tag/" + urlencode(it->second[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ttdebug << "ERROR: Invalid call.\n";
|
|
|
|
return 11;
|
|
|
|
}
|
|
|
|
}
|
2018-01-12 20:49:15 +01:00
|
|
|
break;
|
|
|
|
case v1::timelines_list_list_id:
|
2018-04-19 00:20:43 +02:00
|
|
|
strcall = "/api/v1/timelines/list/" + strid;
|
2018-01-12 20:49:15 +01:00
|
|
|
break;
|
2018-01-09 22:12:11 +01:00
|
|
|
default:
|
2018-01-13 16:07:00 +01:00
|
|
|
ttdebug << "ERROR: Invalid call.\n";
|
2018-02-28 22:37:30 +01:00
|
|
|
return 11;
|
2018-01-09 22:12:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-01-13 00:34:16 +01:00
|
|
|
if (parameters.size() > 0)
|
|
|
|
{
|
2018-04-19 00:20:43 +02:00
|
|
|
// Delete the parameters that are already in strcall
|
|
|
|
parametermap newparameters = parameters;
|
|
|
|
newparameters.erase("id");
|
|
|
|
newparameters.erase("hashtag");
|
|
|
|
strcall += maptostr(newparameters);
|
2018-01-13 00:34:16 +01:00
|
|
|
}
|
|
|
|
|
2018-04-19 00:20:43 +02:00
|
|
|
return get(strcall, answer);
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint_fast16_t API::get(const Mastodon::API::v1 &call, string &answer)
|
|
|
|
{
|
|
|
|
const parametermap p;
|
|
|
|
return get(call, p, answer);
|
2018-01-09 22:12:11 +01:00
|
|
|
}
|
|
|
|
|
2018-04-02 01:47:44 +02:00
|
|
|
const uint_fast16_t API::get(const std::string &call, string &answer)
|
2018-01-09 22:12:11 +01:00
|
|
|
{
|
2018-03-13 14:37:44 +01:00
|
|
|
return _http.request(http::method::GET, call, answer);
|
2018-01-09 22:12:11 +01:00
|
|
|
}
|
2018-04-19 00:20:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ↓↓ DEPRECATED ↓↓
|
|
|
|
|
|
|
|
const uint_fast16_t API::get(const Mastodon::API::v1 &call,
|
|
|
|
const string &argument,
|
|
|
|
const parametermap ¶meters, string &answer)
|
|
|
|
{
|
|
|
|
parametermap newparameters = parameters;
|
|
|
|
|
|
|
|
// Emulate old behaviour
|
|
|
|
switch (call)
|
|
|
|
{
|
|
|
|
case v1::search:
|
|
|
|
case v1::accounts_search:
|
|
|
|
newparameters["q"] = { argument };
|
|
|
|
break;
|
|
|
|
case v1::timelines_tag_hashtag:
|
|
|
|
newparameters["hashtag"] = { argument };
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
newparameters["id"] = { argument };
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return get(call, newparameters, answer);
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint_fast16_t API::get(const Mastodon::API::v1 &call,
|
|
|
|
const string &argument, string &answer)
|
|
|
|
{
|
|
|
|
const parametermap p;
|
|
|
|
return get(call, argument, p, answer);
|
|
|
|
}
|