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

Class to hold accounts. More...

#include <account.hpp>

Inheritance diagram for Mastodon::Easy::Account:
Mastodon::Easy::Entity

Classes

class  Source
 Class to hold source attribute. More...
 

Public Member Functions

virtual bool valid () const override
 Returns true if the Entity holds valid data. More...
 
const string acct () const
 Returns username. More...
 
const string avatar () const
 Returns URL of avatar. More...
 
const string avatar_static () const
 Returns URL of static avatar. More...
 
bool bot () const
 Returns true if the account performs automated actions. More...
 
const Easy::time_type created_at () const
 Returns time of creation. More...
 
const string display_name () const
 Returns display name. More...
 
const std::vector< Easy::Emojiemojis ()
 Returns emojis. More...
 
const vector< Easy::account_field_typefields () const
 Returns metadata fields. More...
 
uint64_t followers_count () const
 Returns number of followers. More...
 
uint64_t following_count () const
 Returns number of people this account follows. More...
 
const string header () const
 Returns URL of header image. More...
 
const string header_static () const
 Returns URL of static header image. More...
 
const string id () const
 Returns account-ID. More...
 
bool locked () const
 Returns true if the account is locked. More...
 
bool has_moved () const
 Returns true if the account has been moved. (Deprecated) More...
 
const Account moved () const
 If the owner decided to switch accounts, new account is in this attribute. More...
 
const string note () const
 Returns account description, or biography. More...
 
visibility_type privacy () const
 Returns default privacy of new toots. More...
 
bool sensitive () const
 Returns if media is marked as sensitive by default. More...
 
const Source source () const
 Get source. More...
 
uint64_t statuses_count () const
 Returns number of statuses. More...
 
const string url () const
 Returns URL of the profile. More...
 
const string username () const
 Returns username (without @hostname) 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 accounts.

Since
before 0.11.0

Member Function Documentation

◆ acct()

const string Account::acct ( ) const

Returns username.

    `username` for users on the same instance, `user@hostname`
    for users on other instances.
Since
before 0.11.0
Examples
example01_get_public_timeline.cpp, and example02_stream.cpp.
49 {
50  return get_string("acct");
51 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ avatar()

const string Account::avatar ( ) const

Returns URL of avatar.

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

◆ avatar_static()

const string Account::avatar_static ( ) const

Returns URL of static avatar.

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

◆ bot()

bool Account::bot ( ) const

Returns true if the account performs automated actions.

Since
0.16.0
64 {
65  return get_bool("bot");
66 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:216

◆ created_at()

const Easy::time_type Account::created_at ( ) const

Returns time of creation.

Since
before 0.11.0
69 {
70  return get_time("created_at");
71 }
const Easy::time_type get_time(const string &key) const
Returns the value of key as Easy::time.
Definition: entity.cpp:230

◆ display_name()

const string Account::display_name ( ) const

Returns display name.

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

◆ emojis()

const std::vector< Easy::Emoji > Account::emojis ( )

Returns emojis.

Since
0.106.0
79 {
80  const Json::Value &node = get("emojis");
81 
82  if (node.isArray())
83  {
84  std::vector<Easy::Emoji> vec;
85  std::transform(node.begin(), node.end(), std::back_inserter(vec),
86  [](const Json::Value &value)
87  {
88  return Easy::Emoji(value);
89  });
90  return vec;
91  }
92 
93  return {};
94 }
const Json::Value get(const string &key) const
Returns the value of key as Json::Value.
Definition: entity.cpp:133
Class to hold emojis.
Definition: emoji.hpp:36

◆ 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 {}

◆ fields()

const vector< Easy::account_field_type > Account::fields ( ) const

Returns metadata fields.

Since
0.16.1
97 {
98  const Json::Value &node = get("fields");
99 
100  if (node.isArray())
101  {
102  vector<Easy::account_field_type> vec;
103  std::transform(node.begin(), node.end(), std::back_inserter(vec),
104  [](const Json::Value &value)
105  {
107  {
108  value["name"].asString(),
109  value["value"].asString(),
111  value["verified_at"].asString())
112  });
113  });
114  return vec;
115  }
116 
117  return {};
118 }
const Json::Value get(const string &key) const
Returns the value of key as Json::Value.
Definition: entity.cpp:133
const Easy::time_type string_to_time(const string &strtime)
Convert ISO 8601 time string to Easy::time.
Definition: easy.cpp:85
struct Mastodon::Easy::account_field_type account_field_type
Describes an account-field.

◆ followers_count()

std::uint64_t Account::followers_count ( ) const

Returns number of followers.

Since
before 0.11.0
121 {
122  return get_uint64("followers_count");
123 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:188

◆ following_count()

std::uint64_t Account::following_count ( ) const

Returns number of people this account follows.

Since
before 0.11.0
126 {
127  return get_uint64("following_count");
128 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:188

◆ has_moved()

bool Account::has_moved ( ) const

Returns true if the account has been moved. (Deprecated)

Since
before 0.11.0
151 {
152  if (get("moved").isObject())
153  {
154  return true;
155  }
156 
157  return false;
158 }
const Json::Value get(const string &key) const
Returns the value of key as Json::Value.
Definition: entity.cpp:133

◆ header()

const string Account::header ( ) const

Returns URL of header image.

Since
before 0.11.0
131 {
132  return get_string("header");
133 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ header_static()

const string Account::header_static ( ) const

Returns URL of static header image.

Since
before 0.11.0
136 {
137  return get_string("header_static");
138 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ id()

const string Account::id ( ) const

Returns account-ID.

Since
before 0.11.0
141 {
142  return get_string("id");
143 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ locked()

bool Account::locked ( ) const

Returns true if the account is locked.

Since
before 0.11.0
146 {
147  return get_bool("locked");
148 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:216

◆ moved()

const Account Account::moved ( ) const

If the owner decided to switch accounts, new account is in this attribute.

Since
before 0.11.0
161 {
162  if (has_moved())
163  {
164  return Account(get("moved"));
165  }
166 
167  return Account();
168 }
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
bool has_moved() const
Returns true if the account has been moved. (Deprecated)
Definition: account.cpp:150

◆ note()

const string Account::note ( ) const

Returns account description, or biography.

Since
before 0.11.0
171 {
172  return get_string("note");
173 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ privacy()

Easy::visibility_type Account::privacy ( ) const

Returns default privacy of new toots.

Since
before 0.11.0
176 {
177  const string strprivacy = get_string("privacy");
178  if (strprivacy == "public")
179  return visibility_type::Public;
180  else if (strprivacy == "unlisted")
181  return visibility_type::Unlisted;
182  else if (strprivacy == "private")
183  return visibility_type::Private;
184  else if (strprivacy == "direct")
185  return visibility_type::Direct;
186 
187  return visibility_type::Undefined;
188 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ sensitive()

bool Account::sensitive ( ) const

Returns if media is marked as sensitive by default.

Since
before 0.11.0
191 {
192  return get_bool("source.sensitive");
193 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:216

◆ source()

const Account::Source Account::source ( ) const

Get source.

Since
before 0.100.0
196 {
197  return Account::Source(get("source"));
198 }
const Json::Value get(const string &key) const
Returns the value of key as Json::Value.
Definition: entity.cpp:133
Class to hold source attribute.
Definition: account.hpp:191

◆ statuses_count()

std::uint64_t Account::statuses_count ( ) const

Returns number of statuses.

Since
before 0.11.0
201 {
202  return get_uint64("statuses_count");
203 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:188

◆ url()

const string Account::url ( ) const

Returns URL of the profile.

Since
before 0.11.0
206 {
207  return get_string("url");
208 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ username()

const string Account::username ( ) const

Returns username (without @hostname)

Since
before 0.11.0
211 {
212  return get_string("username");
213 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ valid()

bool Account::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  "id",
30  "username",
31  "acct",
32  "display_name",
33  "locked",
34  "created_at",
35  "followers_count",
36  "following_count",
37  "statuses_count",
38  "note",
39  "url",
40  "avatar",
41  "avatar_static",
42  "header",
43  "header_static",
44  "emojis"
45  });
46 }
bool check_valid(const std::vector< string > &attributes) const
Checks if an Entity is valid.
Definition: entity.cpp:102

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