From 8a0f709a6e3b6fd4bae4d6fc9a4741fe5451ae1f Mon Sep 17 00:00:00 2001 From: tastytea Date: Tue, 4 Dec 2018 10:34:51 +0100 Subject: [PATCH] Added support vor bookmarks (Glitch-Soc) --- README.md | 6 ++-- examples/example17_bookmarks.cpp | 55 ++++++++++++++++++++++++++++++++ src/api/get.cpp | 3 ++ src/api/post.cpp | 6 ++++ src/mastodon-cpp.hpp | 6 +++- 5 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 examples/example17_bookmarks.cpp diff --git a/README.md b/README.md index 296b01a..124f611 100644 --- a/README.md +++ b/README.md @@ -262,9 +262,9 @@ Feature complete as of Mastodon 2.6.1 * [x] max_toot_chars in /api/v1/instance -* [ ] GET /api/v1/bookmarks -* [ ] POST /api/v1/statuses/:id/bookmark -* [ ] POST /api/v1/statuses/:id/underbookmark +* [x] GET /api/v1/bookmarks +* [x] POST /api/v1/statuses/:id/bookmark +* [x] POST /api/v1/statuses/:id/unbookmark # Copyright diff --git a/examples/example17_bookmarks.cpp b/examples/example17_bookmarks.cpp new file mode 100644 index 0000000..7677a68 --- /dev/null +++ b/examples/example17_bookmarks.cpp @@ -0,0 +1,55 @@ +/* This file is part of mastodon-cpp. + * Print the first 20 characters from every bookmark (Glitch-Soc only). + */ + +// Don't compile this if the Easy-interface is turned off +#ifndef WITHOUT_EASY + +#include +#include +#include +#include +#ifdef MASTODON_CPP + #include "mastodon-cpp.hpp" + #include "easy/all.hpp" +#else + #include + #include +#endif + +using std::cout; +using Mastodon::API; +using Mastodon::Easy; + +int main(int argc, char *argv[]) +{ + if (argc < 3) + { + std::cerr << "usage: " << argv[0] << " \n"; + return 1; + } + + Easy masto(argv[1], argv[2]); + std::string answer; + std::uint16_t ret; + ret = masto.get(API::v1::bookmarks, answer); + + cout << "Return code: " << ret << '\n'; + + std::vector statuses = Easy::json_array_to_vector(answer); + for (const string &json : statuses) + { + cout << Easy::Status(json).content().substr(0, 20) << '\n'; + } + + return 0; +} + +#else +#include +int main() +{ + printf("mastodon-cpp was compiled without Easy support.\n"); + return 255; +} +#endif // WITHOUT_EASY diff --git a/src/api/get.cpp b/src/api/get.cpp index dc71342..7b24c78 100644 --- a/src/api/get.cpp +++ b/src/api/get.cpp @@ -147,6 +147,9 @@ const uint_fast16_t API::get(const Mastodon::API::v1 &call, case v1::endorsements: strcall = "/api/v1/endorsements"; break; + case v1::bookmarks: + strcall = "/api/v1/bookmarks"; + break; default: ttdebug << "ERROR: Invalid call.\n"; return 11; diff --git a/src/api/post.cpp b/src/api/post.cpp index 0cb6667..2489d64 100644 --- a/src/api/post.cpp +++ b/src/api/post.cpp @@ -122,6 +122,12 @@ const uint_fast16_t API::post(const Mastodon::API::v1 &call, case v1::accounts_id_unpin: strcall = "/api/v1/accounts/" + strid + "/unpin"; break; + case v1::statuses_id_bookmark: + strcall = "/api/v1/statuses/" + strid + "/bookmark"; + break; + case v1::statuses_id_unbookmark: + strcall = "/api/v1/statuses/" + strid + "/unbookmark"; + break; default: ttdebug << "ERROR: Invalid call.\n"; return 11; diff --git a/src/mastodon-cpp.hpp b/src/mastodon-cpp.hpp index 3af9875..6d9001d 100644 --- a/src/mastodon-cpp.hpp +++ b/src/mastodon-cpp.hpp @@ -265,7 +265,11 @@ public: streaming_hashtag, streaming_list, // Push - push_subscription + push_subscription, + // Glitch-Soc + bookmarks, + statuses_id_bookmark, + statuses_id_unbookmark }; /*!