mastodon-cpp  0.30.1
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

 Instance (const string &json)
 Constructs an Instance object from a JSON string. More...
 
 Instance ()
 Constructs an empty Instance object. More...
 
virtual bool valid () const
 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...
 
uint_fast64_t max_toot_chars () const
 Returns the maximum chars a post can have. More...
 
- Public Member Functions inherited from Mastodon::Easy::Entity
 Entity (const string &json)
 Constructs an Entity object from a JSON string. More...
 
 Entity ()
 Constructs an empty Entity object. More...
 
void from_string (const string &json)
 Replaces the Entity with a new one from a JSON string. 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...
 
uint_fast64_t get_uint64 (const string &key) const
 Returns the value of key as std::uint_fast64_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 system_clock::time_point get_time_point (const string &key) const
 Returns the value of key as time_point. 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::uint_fast64_t stouint64 (const string &str) const
 
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

Constructor & Destructor Documentation

◆ Instance() [1/2]

Instance::Instance ( const string &  json)
explicit

Constructs an Instance object from a JSON string.

Parameters
jsonJSON string
Since
before 0.11.0
26 : Entity(json)
27 {}
Entity()
Constructs an empty Entity object.
Definition: entity.cpp:65

◆ Instance() [2/2]

Instance::Instance ( )

Constructs an empty Instance object.

Since
before 0.11.0
30 : Entity()
31 {}
Entity()
Constructs an empty Entity object.
Definition: entity.cpp:65

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
51 {
52  const Json::Value node = get("contact_account");
53  if (node.isObject())
54  {
55  return Easy::Account(node.toStyledString());
56  }
57 
58  ttdebug << "Could not get data: contact_account\n";
59  return Easy::Account();
60 }
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
63 {
64  return get_string("description");
65 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:134

◆ email()

const string Instance::email ( ) const

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

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

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

◆ max_toot_chars()

uint_fast64_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
98 {
99  const uint_fast64_t max_chars = get_uint64("max_toot_chars");
100  if (was_set())
101  {
102  return max_chars;
103  }
104  else
105  {
106  return 500;
107  }
108 }
bool was_set() const
Returns true if the last requested value was set, false if it was unset.
Definition: entity.cpp:88
uint_fast64_t get_uint64(const string &key) const
Returns the value of key as std::uint_fast64_t.
Definition: entity.cpp:148

◆ streaming_api()

const string Instance::streaming_api ( ) const

Returns the URL for the streaming API.

Since
before 0.11.0
93 {
94  return get_string("urls.streaming_api");
95 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:134

◆ title()

const string Instance::title ( ) const

Returns the title of the instance.

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

◆ uri()

const string Instance::uri ( ) const

Returns the URI of the instance.

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

◆ valid()

bool Instance::valid ( ) const
virtual

Returns true if the Entity holds valid data.

Since
before 0.11.0 (virtual since 0.18.2)

Implements Mastodon::Easy::Entity.

34 {
35  const std::vector<string> attributes =
36  {{
37  "uri",
38  "title",
39  "description",
40  "email",
41  "version",
42  "urls",
43  "languages",
44  "contact_account"
45  }};
46 
47  return Entity::check_valid(attributes);
48 }
bool check_valid(const std::vector< string > &attributes) const
Checks if an Entity is valid.
Definition: entity.cpp:69

◆ version()

const string Instance::version ( ) const

Returns the version used by the instance.

Since
before 0.11.0
88 {
89  return get_string("version");
90 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:134

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