Implemented all GET calls (but without parameters).

This commit is contained in:
tastytea 2018-01-12 20:49:15 +01:00
parent c4a509c42e
commit 9c018df528
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
6 changed files with 162 additions and 25 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project (mastodon-cpp
VERSION 0.0.1
VERSION 0.0.2
LANGUAGES CXX
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")

View File

@ -21,6 +21,7 @@ All versions below 1.0.0 (SOVERSION 0) are considered insecure, unstable and can
# Usage
Mastodon::API masto("social.example.com", "access token");
std::cout << masto.get(Mastodon::API::v1::timelines_home) << '\n';
std::cout << masto.get(Mastodon::API::v1::accounts_id, "12345") << '\n';
There is an example in `src/example`.
@ -30,6 +31,7 @@ There is an example in `src/example`.
* [ ] Implement all GET methods
* [ ] Proper error handling
* [x] Network stuff
* [ ] Comprehensive example
* Version 0.2.0
* [ ] Implement all PATCH methods
* [ ] Implement all POST methods
@ -54,42 +56,59 @@ There is an example in `src/example`.
* [x] GET /api/v1/accounts/relationships
* [x] GET /api/v1/accounts/search
* [ ] POST /api/v1/apps
* [ ] GET /api/v1/blocks
* [ ] GET /api/v1/favourites
* [ ] GET /api/v1/follow_requests
* [x] GET /api/v1/blocks
* [x] GET /api/v1/domain_blocks
* [ ] POST /api/v1/domain_blocks
* [ ] DELETE /api/v1/domain_blocks
* [x] GET /api/v1/favourites
* [x] GET /api/v1/follow_requests
* [ ] POST /api/v1/follow_requests/:id/authorize
* [ ] POST /api/v1/follow_requests/:id/reject
* [ ] POST /api/v1/follows
* [ ] GET /api/v1/instance
* [x] GET /api/v1/instance
* [x] GET /api/v1/custom_emojis
* [x] GET /api/v1/lists
* [x] GET /api/v1/accounts/:id/lists
* [x] GET /api/v1/lists/:id/accounts
* [x] GET /api/v1/lists/:id
* [ ] POST /api/v1/lists
* [ ] PUT /api/v1/lists/:id
* [ ] DELETE /api/v1/lists/:id
* [ ] POST /api/v1/lists/:id/accounts
* [ ] DELETE /api/v1/lists/:id/accounts
* [ ] POST /api/v1/media
* [ ] GET /api/v1/mutes
* [ ] GET /api/v1/notifications
* [ ] GET /api/v1/notifications/:id
* [x] GET /api/v1/mutes
* [x] GET /api/v1/notifications
* [x] GET /api/v1/notifications/:id
* [ ] POST /api/v1/notifications/clear
* [ ] GET /api/v1/reports
* [ ] POST /api/v1/notifications/dismiss
* [x] GET /api/v1/reports
* [ ] POST /api/v1/reports
* [ ] GET /api/v1/search
* [ ] GET /api/v1/statuses/:id
* [ ] GET /api/v1/statuses/:id/context
* [ ] GET /api/v1/statuses/:id/card
* [ ] GET /api/v1/statuses/:id/reblogged_by
* [ ] GET /api/v1/statuses/:id/favourited_by
* [x] GET /api/v1/search
* [x] GET /api/v1/statuses/:id
* [x] GET /api/v1/statuses/:id/context
* [x] GET /api/v1/statuses/:id/card
* [x] GET /api/v1/statuses/:id/reblogged_by
* [x] GET /api/v1/statuses/:id/favourited_by
* [ ] POST /api/v1/statuses
* [ ] DELETE /api/v1/statuses/:id
* [ ] POST /api/v1/statuses/:id/reblog
* [ ] POST /api/v1/statuses/:id/unreblog
* [ ] POST /api/v1/statuses/:id/favourite
* [ ] POST /api/v1/statuses/:id/unfavourite
* [ ] GET /api/v1/timelines/home
* [ ] GET /api/v1/timelines/public
* [ ] GET /api/v1/timelines/tag/:hashtag
* [ ] GET /api/v1/timelines/list/:list_id
* [ ] POST /api/v1/statuses/:id/pin
* [ ] POST /api/v1/statuses/:id/unpin
* [ ] POST /api/v1/statuses/:id/mute
* [ ] POST /api/v1/statuses/:id/unmute
* [x] GET /api/v1/timelines/home
* [x] GET /api/v1/timelines/public
* [x] GET /api/v1/timelines/tag/:hashtag
* [x] GET /api/v1/timelines/list/:list_id
[Full reference](https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md)
# Copyright
Copyright © 2018 tastytea <tastytea@tastytea.de>.
License GPLv3: GNU GPL version 3 <https://www.gnu.org/licenses/gpl-3.0.html>.
This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
# Bugs & feature requests
Via [E-Mail](mailto:bugs -AT- tastytea.de) or [XMPP](xmpp:tastytea -AT- tastytea.de?message).

View File

@ -37,8 +37,45 @@ const string API::get(const Mastodon::API::v1 &call,
case v1::accounts_verify_credentials:
strcall = "/api/v1/accounts/verify_credentials";
break;
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;
default:
cerr << "ERROR: Invalid call.\n";
return "";
break;
}
@ -78,6 +115,42 @@ const string API::get(const Mastodon::API::v1 &call,
case v1::accounts_search:
strcall = "/api/v1/accounts/search?q=" + argument;
break;
case v1::accounts_id_lists:
strcall = "/api/v1/accounts/" + argument + "/lists";
break;
case v1::lists_id_accounts:
strcall = "/api/v1/lists/" + argument + "/accounts";
break;
case v1::lists_id:
strcall = "/api/v1/lists/" + argument;
break;
case v1::notifications_id:
strcall = "/api/v1/notifications/" + argument;
break;
case v1::search:
strcall = "/api/v1/search?q=" + argument;
break;
case v1::statuses_id:
strcall = "/api/v1/statuses/" + argument;
break;
case v1::statuses_id_context:
strcall = "/api/v1/statuses/" + argument + "/context";
break;
case v1::statuses_id_card:
strcall = "/api/v1/statuses/" + argument + "/card";
break;
case v1::statuses_id_reblogged_by:
strcall = "/api/v1/statuses/" + argument + "/reblogged_by";
break;
case v1::statuses_id_favourited_by:
strcall = "/api/v1/statuses/" + argument + "/favourited_by";
break;
case v1::timelines_tag_hashtag:
strcall = "/api/v1/timelines/tag/" + argument;
break;
case v1::timelines_list_list_id:
strcall = "/api/v1/timelines/list/" + argument;
break;
default:
cerr << "ERROR: Invalid call.\n";
return "";

View File

@ -4,6 +4,8 @@
#include <iostream>
#include "../mastodon-cpp.hpp"
using Mastodon::API;
int main(int argc, char *argv[])
{
if (argc < 3)
@ -14,6 +16,5 @@ int main(int argc, char *argv[])
Mastodon::API masto(argv[1], argv[2]);
std::cout << masto.get(Mastodon::API::v1::accounts_id,
"44897") << '\n';
std::cout << masto.get(API::v1::timelines_tag_hashtag, "FOSS") << '\n';
}

View File

@ -36,7 +36,31 @@ namespace Mastodon
accounts_id_following,
accounts_id_statuses,
accounts_relationships,
accounts_search
accounts_search,
blocks,
domain_blocks,
favourites,
follow_requests,
instance,
custom_emojis,
lists,
accounts_id_lists,
lists_id_accounts,
lists_id,
mutes,
notifications,
notifications_id,
reports,
search,
statuses_id,
statuses_id_context,
statuses_id_card,
statuses_id_reblogged_by,
statuses_id_favourited_by,
timelines_home,
timelines_public,
timelines_tag_hashtag,
timelines_list_list_id
};
explicit API(const std::string &instance,

View File

@ -0,0 +1,20 @@
/* This file is part of mastodon-cpp.
*/
#include <iostream>
#include "../mastodon-cpp.hpp"
int main(int argc, char *argv[])
{
Mastodon::API test("soc.ialis.me", "");
std::string answer = test.get(Mastodon::API::v1::instance);
if (answer.substr(7, 14) == "\"soc.ialis.me\"")
{
return 0;
}
else
{
return 1;
}
}