mastodon-cpp  0.106.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  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  PushSubscription
 Class to hold push subscriptions. More...
 
class  Relationship
 Class to hold relationships. More...
 
class  Report
 Class to hold reports. 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().
 

Enumerations

enum  event_type {
  Update, Notification, Delete, Error,
  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
69  {
70  Image,
71  Video,
72  Gifv,
73  Unknown,
74  Undefined
75  };

◆ card_type

Describes the card type.

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

◆ context_type

Describes the context.

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

◆ event_type

Describes the event type returned in streams.

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

◆ notification_type

Describes the notification type.

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

◆ visibility_type

Describes visibility of posts.

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

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|ERROR)\ndata: (.*)\n");
57  std::smatch match;
58  std::vector<stream_event_type> vec = {};
59 
60  while (std::regex_search(stream, match, reevent))
61  {
62  const string &event = match[1].str();
63  const string &data = match[2].str();
64  event_type type = event_type::Undefined;
65 
66  if (event.compare("update") == 0)
67  type = event_type::Update;
68  else if (event.compare("notification") == 0)
69  type = event_type::Notification;
70  else if (event.compare("delete") == 0)
71  type = event_type::Delete;
72  else if (event.compare("ERROR") == 0)
73  type = event_type::Error;
74 
75  vec.push_back({ type, data });
76  stream = match.suffix().str();
77  }
78 
79  return vec;
80 }
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.
83 {
84  std::stringstream sstime(strtime);
85  struct std::tm tm = {};
86  tm.tm_isdst = -1; // Detect daylight saving time.
87  sstime >> std::get_time(&tm, "%Y-%m-%dT%T");
88  std::time_t time = timegm(&tm); // Assume time is UTC.
89  return { system_clock::from_time_t(time) };
90 }