mastodon-cpp  0.104.0
Classes | Public Types | 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 Types

using fields_pair = std::pair< const string, const string >
 Describes a field. Format: name, value. 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...
 
Account avatar (const string &avatar)
 Sets 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 created_at () const
 Returns time of creation. More...
 
const string display_name () const
 Returns display name. More...
 
Account display_name (const string &display_name)
 Sets display name. More...
 
const std::vector< fields_pairfields () const
 Returns metadata fields. More...
 
Account fields (std::vector< fields_pair > &fields)
 Sets 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...
 
Account header (const string &header)
 Sets 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...
 
Account locked (const bool &locked)
 Sets locked state. More...
 
bool has_moved () const
 Returns true if the account has been moved. More...
 
const Account moved () const
 If the owner decided to switch accounts, new account is in this attribute. More...
 
const string note () const
 Returns note. More...
 
Account note (const string &note)
 Sets note. 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...
 
Account source (const Source &source)
 Set 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 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 accounts.

Since
before 0.11.0

Member Typedef Documentation

◆ fields_pair

using Mastodon::Easy::Account::fields_pair = std::pair<const string, const string>

Describes a field. Format: name, value.

Since
0.16.1

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.
51 {
52  return get_string("acct");
53 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ avatar() [1/2]

const string Account::avatar ( ) const

Returns URL of avatar.

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

◆ avatar() [2/2]

Account Account::avatar ( const string &  avatar)

Sets avatar.

Filename or base64-encoded

Since
0.18.5
61 {
62  set("avatar", Json::Value(avatar));
63  return *this;
64 }
const string avatar() const
Returns URL of avatar.
Definition: account.cpp:55

◆ avatar_static()

const string Account::avatar_static ( ) const

Returns URL of static avatar.

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

◆ bot()

bool Account::bot ( ) const

Returns true if the account performs automated actions.

Since
0.16.0
72 {
73  return get_bool("bot");
74 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:215

◆ created_at()

const Easy::time Account::created_at ( ) const

Returns time of creation.

Since
before 0.11.0
77 {
78  return get_time("created_at");
79 }
const Easy::time get_time(const string &key) const
Returns the value of key as Easy::time.
Definition: entity.cpp:229

◆ display_name() [1/2]

const string Account::display_name ( ) const

Returns display name.

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

◆ display_name() [2/2]

Account Account::display_name ( const string &  display_name)

Sets display name.

Since
0.18.5
87 {
88  set("display_name", Json::Value(display_name));
89  return *this;
90 }
const string display_name() const
Returns display name.
Definition: account.cpp:81

◆ Entity() [1/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 {}

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

◆ fields() [1/2]

const std::vector< Account::fields_pair > Account::fields ( ) const

Returns metadata fields.

Since
0.16.1
93 {
94  const Json::Value &node = get("fields");
95 
96  if (node.isArray())
97  {
98  std::vector<Account::fields_pair> vec;
99  std::transform(node.begin(), node.end(), std::back_inserter(vec),
100  [](const Json::Value &value)
101  {
102  return Account::fields_pair
103  (value["name"].asString(),
104  value["value"].asString());
105  });
106  return vec;
107  }
108 
109  return {};
110 }
std::pair< const string, const string > fields_pair
Describes a field. Format: name, value.
Definition: account.hpp:56

◆ fields() [2/2]

Account Mastodon::Easy::Account::fields ( std::vector< fields_pair > &  fields)

Sets metadata fields.

Since
0.18.5

◆ followers_count()

std::uint64_t Account::followers_count ( ) const

Returns number of followers.

Since
before 0.11.0
128 {
129  return get_uint64("followers_count");
130 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:187

◆ following_count()

std::uint64_t Account::following_count ( ) const

Returns number of people this account follows.

Since
before 0.11.0
133 {
134  return get_uint64("following_count");
135 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:187

◆ has_moved()

bool Account::has_moved ( ) const

Returns true if the account has been moved.

Since
before 0.11.0
170 {
171  if (get("moved").isObject())
172  {
173  return true;
174  }
175 
176  return false;
177 }

◆ header() [1/2]

const string Account::header ( ) const

Returns URL of header image.

Since
before 0.11.0
138 {
139  return get_string("header");
140 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ header() [2/2]

Account Account::header ( const string &  header)

Sets header image.

Filename or base64-encoded.

Since
0.18.5
143 {
144  set("header", Json::Value(header));
145  return *this;
146 }
const string header() const
Returns URL of header image.
Definition: account.cpp:137

◆ header_static()

const string Account::header_static ( ) const

Returns URL of static header image.

Since
before 0.11.0
149 {
150  return get_string("header_static");
151 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ id()

const string Account::id ( ) const

Returns account-ID.

Since
before 0.11.0
154 {
155  return get_string("id");
156 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ locked() [1/2]

bool Account::locked ( ) const

Returns true if the account is locked.

Since
before 0.11.0
159 {
160  return get_bool("locked");
161 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:215

◆ locked() [2/2]

Account Account::locked ( const bool &  locked)

Sets locked state.

Since
0.18.5
164 {
165  set("locked", Json::Value(locked));
166  return *this;
167 }
bool locked() const
Returns true if the account is locked.
Definition: account.cpp:158

◆ moved()

const Account Account::moved ( ) const

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

Since
before 0.11.0
180 {
181  if (has_moved())
182  {
183  // TODO: Find an account with moved-node and test
184  return Account(get("moved").toStyledString());
185  }
186 
187  return Account();
188 }
Class to hold accounts.
Definition: account.hpp:46
bool has_moved() const
Returns true if the account has been moved.
Definition: account.cpp:169

◆ note() [1/2]

const string Account::note ( ) const

Returns note.

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

◆ note() [2/2]

Account Account::note ( const string &  note)

Sets note.

Since
0.18.5
196 {
197  set("note", Json::Value(note));
198  return *this;
199 }
const string note() const
Returns note.
Definition: account.cpp:190

◆ privacy()

Easy::visibility_type Account::privacy ( ) const

Returns default privacy of new toots.

Since
before 0.11.0
202 {
203  const string strprivacy = get_string("source.privacy");
204  if (strprivacy.compare("public") == 0)
205  return visibility_type::Public;
206  else if (strprivacy.compare("unlisted") == 0)
207  return visibility_type::Unlisted;
208  else if (strprivacy.compare("private") == 0)
209  return visibility_type::Private;
210  else if (strprivacy.compare("direct") == 0)
211  return visibility_type::Direct;
212 
213  ttdebug << "Could not get data: source.privacy\n";
214  return visibility_type::Undefined;
215 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ sensitive()

bool Account::sensitive ( ) const

Returns if media is marked as sensitive by default.

Since
before 0.11.0
218 {
219  return get_bool("source.sensitive");
220 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:215

◆ source() [1/2]

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

Get source.

Since
before 0.100.0
337 {
338  return Account::Source(get("source"));
339 }
Class to hold source attribute.
Definition: account.hpp:241

◆ source() [2/2]

Account Account::source ( const Source source)

Set source.

Since
before 0.100.0
342 {
343  set("source", Json::Value(source.to_object()));
344  return *this;
345 }
const Source source() const
Get source.
Definition: account.cpp:336
const Json::Value to_object() const
Returns the JSON object of the Entity.
Definition: entity.cpp:96

◆ statuses_count()

std::uint64_t Account::statuses_count ( ) const

Returns number of statuses.

Since
before 0.11.0
348 {
349  return get_uint64("statuses_count");
350 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:187

◆ url()

const string Account::url ( ) const

Returns URL of the profile.

Since
before 0.11.0
353 {
354  return get_string("url");
355 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ username()

const string Account::username ( ) const

Returns username (without @hostname)

Since
before 0.11.0
358 {
359  return get_string("username");
360 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ 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  const std::vector<string> attributes =
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 
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:101

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