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

◆ avatar() [1/2]

const string Account::avatar ( ) const

Returns URL of avatar.

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

◆ avatar() [2/2]

Account Account::avatar ( const string &  avatar)

Sets avatar.

Filename or base64-encoded

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

◆ avatar_static()

const string Account::avatar_static ( ) const

Returns URL of static avatar.

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

◆ bot()

bool Account::bot ( ) const

Returns true if the account performs automated actions.

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

◆ created_at()

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

Returns time of creation.

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

◆ display_name() [1/2]

const string Account::display_name ( ) const

Returns display name.

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

◆ display_name() [2/2]

Account Account::display_name ( const string &  display_name)

Sets display name.

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

◆ 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
92 {
93  const Json::Value &node = get("fields");
94 
95  if (node.isArray())
96  {
97  std::vector<Account::fields_pair> vec;
98  std::transform(node.begin(), node.end(), std::back_inserter(vec),
99  [](const Json::Value &value)
100  {
101  return Account::fields_pair
102  (value["name"].asString(),
103  value["value"].asString());
104  });
105  return vec;
106  }
107 
108  return {};
109 }
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
127 {
128  return get_uint64("followers_count");
129 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:173

◆ following_count()

std::uint64_t Account::following_count ( ) const

Returns number of people this account follows.

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

◆ has_moved()

bool Account::has_moved ( ) const

Returns true if the account has been moved.

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

◆ header() [1/2]

const string Account::header ( ) const

Returns URL of header image.

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

◆ header() [2/2]

Account Account::header ( const string &  header)

Sets header image.

Filename or base64-encoded.

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

◆ header_static()

const string Account::header_static ( ) const

Returns URL of static header image.

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

◆ id()

const string Account::id ( ) const

Returns account-ID.

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

◆ locked() [1/2]

bool Account::locked ( ) const

Returns true if the account is locked.

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

◆ locked() [2/2]

Account Account::locked ( const bool &  locked)

Sets locked state.

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

◆ moved()

const Account Account::moved ( ) const

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

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

◆ note() [1/2]

const string Account::note ( ) const

Returns note.

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

◆ note() [2/2]

Account Account::note ( const string &  note)

Sets note.

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

◆ privacy()

Easy::visibility_type Account::privacy ( ) const

Returns default privacy of new toots.

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

◆ sensitive()

bool Account::sensitive ( ) const

Returns if media is marked as sensitive by default.

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

◆ source() [1/2]

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

Get source.

Since
before 0.100.0
336 {
337  return Account::Source(get("source"));
338 }
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
341 {
342  set("source", Json::Value(source.to_object()));
343  return *this;
344 }
const Source source() const
Get source.
Definition: account.cpp:335
const Json::Value to_object() const
Returns the JSON object of the Entity.
Definition: entity.cpp:89

◆ statuses_count()

std::uint64_t Account::statuses_count ( ) const

Returns number of statuses.

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

◆ url()

const string Account::url ( ) const

Returns URL of the profile.

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

◆ username()

const string Account::username ( ) const

Returns username (without @hostname)

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

◆ 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  }};
45 
46  return Entity::check_valid(attributes);
47 }
bool check_valid(const std::vector< string > &attributes) const
Checks if an Entity is valid.
Definition: entity.cpp:94

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