Added Easy::Tag::History
This commit is contained in:
parent
55837e78d2
commit
3423e7f672
@ -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
|
||||
|
||||
|
@ -14,7 +14,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#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> Tag::history() const
|
||||
{
|
||||
const Json::Value node = get("history");
|
||||
if (node.isArray())
|
||||
{
|
||||
std::vector<Easy::Tag::History> 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"));
|
||||
}
|
||||
|
@ -18,6 +18,8 @@
|
||||
#define MASTODON_CPP_EASY_TAG_HPP
|
||||
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
|
||||
// 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> history() const;
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user