From 3423e7f6722e68be80c3faa1b3aac5c51236a533 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 11 Jun 2018 01:39:19 +0200 Subject: [PATCH] Added Easy::Tag::History --- README.md | 4 +-- src/easy/entities/tag.cpp | 53 +++++++++++++++++++++++++++++++++++++++ src/easy/entities/tag.hpp | 50 ++++++++++++++++++++++++++++++++++-- 3 files changed, 103 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 762fb67..d1d0e16 100644 --- a/README.md +++ b/README.md @@ -201,7 +201,7 @@ Run `make package` from the build directory to generate a tar.gz archive. # Status of implementation -Feature complete as of Mastodon 2.4.0 +Feature complete as of Mastodon 2.4.1 * [x] GET /api/v1/accounts/:id * [x] GET /api/v1/accounts/verify_credentials @@ -276,7 +276,7 @@ Feature complete as of Mastodon 2.4.0 * [x] GET /api/v1/push/subscription * [x] PUT /api/v1/push/subscription * [x] DELETE /api/v1/push/subscription - * [ ] GET /api/v2/search + * [x] GET /api/v2/search # Copyright diff --git a/src/easy/entities/tag.cpp b/src/easy/entities/tag.cpp index 4ab6402..47dcbfb 100644 --- a/src/easy/entities/tag.cpp +++ b/src/easy/entities/tag.cpp @@ -14,7 +14,10 @@ * along with this program. If not, see . */ +#include +#include #include "tag.hpp" +#include "macros.hpp" using namespace Mastodon; using Tag = Easy::Tag; @@ -36,3 +39,53 @@ const string Tag::url() const { return get_string("url"); } + +const std::vector Tag::history() const +{ + const Json::Value node = get("history"); + if (node.isArray()) + { + std::vector vec; + for (const Json::Value &value : node) + { + vec.push_back(Easy::Tag::History(value.toStyledString())); + } + return vec; + } + + ttdebug << "Could not get data: history\n"; + return {}; +} + + +Tag::History::History(const string &json) +: Entity(json) +{} + +Tag::History::History() +: Entity() +{} + +const uint_fast64_t Tag::History::accounts() +{ + return stouint64(get_string("accounts")); +} + +const system_clock::time_point Tag::History::day() +{ + const Json::Value node = get("day"); + + if (node.isString()) + { + std::chrono::seconds seconds(stouint64(node.asString())); + return system_clock::time_point(seconds); + } + + ttdebug << "Could not get data: day\n"; + return system_clock::time_point(); +} + +const uint_fast64_t Tag::History::uses() +{ + return stouint64(get_string("uses")); +} diff --git a/src/easy/entities/tag.hpp b/src/easy/entities/tag.hpp index 032f928..f093328 100644 --- a/src/easy/entities/tag.hpp +++ b/src/easy/entities/tag.hpp @@ -18,6 +18,8 @@ #define MASTODON_CPP_EASY_TAG_HPP #include +#include +#include // If we are compiling mastodon-cpp, use another include path #ifdef MASTODON_CPP @@ -29,6 +31,8 @@ #endif using std::string; +using std::chrono::system_clock; +using std::uint_fast64_t; namespace Mastodon { @@ -38,6 +42,41 @@ namespace Mastodon class Easy::Tag : public Easy::Entity { public: + /*! + * @brief Class to hold Tag history + * + * @since 0.16.0 + */ + class History : public Easy::Entity + { + public: + /*! + * @brief Constructs an Tag::History object from a JSON string. + * + * @param json JSON string + */ + explicit History(const string &json); + /*! + * @brief Constructs an empty Tag::History object. + */ + History(); + + /*! + * @brief Returns the number of accounts using that hashtag. + */ + const uint_fast64_t accounts(); + + /*! + * @brief Returns the day. + */ + const system_clock::time_point day(); + + /*! + * @brief Returns the number of accounts using that hashtag. + */ + const uint_fast64_t uses(); + }; + /*! * @brief Constructs an Tag object from a JSON string. * @@ -51,14 +90,21 @@ namespace Mastodon Tag(); /*! - * @brief Returns the name of the application + * @brief Returns the name of the tag */ const string name() const; /*! - * @brief Returns the URL of the application + * @brief Returns the URL of the tag */ const string url() const; + + /*! + * @brief Returns the history of the tag + * + * @since 0.16.0 + */ + const std::vector history() const; }; }