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

Class to hold polls. More...

#include <poll.hpp>

Inheritance diagram for Mastodon::Easy::Poll:
Mastodon::Easy::Entity

Public Member Functions

virtual bool valid () const override
 Returns true if the Entity holds valid data. More...
 
const string id () const
 Returns poll ID. More...
 
const Easy::time_type expires_at () const
 Returns time when the poll expires. More...
 
bool expired () const
 Returns true if poll has expired. More...
 
bool multiple () const
 Returns true or false. More...
 
uint64_t votes_count () const
 Returns the number of votes. More...
 
const vector< poll_options_typeoptions () const
 Returns poll options and their votes count. More...
 
bool voted () const
 Returns whether you voted or not. 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 polls.

Since
0.110.0

Member Function Documentation

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

◆ Entity() [3/3]

Easy::Entity::Entity

Constructs an empty Entity object.

Since
before 0.11.0
44 : _tree(Json::nullValue)
45 , _was_set(false)
46 {}

◆ expired()

bool Poll::expired ( ) const

Returns true if poll has expired.

Since
0.110.0
47 {
48  return get_bool("expired");
49 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:216

◆ expires_at()

const Easy::time_type Poll::expires_at ( ) const

Returns time when the poll expires.

Since
0.110.0
42 {
43  return get_time("expires_at");
44 }
const Easy::time_type get_time(const string &key) const
Returns the value of key as Easy::time.
Definition: entity.cpp:230

◆ id()

const string Poll::id ( ) const

Returns poll ID.

Since
0.110.0
37 {
38  return get_string("id");
39 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ multiple()

bool Poll::multiple ( ) const

Returns true or false.

Since
0.110.0
52 {
53  return get_bool("multiple");
54 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:216

◆ options()

const vector< Easy::poll_options_type > Poll::options ( ) const

Returns poll options and their votes count.

Since
0.110.0
62 {
63  const Json::Value &node = get("options");
64 
65  if (node.isArray())
66  {
67  vector<Easy::poll_options_type> vec_options;
68  std::transform(node.begin(), node.end(), std::back_inserter(vec_options),
69  [](const Json::Value &value)
70  {
72  {
73  value["title"].asString(),
74  value["votes_count"].asUInt64()
75  });
76  });
77  return vec_options;
78  }
79 
80  return {};
81 }
const Json::Value get(const string &key) const
Returns the value of key as Json::Value.
Definition: entity.cpp:133
struct Mastodon::Easy::poll_options_type poll_options_type
Poll options returned by Poll::options().

◆ valid()

bool Poll::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.

24 {
25  return Entity::check_valid(
26  {
27  "id",
28  "expired",
29  "expired",
30  "multiple",
31  "votes_count",
32  "options"
33  });
34 }
bool check_valid(const std::vector< string > &attributes) const
Checks if an Entity is valid.
Definition: entity.cpp:102

◆ voted()

bool Poll::voted ( ) const

Returns whether you voted or not.

Since
0.110.0
84 {
85  return get_bool("voted");
86 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:216

◆ votes_count()

uint64_t Poll::votes_count ( ) const

Returns the number of votes.

Since
0.110.0
57 {
58  return get_uint64("votes_count");
59 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:188

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