From 4372f3249c46914a0bd86f97502ca4ba3f29e704 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 5 Mar 2018 12:12:58 +0100 Subject: [PATCH] Added example for simplifying the interface, renamed examples --- CMakeLists.txt | 2 +- README.md | 2 + ..._dump_json.cpp => example01_dump_json.cpp} | 0 ...ccount.cpp => example02_parse_account.cpp} | 0 ..._mastocron.cpp => example03_mastocron.cpp} | 0 ...s.cpp => example04_update_credentials.cpp} | 0 ...llow.cpp => example05_follow_unfollow.cpp} | 0 ...oot.cpp => example06_toot_delete-toot.cpp} | 0 ...ter_app.cpp => example07_register_app.cpp} | 0 ...miting.cpp => example08_rate_limiting.cpp} | 0 ...ng_api.cpp => example09_streaming_api.cpp} | 0 src/examples/example10_simplify.cpp | 53 +++++++++++++++++++ src/mastodon-cpp.hpp | 19 +++---- 13 files changed, 66 insertions(+), 10 deletions(-) rename src/examples/{example1_dump_json.cpp => example01_dump_json.cpp} (100%) rename src/examples/{example2_parse_account.cpp => example02_parse_account.cpp} (100%) rename src/examples/{example3_mastocron.cpp => example03_mastocron.cpp} (100%) rename src/examples/{example4_update_credentials.cpp => example04_update_credentials.cpp} (100%) rename src/examples/{example5_follow_unfollow.cpp => example05_follow_unfollow.cpp} (100%) rename src/examples/{example6_toot_delete-toot.cpp => example06_toot_delete-toot.cpp} (100%) rename src/examples/{example7_register_app.cpp => example07_register_app.cpp} (100%) rename src/examples/{example8_rate_limiting.cpp => example08_rate_limiting.cpp} (100%) rename src/examples/{example9_streaming_api.cpp => example09_streaming_api.cpp} (100%) create mode 100644 src/examples/example10_simplify.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c4d953..ca06394 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (mastodon-cpp - VERSION 0.5.0 + VERSION 0.5.1 LANGUAGES CXX ) diff --git a/README.md b/README.md index 8e92319..1962e1e 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,8 @@ If you use a debug build, you get more verbose error messages. ## Status of implementation +Feature complete as of Mastodon 2.2.0 + * [x] GET /api/v1/accounts/:id * [x] GET /api/v1/accounts/verify_credentials * [x] PATCH /api/v1/accounts/update_credentials diff --git a/src/examples/example1_dump_json.cpp b/src/examples/example01_dump_json.cpp similarity index 100% rename from src/examples/example1_dump_json.cpp rename to src/examples/example01_dump_json.cpp diff --git a/src/examples/example2_parse_account.cpp b/src/examples/example02_parse_account.cpp similarity index 100% rename from src/examples/example2_parse_account.cpp rename to src/examples/example02_parse_account.cpp diff --git a/src/examples/example3_mastocron.cpp b/src/examples/example03_mastocron.cpp similarity index 100% rename from src/examples/example3_mastocron.cpp rename to src/examples/example03_mastocron.cpp diff --git a/src/examples/example4_update_credentials.cpp b/src/examples/example04_update_credentials.cpp similarity index 100% rename from src/examples/example4_update_credentials.cpp rename to src/examples/example04_update_credentials.cpp diff --git a/src/examples/example5_follow_unfollow.cpp b/src/examples/example05_follow_unfollow.cpp similarity index 100% rename from src/examples/example5_follow_unfollow.cpp rename to src/examples/example05_follow_unfollow.cpp diff --git a/src/examples/example6_toot_delete-toot.cpp b/src/examples/example06_toot_delete-toot.cpp similarity index 100% rename from src/examples/example6_toot_delete-toot.cpp rename to src/examples/example06_toot_delete-toot.cpp diff --git a/src/examples/example7_register_app.cpp b/src/examples/example07_register_app.cpp similarity index 100% rename from src/examples/example7_register_app.cpp rename to src/examples/example07_register_app.cpp diff --git a/src/examples/example8_rate_limiting.cpp b/src/examples/example08_rate_limiting.cpp similarity index 100% rename from src/examples/example8_rate_limiting.cpp rename to src/examples/example08_rate_limiting.cpp diff --git a/src/examples/example9_streaming_api.cpp b/src/examples/example09_streaming_api.cpp similarity index 100% rename from src/examples/example9_streaming_api.cpp rename to src/examples/example09_streaming_api.cpp diff --git a/src/examples/example10_simplify.cpp b/src/examples/example10_simplify.cpp new file mode 100644 index 0000000..1cd9195 --- /dev/null +++ b/src/examples/example10_simplify.cpp @@ -0,0 +1,53 @@ +/* This file is part of mastodon-cpp. + * Simplify the interface + */ + + +#include +#include +#include +#include "../mastodon-cpp.hpp" + +using Mastodon::API; + +class EasyToot : public Mastodon::API +{ +public: + explicit EasyToot(const std::string &instance, const std::string &access_token) + : API(instance, access_token) + {} + + std::uint16_t toot(const std::string &text, const std::string &cw = "") + { + std::string answer; + API::parametermap parameters; + parameters.insert({ "status", { text } } ); + if (!cw.empty()) + { + parameters.insert({ "spoiler_text", { cw } } ); + } + + return post(API::v1::statuses, parameters, answer); + } +}; + +int main(int argc, char *argv[]) +{ + if (argc < 3) + { + std::cerr << "usage: " << argv[0] << " \n"; + return 1; + } + + std::string answer; + std::uint16_t ret = 0; + EasyToot masto(argv[1], argv[2]); + + masto.toot("Test"); + if (ret != 0) + { + std::cerr << "Error: " << ret << '\n'; + } + + return ret; +} diff --git a/src/mastodon-cpp.hpp b/src/mastodon-cpp.hpp index 8605384..56fd217 100644 --- a/src/mastodon-cpp.hpp +++ b/src/mastodon-cpp.hpp @@ -26,15 +26,16 @@ #include /*! - * @example example1_dump_json.cpp - * @example example2_parse_account.cpp - * @example example3_mastocron.cpp - * @example example4_update_credentials.cpp - * @example example5_follow_unfollow.cpp - * @example example6_toot_delete-toot.cpp - * @example example7_register_app.cpp - * @example example8_rate_limiting.cpp - * @example example9_streaming_api.cpp + * @example example01_dump_json.cpp + * @example example02_parse_account.cpp + * @example example03_mastocron.cpp + * @example example04_update_credentials.cpp + * @example example05_follow_unfollow.cpp + * @example example06_toot_delete-toot.cpp + * @example example07_register_app.cpp + * @example example08_rate_limiting.cpp + * @example example09_streaming_api.cpp + * @example example10_simplify.cpp */ namespace Mastodon {