mastodon-cpp  0.104.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 std::vector< string > languages () const
 Returns a vector of ISO 6391 language codes the instance has chosen to advertise. More...
 
const string title () const
 Returns the title of the instance. More...
 
const string uri () const
 Returns the URI of the instance. More...
 
const string version () const
 Returns the version used by the instance. More...
 
const string streaming_api () const
 Returns the URL for the streaming API. 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 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 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
42 {
43  const Json::Value node = get("contact_account");
44  if (node.isObject())
45  {
46  return Easy::Account(node.toStyledString());
47  }
48 
49  ttdebug << "Could not get data: contact_account\n";
50  return Easy::Account();
51 }
Class to hold accounts.
Definition: account.hpp:46

◆ description()

const string Instance::description ( ) const

Returns the description of the instance.

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

◆ email()

const string Instance::email ( ) const

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

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

◆ Entity() [1/3]

Easy::Entity::Entity
explicit

Constructs an Entity object from a JSON string.

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

◆ Entity() [2/3]

Easy::Entity::Entity

Constructs an empty Entity object.

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

◆ Entity() [3/3]

Easy::Entity::Entity
explicit

Constructs an Entity object from a JSON object.

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

◆ 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
64 {
65  return get_vector("languages");
66 }
const std::vector< string > get_vector(const string &key) const
Returns the value of key as vector.
Definition: entity.cpp:249

◆ 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
89 {
90  const uint64_t max_chars = get_uint64("max_toot_chars");
91  if (was_set())
92  {
93  return max_chars;
94  }
95  else
96  {
97  return 500;
98  }
99 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:187
bool was_set() const
Returns true if the last requested value was set, false if it was unset.
Definition: entity.cpp:127

◆ streaming_api()

const string Instance::streaming_api ( ) const

Returns the URL for the streaming API.

Since
before 0.11.0
84 {
85  return get_string("urls.streaming_api");
86 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ title()

const string Instance::title ( ) const

Returns the title of the instance.

Since
before 0.11.0
69 {
70  return get_string("title");
71 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ uri()

const string Instance::uri ( ) const

Returns the URI of the instance.

Since
before 0.11.0
74 {
75  return get_string("uri");
76 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ 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  const std::vector<string> attributes =
28  {{
29  "uri",
30  "title",
31  "description",
32  "email",
33  "version",
34  "urls",
35  "languages"
36  }};
37 
38  return Entity::check_valid(attributes);
39 }
bool check_valid(const std::vector< string > &attributes) const
Checks if an Entity is valid.
Definition: entity.cpp:101

◆ version()

const string Instance::version ( ) const

Returns the version used by the instance.

Since
before 0.11.0
79 {
80  return get_string("version");
81 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

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