From 5dce94a4a3196b69d9142c7a2b5427fb048e6a5c Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 13 Oct 2019 17:39:49 +0200 Subject: [PATCH] Add Emoji example. --- examples/example04_list_custom_emojis.cpp | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 examples/example04_list_custom_emojis.cpp diff --git a/examples/example04_list_custom_emojis.cpp b/examples/example04_list_custom_emojis.cpp new file mode 100644 index 0000000..b846e5b --- /dev/null +++ b/examples/example04_list_custom_emojis.cpp @@ -0,0 +1,48 @@ +// This file is part of mastodon-cpp. +// Prints shortcode + URL for each custom emoji. + +// Don't compile this if the Easy-interface is turned off +#ifndef WITHOUT_EASY + +#include +#include +#include +#include "mastodon-cpp.hpp" +#include "easy/all.hpp" + +using std::string; +using std::vector; +using namespace Mastodon; + +int main(int argc, char *argv[]) +{ + const vector args(argv, argv + argc); + if (args.size() < 2) + { + std::cerr << "usage: " << args[0] << " \n"; + return 1; + } + + // Construct a Mastodon::Easy object. + Easy::API masto(args[1], ""); + const return_call ret = masto.get(API::v1::custom_emojis); + + // Convert JSON array into vector of strings. + for (const string &str : Easy::json_array_to_vector(ret)) + { + // Construct Emoji object from string. + const Easy::Emoji emoji(str); + std::cout << ':' << emoji.shortcode() << ": <" << emoji.url() << ">\n"; + } + + return 0; +} + +#else +#include +int main() +{ + std::cout << "mastodon-cpp was compiled without Easy support.\n"; + return 255; +} +#endif // WITHOUT_EASY