Updated Easy::Instance.

Added urls() and stats() and removed streaming_api().
This commit is contained in:
tastytea 2019-05-13 21:52:28 +02:00
parent 8a6bef8c2c
commit 8f5d40ff7f
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 52 additions and 25 deletions

View File

@ -42,7 +42,7 @@ const Easy::Account Instance::contact_account() const
const Json::Value node = get("contact_account"); const Json::Value node = get("contact_account");
if (node.isObject()) if (node.isObject())
{ {
return Easy::Account(node.toStyledString()); return Easy::Account(node);
} }
return Easy::Account(); return Easy::Account();
@ -73,16 +73,24 @@ const string Instance::uri() const
return get_string("uri"); return get_string("uri");
} }
const Easy::urls_type Instance::urls() const
{
return { get_string("urls.streaming_api") };
}
const string Instance::version() const const string Instance::version() const
{ {
return get_string("version"); return get_string("version");
} }
const string Instance::streaming_api() const const Easy::stats_type Instance::stats() const
{ {
return get_string("urls.streaming_api"); Easy::stats_type s;
s.user_count = get_uint64("user_count");
s.status_count = get_uint64("status_count");
s.domain_count = get_uint64("domain_count");
return s;
} }
const string Instance::thumbnail() const const string Instance::thumbnail() const
{ {
return get_string("thumbnail"); return get_string("thumbnail");

View File

@ -40,9 +40,9 @@ namespace Mastodon
namespace Easy namespace Easy
{ {
/*! /*!
* @brief Class to hold instances * @brief Class to hold instances.
* *
* @since before 0.11.0 * @since before 0.11.0
*/ */
class Instance : public Entity class Instance : public Entity
{ {
@ -52,34 +52,34 @@ namespace Easy
virtual bool valid() const override; virtual bool valid() const override;
/*! /*!
* @brief Returns the Account of the admin or another contact person * @brief Returns the Account of the admin or another contact person.
* *
* @since before 0.11.0 * @since before 0.11.0
*/ */
const Account contact_account() const; const Account contact_account() const;
/*! /*!
* @brief Returns the description of the instance * @brief Returns the description of the instance.
* *
* @since before 0.11.0 * @since before 0.11.0
*/ */
const string description() const; const string description() const;
/*! /*!
* @brief Returns the email address which can be used to contact the * @brief Returns the email address which can be used to contact the
* instance administrator * instance administrator.
* *
* @since before 0.11.0 * @since before 0.11.0
*/ */
const string email() const; const string email() const;
/*! /*!
* @brief Returns a vector of ISO 6391 language codes the instance has * @brief Returns a vector of ISO 6391 language codes the instance has
* chosen to advertise * chosen to advertise.
* *
* @since before 0.11.0 * @since before 0.11.0
*/ */
const std::vector<string> languages() const; const vector<string> languages() const;
/*! /*!
* @brief Returns the thumbnail of the instance. * @brief Returns the thumbnail of the instance.
@ -89,32 +89,39 @@ namespace Easy
const string thumbnail() const; const string thumbnail() const;
/*! /*!
* @brief Returns the title of the instance * @brief Returns the title of the instance.
* *
* @since before 0.11.0 * @since before 0.11.0
*/ */
const string title() const; const string title() const;
/*! /*!
* @brief Returns the URI of the instance * @brief Returns the URI of the instance.
* *
* @since before 0.11.0 * @since before 0.11.0
*/ */
const string uri() const; const string uri() const;
/*! /*!
* @brief Returns the version used by the instance * @brief Returns the URL for the streaming API and possibly others.
* *
* @since before 0.11.0 * @since 0.106.0
*/ */
const string version() const; const Easy::urls_type urls() const;
/*! /*!
* @brief Returns the URL for the streaming API * @brief Returns statistics about the instance.
* *
* @since before 0.11.0 * @since 0.106.0
*/ */
const string streaming_api() const; const Easy::stats_type stats() const;
/*!
* @brief Returns the version used by the instance.
*
* @since before 0.11.0
*/
const string version() const;
/*! /*!
* @brief Returns the maximum chars a post can have * @brief Returns the maximum chars a post can have

View File

@ -20,9 +20,11 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include <chrono> #include <chrono>
#include <cstdint>
using std::string; using std::string;
using std::chrono::system_clock; using std::chrono::system_clock;
using std::uint64_t;
namespace Mastodon namespace Mastodon
{ {
@ -212,6 +214,16 @@ namespace Easy
{ {
string streaming_api; string streaming_api;
} urls_type; } urls_type;
/*!
* @brief Statistics returned by Instance::stats().
*/
typedef struct stats_type
{
uint64_t user_count = 0;
uint64_t status_count = 0;
uint64_t domain_count = 0;
} stats_type;
} }
} }
#endif // MASTODON_CPP_EASY_TYPES_EASY_HPP #endif // MASTODON_CPP_EASY_TYPES_EASY_HPP