mastodon-cpp  0.16.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | List of all members
Mastodon::Easy Class Reference

Child of Mastodon::API with abstract methods. More...

#include <easy.hpp>

Inheritance diagram for Mastodon::Easy:
Mastodon::API

Classes

class  Account
 Class to hold accounts. 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  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...
 
class  Status
 Class to hold statuses. More...
 
class  Tag
 Class to hold tags. More...
 

Public Types

enum  event_type { Update, Notification, Delete, Undefined }
 Describes the event type.
 
enum  visibility_type {
  Direct, Private, Unlisted, Public,
  Undefined
}
 Describes visibility of toots.
 
enum  attachment_type {
  Image, Video, Gifv, Unknown,
  Undefined
}
 Describes the attachment type.
 
enum  card_type {
  Link, Photo, Video, Rich,
  Undefined
}
 Describes the card type.
 
enum  notification_type {
  Mention, Reblog, Favourite, Follow,
  Undefined
}
 Describes the notification type.
 
typedef std::pair< event_type, string > stream_event
 Used for stream events.
 
typedef std::map< Easy::notification_type, bool > alertmap
 Map of 'notification type' and 'push is requested or not'. More...
 
- Public Types inherited from Mastodon::API
enum  v1 {
  accounts_id, accounts_verify_credentials, accounts_id_followers, accounts_id_following,
  accounts_id_statuses, accounts_relationships, accounts_search, blocks,
  domain_blocks, favourites, follow_requests, instance,
  custom_emojis, lists, accounts_id_lists, lists_id_accounts,
  lists_id, mutes, notifications, notifications_id,
  reports, search, statuses_id, statuses_id_context,
  statuses_id_card, statuses_id_reblogged_by, statuses_id_favourited_by, timelines_home,
  timelines_public, timelines_tag_hashtag, timelines_list_list_id, accounts_update_credentials,
  accounts_id_follow, accounts_id_unfollow, accounts_id_block, accounts_id_unblock,
  accounts_id_mute, accounts_id_unmute, apps, follow_requests_id_authorize,
  follow_requests_id_reject, follows, media, notifications_clear,
  notifications_dismiss, statuses, statuses_id_reblog, statuses_id_unreblog,
  statuses_id_favourite, statuses_id_unfavourite, statuses_id_pin, statuses_id_unpin,
  statuses_id_mute, statuses_id_unmute, media_id, streaming_user,
  streaming_public, streaming_public_local, streaming_hashtag, streaming_list,
  push_subscription
}
 A list of all API calls. More...
 
enum  v2 { search }
 
typedef std::map< string, std::vector< string > > parametermap
 Used for passing parameters. More...
 

Public Member Functions

 Easy (const string &instance, const string &access_token)
 Constructs a new Easy object. More...
 
const Link get_link () const
 Gets the links from the last answer.
 
- Public Member Functions inherited from Mastodon::API
 API (const string &instance, const string &access_token)
 Constructs a new API object. More...
 
const void set_useragent (const string &useragent)
 Sets the useragent. Default is mastodon-cpp/version. More...
 
const string get_useragent () const
 Gets the useragent. More...
 
const string get_instance () const
 Returns the instance. More...
 
const uint_fast16_t register_app1 (const string &client_name, const string &redirect_uri, const string &scopes, const string &website, string &client_id, string &client_secret, string &url)
 Register application, step 1/2. More...
 
const uint_fast16_t register_app1 (const string &instance, const string &client_name, const string &redirect_uri, const string &scopes, const string &website, string &client_id, string &client_secret, string &url)
 
const uint_fast16_t register_app2 (const string &client_id, const string &client_secret, const string &redirect_uri, const string &code, string &access_token)
 Register application, step 2/2. More...
 
const uint_fast16_t register_app2 (const string &instance, const string &client_id, const string &client_secret, const string &redirect_uri, const string &code, string &access_token)
 
const string get_header (const string &header) const
 Gets the header from the last answer. More...
 
bool exceptions (const bool &value)
 Turn exceptions on or off. Defaults to off. More...
 
const bool exceptions () const
 Returns true if exceptions are turned on, false otherwise.
 
const void set_proxy (const string &proxy, const string &userpw="")
 Sets the proxy. More...
 
const void get_proxy (string &proxy, string &userpw) const
 For internal use. More...
 
const uint_fast16_t get (const Mastodon::API::v1 &call, string &answer)
 Make a GET request which doesn't require parameters. More...
 
const uint_fast16_t get (const Mastodon::API::v1 &call, const parametermap &parameters, string &answer)
 Make a GET request which requires parameters. More...
 
const uint_fast16_t get (const Mastodon::API::v2 &call, const parametermap &parameters, string &answer)
 Make a GET request which requires parameters. More...
 
const uint_fast16_t get (const string &call, string &answer)
 Make a custom GET request. More...
 
const uint_fast16_t get (const Mastodon::API::v1 &call, const string &argument, string &answer)
 
const uint_fast16_t get (const Mastodon::API::v1 &call, const string &argument, const parametermap &parameters, string &answer)
 
const uint_fast16_t get_stream (const Mastodon::API::v1 &call, const parametermap &parameters, string &answer, std::unique_ptr< Mastodon::API::http > &ptr)
 Make a streaming GET request. More...
 
const uint_fast16_t get_stream (const Mastodon::API::v1 &call, string &answer, std::unique_ptr< Mastodon::API::http > &ptr)
 Make a streaming GET request. More...
 
const uint_fast16_t get_stream (const string &call, string &answer, std::unique_ptr< Mastodon::API::http > &ptr)
 Make a streaming GET request. More...
 
const uint_fast16_t get_stream (const Mastodon::API::v1 &call, const string &argument, string &answer, std::unique_ptr< Mastodon::API::http > &ptr)
 
const uint_fast16_t patch (const Mastodon::API::v1 &call, const parametermap &parameters, string &answer)
 Make a PATCH request. More...
 
const uint_fast16_t post (const Mastodon::API::v1 &call, string &answer)
 Make a POST request which doesn't require parameters. More...
 
const uint_fast16_t post (const Mastodon::API::v1 &call, const parametermap &parameters, string &answer)
 Make a POST request which requires parameters. More...
 
const uint_fast16_t post (const string &call, const parametermap &parameters, string &answer)
 Make a custom POST request. More...
 
const uint_fast16_t post (const Mastodon::API::v1 &call, const string &argument, string &answer)
 
const uint_fast16_t post (const Mastodon::API::v1 &call, const string &argument, const parametermap &parameters, string &answer)
 
const uint_fast16_t put (const Mastodon::API::v1 &call, const parametermap &parameters, string &answer)
 Make a PUT request which requires a parameters. More...
 
const uint_fast16_t put (const string &call, const parametermap &parameters, string &answer)
 Make a custom PUT request. More...
 
const uint_fast16_t put (const Mastodon::API::v1 &call, const string &argument, const parametermap &parameters, string &answer)
 
const uint_fast16_t del (const Mastodon::API::v1 &call, const parametermap &parameters)
 Make a DELETE request which requires parameters. More...
 
const uint_fast16_t del (const string &call, const parametermap &parameters, string &answer)
 Make a custom DELETE request. More...
 
const uint_fast16_t del (const Mastodon::API::v1 &call, const string &argument)
 
const uint_fast16_t del (const Mastodon::API::v1 &call, const string &argument, const parametermap &parameters)
 

Static Public Member Functions

static const std::vector< string > json_array_to_vector (const string &json)
 Turns a JSON array into a vector of strings. More...
 
static const std::vector< stream_eventparse_stream (const std::string &streamdata)
 Split stream into a vector of events. More...
 
static const string strtime_utc (const system_clock::time_point &timepoint, const string &format)
 Converts a time_point to a string. More...
 
static const string strtime_local (const system_clock::time_point &timepoint, const string &format)
 See strtime_utc. More...
 
- Static Public Member Functions inherited from Mastodon::API
static const string urlencode (const string &str)
 Percent-encodes a string. This is done automatically, unless you make a custom request. More...
 
static const string unescape_html (const string &html)
 Replaces HTML entities with UTF-8 characters. More...
 

Static Protected Member Functions

static const string strtime (const system_clock::time_point &timepoint, const string &format, const bool &utc)
 

Detailed Description

Child of Mastodon::API with abstract methods.

Examples:
example12_easy_laststatus.cpp, example13_easy_stream.cpp, example14_easy_treeview.cpp, and example16_account_fields.cpp.

Member Typedef Documentation

◆ alertmap

Map of 'notification type' and 'push is requested or not'.

Used in PushSubscription::alerts().

Constructor & Destructor Documentation

◆ Easy()

Easy::Easy ( const string &  instance,
const string &  access_token 
)
explicit

Constructs a new Easy object.

To register your application, leave access_token blank and call register_app1() and register_app2().

Parameters
instanceThe hostname of your instance
access_tokenThe access token
28 : API(instance, access_token)
29 {}
API(const string &instance, const string &access_token)
Constructs a new API object.
Definition: mastodon-cpp.cpp:30

Member Function Documentation

◆ json_array_to_vector()

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

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
32 {
33  Json::Value json_array;
34  std::stringstream ss(json);
35  ss >> json_array;
36 
37  if (json_array.isArray())
38  {
39  std::vector<string> vec;
40  for (const Json::Value &value : json_array)
41  {
42  vec.push_back(value.toStyledString());
43  }
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 std::vector< Easy::stream_event > Easy::parse_stream ( const std::string &  streamdata)
static

Split stream into a vector of events.

Parameters
streamdataData from get_stream()
Returns
vector of stream events
54 {
55  string stream = streamdata;
56  std::regex reevent("event: (update|notification|delete)\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 
73  vec.push_back(stream_event(type, data));
74  stream = match.suffix().str();
75  }
76 
77  return vec;
78 }
event_type
Describes the event type.
Definition: easy.hpp:50
std::pair< event_type, string > stream_event
Used for stream events.
Definition: easy.hpp:109

◆ strtime_local()

const string Easy::strtime_local ( const system_clock::time_point &  timepoint,
const string &  format 
)
static

See strtime_utc.

Returns
The local time as string
Since
0.11.0
93 {
94  return strtime(timepoint, format, false);
95 }

◆ strtime_utc()

const string Easy::strtime_utc ( const system_clock::time_point &  timepoint,
const string &  format 
)
static

Converts a time_point to a string.

The return value can not exceed 1023 chars.

Parameters
timepointThe timepoint
formatThe format of the string, same as with strftime.

Example:

auto timepoint = status.created_at();
cout << Easy::strtime_utc(timepoint, "%F, %T") << '\n';
Returns
The UTC time as string
Since
0.11.0
87 {
88  return strtime(timepoint, format, true);
89 }

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