mastodon-cpp  0.104.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  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...
 
class  Status
 Class to hold statuses. More...
 
struct  stream_event
 Used for stream events. More...
 
class  Tag
 Class to hold tags. More...
 
struct  time
 Type for time. Converts to time_point and string. More...
 
class  Token
 Class to hold applications. More...
 

Typedefs

typedef struct Mastodon::Easy::stream_event stream_event
 Used for stream events. More...
 
typedef struct Mastodon::Easy::alert_type alert_type
 Type of notification and 'push is requested or not'. More...
 
typedef vector< alert_typealerts
 Vector of Easy::alert_type. More...
 

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 std::vector< string > json_array_to_vector (const string &json)
 Turns a JSON array into a vector of strings. More...
 
const std::vector< stream_eventparse_stream (const std::string &streamdata)
 Split stream into a vector of events. More...
 
template<typename T >
std::ostream & operator<< (std::ostream &, const return_entity< T > &)
 

Detailed Description

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

Typedef Documentation

◆ alert_type

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

Since
0.100.0

◆ alerts

Vector of Easy::alert_type.

Used in PushSubscription::alerts().

Since
0.100.0

◆ stream_event

Used for stream events.

Since
0.100.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:48

◆ 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:45

◆ 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 }

◆ parse_stream()

const vector< Easy::stream_event > 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> 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