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

Class to hold source attribute. More...

#include <account.hpp>

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

Public Member Functions

 Source (const string &json)
 Constructs an Account::Source object from a JSON string. More...
 
 Source ()
 Constructs an empty Account::Source object. More...
 
virtual bool valid () const
 Returns true if the Entity holds valid data. More...
 
const std::vector< fields_pairfields () const
 Returns metadata fields. More...
 
Source fields (std::vector< fields_pair > &fields)
 Sets metadata fields. More...
 
const string note () const
 Returns note in plain text. More...
 
Source note (const string &note)
 Sets note. More...
 
visibility_type privacy () const
 Returns default privacy of new toots. More...
 
Source privacy (const visibility_type &privacy)
 Sets default privacy of new toots. More...
 
bool sensitive () const
 Returns if media is marked as sensitive by default. More...
 
Source sensitive (const bool &sensitive)
 Sets if media is marked as sensitive by default. 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 source attribute.

Since
0.18.5

Constructor & Destructor Documentation

◆ Source() [1/2]

Account::Source::Source ( const string &  json)
explicit

Constructs an Account::Source object from a JSON string.

Parameters
jsonJSON string
Since
0.18.5
232 : Entity(json)
233 {}
Entity()
Constructs an empty Entity object.
Definition: entity.cpp:65

◆ Source() [2/2]

Constructs an empty Account::Source object.

Since
0.18.5
236 : Entity()
237 {}
Entity()
Constructs an empty Entity object.
Definition: entity.cpp:65

Member Function Documentation

◆ fields() [1/2]

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

Returns metadata fields.

Since
0.18.5
245 {
246  const Json::Value &node = get("fields");
247 
248  if (node.isArray())
249  {
250  std::vector<Account::fields_pair> vec;
251  for (const Json::Value &value : node)
252  {
253  vec.push_back(Account::fields_pair(value["name"].asString(),
254  value["value"].asString()));
255  }
256  return vec;
257  }
258 
259  return {};
260 }
std::pair< const string, const string > fields_pair
Describes a field. Format: name, value.
Definition: account.hpp:54

◆ fields() [2/2]

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

Sets metadata fields.

Since
0.18.5

◆ note() [1/2]

const string Account::Source::note ( ) const

Returns note in plain text.

Since
0.18.5
279 {
280  return get_string("note");
281 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:134

◆ note() [2/2]

Account::Source Account::Source::note ( const string &  note)

Sets note.

Since
0.18.5
284 {
285  set("note", Json::Value(note));
286  return *this;
287 }
const string note() const
Returns note in plain text.
Definition: account.cpp:278

◆ privacy() [1/2]

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

Returns default privacy of new toots.

Since
0.18.5
290 {
291  const string strprivacy = get_string("privacy");
292  if (strprivacy.compare("public") == 0)
293  return visibility_type::Public;
294  else if (strprivacy.compare("unlisted") == 0)
295  return visibility_type::Unlisted;
296  else if (strprivacy.compare("private") == 0)
297  return visibility_type::Private;
298  else if (strprivacy.compare("direct") == 0)
299  return visibility_type::Direct;
300 
301  ttdebug << "Could not get data: source.privacy\n";
302  return visibility_type::Undefined;
303 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:134

◆ privacy() [2/2]

Account::Source Account::Source::privacy ( const visibility_type privacy)

Sets default privacy of new toots.

Since
0.18.5
306 {
307  string strprivacy = "";
308  switch (privacy)
309  {
310  case visibility_type::Public:
311  {
312  strprivacy = "public";
313  break;
314  }
315  case visibility_type::Unlisted:
316  {
317  strprivacy = "unlisted";
318  break;
319  }
320  case visibility_type::Private:
321  {
322  strprivacy = "private";
323  break;
324  }
325  case visibility_type::Direct:
326  {
327  strprivacy = "direct";
328  break;
329  }
330  default:
331  {
332  strprivacy = "undefined";
333  break;
334  }
335  }
336  set("privacy", Json::Value(strprivacy));
337  return *this;
338 }
visibility_type privacy() const
Returns default privacy of new toots.
Definition: account.cpp:289

◆ sensitive() [1/2]

bool Account::Source::sensitive ( ) const

Returns if media is marked as sensitive by default.

Since
0.18.5
341 {
342  return get_bool("sensitive");
343 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:176

◆ sensitive() [2/2]

Account::Source Account::Source::sensitive ( const bool &  sensitive)

Sets if media is marked as sensitive by default.

Since
0.18.5
346 {
347  set("source", Json::Value(sensitive));
348  return *this;
349 }
bool sensitive() const
Returns if media is marked as sensitive by default.
Definition: account.cpp:340

◆ valid()

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

240 {
241  return true;
242 }

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