mastodon-cpp  0.110.0
Classes | Typedefs | Enumerations | Functions
Mastodon::Easy Namespace Reference

Collection of things that make it easier to interface with server software that implements the Mastodon API. More...

Classes

class  Account
 Class to hold accounts. More...
 
struct  account_field_type
 Describes an account-field. More...
 
struct  alert_type
 Type of notification and 'push is requested or not'. More...
 
class  API
 Child of Mastodon::API with abstract methods. More...
 
class  Application
 Class to hold applications. More...
 
class  Attachment
 Class to hold attachments. More...
 
class  Card
 Class to hold cards. More...
 
class  Context
 Class to hold contexts. More...
 
class  Conversation
 Class to hold conversations. More...
 
class  Emoji
 Class to hold emojis. More...
 
class  Entity
 Base class for all entities. More...
 
class  Filter
 Class to hold filters. More...
 
class  Instance
 Class to hold instances. More...
 
class  Link
 Class to hold the Link-header. More...
 
class  List
 Class to hold lists. More...
 
class  Mention
 Class to hold mentions. More...
 
class  Notification
 Class to hold notifications. More...
 
class  Poll
 Class to hold polls. More...
 
struct  poll_options_type
 Poll options returned by Poll::options(). More...
 
class  PushSubscription
 Class to hold push subscriptions. More...
 
class  Relationship
 Class to hold relationships. More...
 
class  Results
 Class to hold results. More...
 
struct  return_entity
 Return types for calls that return a single Easy::Entity. More...
 
struct  return_entity_vector
 Return types for calls that return multiple Easy::Entitys. More...
 
struct  stats_type
 Statistics returned by Instance::stats(). More...
 
class  Status
 Class to hold statuses. More...
 
struct  stream_event_type
 Used for stream events. More...
 
class  Tag
 Class to hold tags. More...
 
struct  time_type
 Type for time. Converts to time_point and string. More...
 
class  Token
 Class to hold applications. More...
 
struct  urls_type
 URLs returned by Instance::urls(). More...
 

Typedefs

typedef struct Mastodon::Easy::stream_event_type stream_event_type
 Used for stream events. More...
 
typedef stream_event_type stream_event
 
typedef struct Mastodon::Easy::alert_type alert_type
 Type of notification and 'push is requested or not'. More...
 
typedef time_type time
 
typedef struct Mastodon::Easy::account_field_type account_field_type
 Describes an account-field. More...
 
typedef struct Mastodon::Easy::urls_type urls_type
 URLs returned by Instance::urls(). More...
 
typedef struct Mastodon::Easy::stats_type stats_type
 Statistics returned by Instance::stats().
 
typedef struct Mastodon::Easy::poll_options_type poll_options_type
 Poll options returned by Poll::options().
 

Enumerations

enum  event_type {
  Update, Notification, Delete, Error,
  Filters_changed, Undefined
}
 Describes the event type returned in streams. More...
 
enum  visibility_type {
  Direct, Private, Unlisted, Public,
  Undefined
}
 Describes visibility of posts. More...
 
enum  attachment_type {
  Image, Video, Gifv, Unknown,
  Undefined
}
 Describes the attachment type. More...
 
enum  card_type {
  Link, Photo, Video, Rich,
  Undefined
}
 Describes the card type. More...
 
enum  notification_type {
  Mention, Reblog, Favourite, Follow,
  Undefined
}
 Describes the notification type. More...
 
enum  context_type {
  Home, Notifications, Public, Thread,
  Undefined
}
 Describes the context. More...
 

Functions

const vector< string > json_array_to_vector (const string &json)
 Turns a JSON array into a vector of strings. More...
 
const vector< stream_event_typeparse_stream (const std::string &streamdata)
 Split stream into a vector of events. More...
 
const Easy::time_type string_to_time (const string &strtime)
 Convert ISO 8601 time string to Easy::time. More...
 
std::ostream & operator<< (std::ostream &out, const time_type &t)
 

Detailed Description

Collection of things that make it easier to interface with server software that implements the Mastodon API.

Typedef Documentation

◆ account_field_type

Describes an account-field.

Since
0.106.0

◆ alert_type

Type of notification and 'push is requested or not'.

Since
0.100.0

◆ stream_event_type

Used for stream events.

Since
0.100.0

◆ urls_type

URLs returned by Instance::urls().

Since
0.106.0

Enumeration Type Documentation

◆ attachment_type

Describes the attachment type.

Since
before 0.11.0
70  {
71  Image,
72  Video,
73  Gifv,
74  Unknown,
75  Undefined
76  };

◆ card_type

Describes the card type.

Since
before 0.11.0
84  {
85  Link,
86  Photo,
87  Video,
88  Rich,
89  Undefined
90  };

◆ context_type

Describes the context.

Since
0.104.0
112  {
113  Home,
114  Notifications,
115  Public,
116  Thread,
117  Undefined
118  };

◆ event_type

Describes the event type returned in streams.

Since
before 0.11.0
39  {
40  Update,
42  Delete,
43  Error,
44  Filters_changed,
45  Undefined
46  };
Class to hold notifications.
Definition: notification.hpp:40

◆ notification_type

Describes the notification type.

Since
before 0.11.0
98  {
99  Mention,
100  Reblog,
101  Favourite,
102  Follow,
103  Undefined
104  };
Class to hold mentions.
Definition: mention.hpp:39

◆ visibility_type

Describes visibility of posts.

Since
before 0.11.0
55  {
56  Direct,
57  Private,
58  Unlisted,
59  Public,
60  Undefined
61  };

Function Documentation

◆ json_array_to_vector()

const std::vector< string > Mastodon::Easy::json_array_to_vector ( const string &  json)

Turns a JSON array into a vector of strings.

Parameters
jsonJSON string holding the array
Returns
vector of strings or an empty vector on error
Since
before 0.11.0
Examples
example01_get_public_timeline.cpp.
32 {
33  Json::Value json_array;
34  std::stringstream ss(json);
35  ss >> json_array;
36 
37  if (json_array.isArray())
38  {
39  // Transform array of Json::Value to vector of string.
40  std::vector<string> vec(json_array.size());
41  std::transform(json_array.begin(), json_array.end(), vec.begin(),
42  [](const Json::Value &j)
43  { return j.toStyledString(); });
44  return vec;
45  }
46 
47  ttdebug << "ERROR: JSON string holds no array\n";
48  ttdebug << "String was: " << json << '\n';
49  return {};
50 }

◆ operator<<()

std::ostream& Mastodon::Easy::operator<< ( std::ostream &  out,
const time_type t 
)
Since
0.100.0
55  {
56  const string s = t; // Converts using operator const string().
57  out << s;
58  return out;
59  }

◆ parse_stream()

const vector< Easy::stream_event_type > Mastodon::Easy::parse_stream ( const std::string &  streamdata)

Split stream into a vector of events.

Parameters
streamdataData from get_stream()
Returns
vector of Easy::stream_event
Since
before 0.11.0
Examples
example02_stream.cpp.
54 {
55  string stream = streamdata;
56  std::regex reevent("event: (update|notification|delete|filters_changed"
57  "|ERROR)\ndata: (.*)\n");
58  std::smatch match;
59  std::vector<stream_event_type> vec = {};
60 
61  while (std::regex_search(stream, match, reevent))
62  {
63  const string &event = match[1].str();
64  const string &data = match[2].str();
65  event_type type = event_type::Undefined;
66 
67  if (event == "update")
68  type = event_type::Update;
69  else if (event == "notification")
70  type = event_type::Notification;
71  else if (event == "delete")
72  type = event_type::Delete;
73  else if (event == "ERROR")
74  type = event_type::Error;
75  else if (event == "filters_changed")
76  type = event_type::Filters_changed;
77 
78  vec.push_back({ type, data });
79  stream = match.suffix().str();
80  }
81 
82  return vec;
83 }
event_type
Describes the event type returned in streams.
Definition: types_easy.hpp:38

◆ string_to_time()

const Easy::time_type Mastodon::Easy::string_to_time ( const string &  strtime)

Convert ISO 8601 time string to Easy::time.

Parameters
strtimeTime string as returned by Mastodon.
86 {
87  std::stringstream sstime(strtime);
88  struct std::tm tm = {};
89  tm.tm_isdst = -1; // Detect daylight saving time.
90  sstime >> std::get_time(&tm, "%Y-%m-%dT%T");
91  std::time_t time = timegm(&tm); // Assume time is UTC.
92  return { system_clock::from_time_t(time) };
93 }