mastodon-cpp  0.110.0
Public Member Functions | List of all members
Mastodon::Easy::Instance Class Reference

Class to hold instances. More...

#include <instance.hpp>

Inheritance diagram for Mastodon::Easy::Instance:
Mastodon::Easy::Entity

Public Member Functions

virtual bool valid () const override
 Returns true if the Entity holds valid data. More...
 
const Account contact_account () const
 Returns the Account of the admin or another contact person. More...
 
const string description () const
 Returns the description of the instance. More...
 
const string email () const
 Returns the email address which can be used to contact the instance administrator. More...
 
const vector< string > languages () const
 Returns a vector of ISO 6391 language codes the instance has chosen to advertise. More...
 
const string thumbnail () const
 Returns the thumbnail of the instance. More...
 
const string title () const
 Returns the title of the instance. More...
 
const string uri () const
 Returns the URI of the instance. More...
 
const Easy::urls_type urls () const
 Returns the URL for the streaming API and possibly others. More...
 
const Easy::stats_type stats () const
 Returns statistics about the instance. More...
 
const string version () const
 Returns the version used by the instance. More...
 
uint64_t max_toot_chars () const
 Returns the maximum chars a post can have. More...
 
 Entity (const string &json)
 Constructs an Entity object from a JSON string. More...
 
 Entity (const Json::Value &object)
 Constructs an Entity object from a JSON object. More...
 
 Entity ()
 Constructs an empty Entity object. More...
 
- Public Member Functions inherited from Mastodon::Easy::Entity
 Entity (const string &json)
 Constructs an Entity object from a JSON string. More...
 
 Entity (const Json::Value &object)
 Constructs an Entity object from a JSON object. More...
 
 Entity ()
 Constructs an empty Entity object. More...
 
virtual ~Entity ()
 Destroys the object. More...
 
 operator const Json::Value () const
 
void from_string (const string &json)
 Replaces the Entity with a new one from a JSON string. More...
 
const string to_string () const
 Returns the JSON of the Entity as formatted string. More...
 
void from_object (const Json::Value &object)
 Replaces the Entity with a new one from a JSON object. More...
 
const Json::Value to_object () const
 Returns the JSON object of the Entity. More...
 
const string error () const
 Returns error string sent by the server. More...
 
bool was_set () const
 Returns true if the last requested value was set, false if it was unset. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Mastodon::Easy::Entity
const Json::Value get (const string &key) const
 Returns the value of key as Json::Value. More...
 
const string get_string (const string &key) const
 Returns the value of key as std::string. More...
 
uint64_t get_uint64 (const string &key) const
 Returns the value of key as std::uint64_t. More...
 
double get_double (const string &key) const
 Returns the value of key as double. More...
 
bool get_bool (const string &key) const
 Returns the value of key as bool. More...
 
const Easy::time_type get_time (const string &key) const
 Returns the value of key as Easy::time. More...
 
const std::vector< string > get_vector (const string &key) const
 Returns the value of key as vector. More...
 
void set (const string &key, const Json::Value &value)
 Sets the value of key. More...
 
std::uint64_t stouint64 (const string &str) const
 Returns value of str as uint64_t.
 
bool check_valid (const std::vector< string > &attributes) const
 Checks if an Entity is valid. More...
 

Detailed Description

Class to hold instances.

Since
before 0.11.0

Member Function Documentation

◆ contact_account()

const Easy::Account Instance::contact_account ( ) const

Returns the Account of the admin or another contact person.

Since
before 0.11.0
41 {
42  const Json::Value node = get("contact_account");
43  if (node.isObject())
44  {
45  return Easy::Account(node);
46  }
47 
48  return Easy::Account();
49 }
const Json::Value get(const string &key) const
Returns the value of key as Json::Value.
Definition: entity.cpp:133
Class to hold accounts.
Definition: account.hpp:42

◆ description()

const string Instance::description ( ) const

Returns the description of the instance.

Since
before 0.11.0
52 {
53  return get_string("description");
54 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ email()

const string Instance::email ( ) const

Returns the email address which can be used to contact the instance administrator.

Since
before 0.11.0
57 {
58  return get_string("email");
59 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ Entity() [1/3]

Easy::Entity::Entity

Constructs an empty Entity object.

Since
before 0.11.0
44 : _tree(Json::nullValue)
45 , _was_set(false)
46 {}

◆ Entity() [2/3]

Easy::Entity::Entity
explicit

Constructs an Entity object from a JSON string.

Parameters
jsonJSON string
Since
before 0.11.0
32 : _tree(Json::nullValue)
33 ,_was_set(false)
34 {
35  from_string(json);
36 }
void from_string(const string &json)
Replaces the Entity with a new one from a JSON string.
Definition: entity.cpp:56

◆ Entity() [3/3]

Easy::Entity::Entity
explicit

Constructs an Entity object from a JSON object.

Parameters
objectJSON object
Since
0.100.0
39 : _tree(object)
40 ,_was_set(false)
41 {}

◆ languages()

const std::vector< string > Instance::languages ( ) const

Returns a vector of ISO 6391 language codes the instance has chosen to advertise.

Since
before 0.11.0
62 {
63  return get_vector("languages");
64 }
const std::vector< string > get_vector(const string &key) const
Returns the value of key as vector.
Definition: entity.cpp:245

◆ max_toot_chars()

uint64_t Instance::max_toot_chars ( ) const

Returns the maximum chars a post can have.

    This parameter is not supported by upstream Mastodon. If it
    is not found, 500 is returned.
Since
0.20.0
101 {
102  const uint64_t max_chars = get_uint64("max_toot_chars");
103  if (was_set())
104  {
105  return max_chars;
106  }
107  else
108  {
109  return 500;
110  }
111 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:188
bool was_set() const
Returns true if the last requested value was set, false if it was unset.
Definition: entity.cpp:128

◆ stats()

const Easy::stats_type Instance::stats ( ) const

Returns statistics about the instance.

Since
0.106.0
67 {
69  s.user_count = get_uint64("stats.user_count");
70  s.status_count = get_uint64("stats.status_count");
71  s.domain_count = get_uint64("stats.domain_count");
72  return s;
73 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:188
Statistics returned by Instance::stats().
Definition: types_easy.hpp:222

◆ thumbnail()

const string Instance::thumbnail ( ) const

Returns the thumbnail of the instance.

Since
0.106.0
96 {
97  return get_string("thumbnail");
98 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ title()

const string Instance::title ( ) const

Returns the title of the instance.

Since
before 0.11.0
76 {
77  return get_string("title");
78 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ uri()

const string Instance::uri ( ) const

Returns the URI of the instance.

Since
before 0.11.0
81 {
82  return get_string("uri");
83 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ urls()

const Easy::urls_type Instance::urls ( ) const

Returns the URL for the streaming API and possibly others.

Since
0.106.0
86 {
87  return { get_string("urls.streaming_api") };
88 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ valid()

bool Instance::valid ( ) const
overridevirtual

Returns true if the Entity holds valid data.

Since
before 0.11.0 (virtual since 0.18.2)

Implements Mastodon::Easy::Entity.

26 {
27  return Entity::check_valid(
28  {
29  "uri",
30  "title",
31  "description",
32  "email",
33  "version",
34  "urls",
35  "stats",
36  "languages"
37  });
38 }
bool check_valid(const std::vector< string > &attributes) const
Checks if an Entity is valid.
Definition: entity.cpp:102

◆ version()

const string Instance::version ( ) const

Returns the version used by the instance.

Since
before 0.11.0
91 {
92  return get_string("version");
93 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

The documentation for this class was generated from the following files: