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

Class to hold notifications. More...

#include <notification.hpp>

Inheritance diagram for Mastodon::Easy::Notification:
Mastodon::Easy::Entity

Public Member Functions

 Notification (const string &json)
 Constructs a Notification object from a JSON string. More...
 
 Notification ()
 Constructs an empty Notification object. More...
 
virtual bool valid () const
 Returns true if the Entity holds valid data. More...
 
const Account account () const
 Returns the Account sending the notification to the user. More...
 
const system_clock::time_point created_at () const
 Returns time of creation. More...
 
uint_fast64_t id () const
 Returns notification ID. More...
 
const Status status () const
 Returns the Status associated with the notification, if applicable. More...
 
Easy::notification_type type () const
 Returns notification type. 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 notifications.

Since
before 0.11.0

Constructor & Destructor Documentation

◆ Notification() [1/2]

Notification::Notification ( const string &  json)
explicit

Constructs a Notification object from a JSON string.

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

◆ Notification() [2/2]

Notification::Notification ( )

Constructs an empty Notification object.

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

Member Function Documentation

◆ account()

const Easy::Account Notification::account ( ) const

Returns the Account sending the notification to the user.

Since
before 0.11.0
45 {
46  const Json::Value node = get("account");
47  if (node.isObject())
48  {
49  return Easy::Account(node.toStyledString());
50  }
51 
52  ttdebug << "Could not get data: account\n";
53  return Easy::Account();
54 }
Class to hold accounts.
Definition: account.hpp:46

◆ created_at()

const system_clock::time_point Notification::created_at ( ) const

Returns time of creation.

Since
before 0.11.0
57 {
58  return get_time_point("created_at");
59 }
const system_clock::time_point get_time_point(const string &key) const
Returns the value of key as time_point.
Definition: entity.cpp:191

◆ id()

uint_fast64_t Notification::id ( ) const

Returns notification ID.

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

◆ status()

const Easy::Status Notification::status ( ) const

Returns the Status associated with the notification, if applicable.

Since
before 0.11.0
67 {
68  const Json::Value node = get("status");
69  if (node.isObject())
70  {
71  return Easy::Status(node.toStyledString());
72  }
73 
74  ttdebug << "Could not get data: status\n";
75  return Easy::Status();
76 }
Class to hold statuses.
Definition: status.hpp:59

◆ type()

Easy::notification_type Notification::type ( ) const

Returns notification type.

Since
before 0.11.0
79 {
80  const string strtype = get_string("type");
81  if (strtype.compare("mention") == 0)
82  return notification_type::Mention;
83  else if (strtype.compare("reblog") == 0)
84  return notification_type::Reblog;
85  else if (strtype.compare("favourite") == 0)
86  return notification_type::Favourite;
87  else if (strtype.compare("follow") == 0)
88  return notification_type::Follow;
89 
90  return notification_type::Undefined;
91 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:134

◆ valid()

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

32 {
33  const std::vector<string> attributes =
34  {{
35  "id",
36  "type",
37  "created_at",
38  "account"
39  }};
40 
41  return Entity::check_valid(attributes);
42 }
bool check_valid(const std::vector< string > &attributes) const
Checks if an Entity is valid.
Definition: entity.cpp:69

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