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

 Account (const string &json)
 Constructs an Account object from a JSON string. More...
 
 Account ()
 Constructs an empty Account object. More...
 
virtual const bool valid () const
 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...
 
const bool bot () const
 Returns true if the account performs automated actions. More...
 
const system_clock::time_point 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...
 
const uint_fast64_t followers_count () const
 Returns number of followers. More...
 
const uint_fast64_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 uint_fast64_t id () const
 Returns account-ID. More...
 
const bool locked () const
 Returns true if the account is locked. More...
 
Account locked (const bool &locked)
 Sets locked state. More...
 
const 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...
 
const string note_plain () const
 Returns plaintext version of note. More...
 
const visibility_type privacy () const
 Returns default privacy of new toots. More...
 
const bool sensitive () const
 Returns if media is marked as sensitive by default. More...
 
const Source source () const
 
Account source (const Source &source)
 
const uint_fast64_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 ) 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...
 
const 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...
 
const 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...
 
const uint_fast64_t get_uint64 (const string &key) const
 Returns the value of key as std::uint_fast64_t. More...
 
const double get_double (const string &key) const
 Returns the value of key as double. More...
 
const 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...
 
const void set (const string &key, const Json::Value &value)
 Sets the value of key. More...
 
const std::uint_fast64_t stouint64 (const string &str) const
 
const 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

Constructor & Destructor Documentation

◆ Account() [1/2]

Account::Account ( const string &  json)
explicit

Constructs an Account object from a JSON string.

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

◆ Account() [2/2]

Account::Account ( )

Constructs an empty Account object.

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

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

◆ avatar() [1/2]

const string Account::avatar ( ) const

Returns URL of avatar.

Since
before 0.11.0
62 {
63  return get_string("avatar");
64 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:135

◆ avatar() [2/2]

Account Account::avatar ( const string &  avatar)

Sets avatar.

Filename or base64-encoded

Since
0.18.5
67 {
68  set("avatar", Json::Value(avatar));
69  return *this;
70 }
const string avatar() const
Returns URL of avatar.
Definition: account.cpp:61

◆ avatar_static()

const string Account::avatar_static ( ) const

Returns URL of static avatar.

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

◆ bot()

const bool Account::bot ( ) const

Returns true if the account performs automated actions.

Since
0.16.0
78 {
79  return get_bool("bot");
80 }
const bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:177

◆ created_at()

const system_clock::time_point Account::created_at ( ) const

Returns time of creation.

Since
before 0.11.0
83 {
84  return get_time_point("created_at");
85 }
const system_clock::time_point get_time_point(const string &key) const
Returns the value of key as time_point.
Definition: entity.cpp:192

◆ display_name() [1/2]

const string Account::display_name ( ) const

Returns display name.

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

◆ display_name() [2/2]

Account Account::display_name ( const string &  display_name)

Sets display name.

Since
0.18.5
93 {
94  set("display_name", Json::Value(display_name));
95  return *this;
96 }
const string display_name() const
Returns display name.
Definition: account.cpp:87

◆ fields() [1/2]

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

Returns metadata fields.

Since
0.16.1
99 {
100  const Json::Value &node = get("fields");
101 
102  if (node.isArray())
103  {
104  std::vector<Account::fields_pair> vec;
105  for (const Json::Value &value : node)
106  {
107  vec.push_back(Account::fields_pair(value["name"].asString(),
108  value["value"].asString()));
109  }
110  return vec;
111  }
112 
113  return {};
114 }
std::pair< const string, const string > fields_pair
Describes a field. Format: name, value.
Definition: account.hpp:54

◆ fields() [2/2]

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

Sets metadata fields.

Since
0.18.5

◆ followers_count()

const std::uint_fast64_t Account::followers_count ( ) const

Returns number of followers.

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

◆ following_count()

const std::uint_fast64_t Account::following_count ( ) const

Returns number of people this account follows.

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

◆ has_moved()

const bool Account::has_moved ( ) const

Returns true if the account has been moved.

Since
before 0.11.0
174 {
175  if (get("moved").isObject())
176  {
177  return true;
178  }
179 
180  return false;
181 }

◆ header() [1/2]

const string Account::header ( ) const

Returns URL of header image.

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

◆ header() [2/2]

Account Account::header ( const string &  header)

Sets header image.

Filename or base64-encoded.

Since
0.18.5
147 {
148  set("header", Json::Value(header));
149  return *this;
150 }
const string header() const
Returns URL of header image.
Definition: account.cpp:141

◆ header_static()

const string Account::header_static ( ) const

Returns URL of static header image.

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

◆ id()

const std::uint_fast64_t Account::id ( ) const

Returns account-ID.

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

◆ locked() [1/2]

const bool Account::locked ( ) const

Returns true if the account is locked.

Since
before 0.11.0
163 {
164  return get_bool("locked");
165 }
const bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:177

◆ locked() [2/2]

Account Account::locked ( const bool &  locked)

Sets locked state.

Since
0.18.5
168 {
169  set("locked", Json::Value(locked));
170  return *this;
171 }
const bool locked() const
Returns true if the account is locked.
Definition: account.cpp:162

◆ moved()

const Account Account::moved ( ) const

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

Since
before 0.11.0
184 {
185  if (has_moved())
186  {
187  // TODO: Find an account with moved-node and test
188  return Account(get("moved").toStyledString());
189  }
190 
191  return Account();
192 }
const bool has_moved() const
Returns true if the account has been moved.
Definition: account.cpp:173
Account()
Constructs an empty Account object.
Definition: account.cpp:28

◆ note() [1/2]

const string Account::note ( ) const

Returns note.

Since
before 0.11.0
195 {
196  return get_string("note");
197 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:135

◆ note() [2/2]

Account Account::note ( const string &  note)

Sets note.

Since
0.18.5
200 {
201  set("note", Json::Value(note));
202  return *this;
203 }
const string note() const
Returns note.
Definition: account.cpp:194

◆ note_plain()

const string Account::note_plain ( ) const

Returns plaintext version of note.

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

◆ privacy()

const Easy::visibility_type Account::privacy ( ) const

Returns default privacy of new toots.

Since
before 0.11.0
211 {
212  const string strprivacy = get_string("source.privacy");
213  if (strprivacy.compare("public") == 0)
214  return visibility_type::Public;
215  else if (strprivacy.compare("unlisted") == 0)
216  return visibility_type::Unlisted;
217  else if (strprivacy.compare("private") == 0)
218  return visibility_type::Private;
219  else if (strprivacy.compare("direct") == 0)
220  return visibility_type::Direct;
221 
222  ttdebug << "Could not get data: source.privacy\n";
223  return visibility_type::Undefined;
224 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:135

◆ sensitive()

const bool Account::sensitive ( ) const

Returns if media is marked as sensitive by default.

Since
before 0.11.0
227 {
228  return get_bool("source.sensitive");
229 }
const bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:177

◆ statuses_count()

const std::uint_fast64_t Account::statuses_count ( ) const

Returns number of statuses.

Since
before 0.11.0
363 {
364  return get_uint64("statuses_count");
365 }
const uint_fast64_t get_uint64(const string &key) const
Returns the value of key as std::uint_fast64_t.
Definition: entity.cpp:149

◆ url()

const string Account::url ( ) const

Returns URL of the profile.

Since
before 0.11.0
368 {
369  return get_string("url");
370 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:135

◆ username()

const string Account::username ( ) const

Returns username (without )

Since
before 0.11.0
373 {
374  return get_string("username");
375 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:135

◆ valid()

const bool Account::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.

33 {
34  const std::vector<string> attributes =
35  {{
36  "id",
37  "username",
38  "acct",
39  "display_name",
40  "locked",
41  "created_at",
42  "followers_count",
43  "following_count",
44  "statuses_count",
45  "note",
46  "url",
47  "avatar",
48  "avatar_static",
49  "header",
50  "header_static"
51  }};
52 
53  return Entity::check_valid(attributes);
54 }
const bool check_valid(const std::vector< string > &attributes) const
Checks if an Entity is valid.
Definition: entity.cpp:70

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