mastodon-cpp  0.19.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
Mastodon::API Class Reference

Class for the Mastodon API. More...

#include <mastodon-cpp.hpp>

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

Classes

class  http
 http class. Do not use this directly. More...
 

Public Types

enum  v1 {
  accounts_id, accounts_verify_credentials, accounts_id_followers, accounts_id_following,
  accounts_id_statuses, accounts_relationships, accounts_search, blocks,
  domain_blocks, endorsements, 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, accounts_id_pin,
  accounts_id_unpin, 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 v1 API calls. More...
 
enum  v2 { search }
 A list of all v2 API calls. More...
 
typedef std::map< string, std::vector< string > > parametermap
 Used for passing parameters. More...
 

Public Member Functions

 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 string urlencode (const string &str)
 Percent-encodes a string. This is done automatically, unless you make a custom request. More...
 
static const string urldecode (const string &str)
 Decodes a percent-encoded string. More...
 
static const string unescape_html (const string &html)
 Replaces HTML entities with UTF-8 characters. More...
 

Detailed Description

Class for the Mastodon API.

All input is expected to be UTF-8. Binary data must be base64-encoded or a filename. It appears that media attachements can not be base64 encoded.

Error codes

mastodon-cpp will never use error codes below 11, except 0.

Code Explanation
0 No error
11 Invalid call
12 Not implemented
13 URL changed (HTTP 301 or 308)
14 Cancelled by user
15 Network error (curlpp exception)
16 Timeout
100 - 999 HTTP status codes
65535 Unknown error
Since
before 0.11.0
Examples:
example01_dump_json.cpp, example02_parse_account.cpp, example03_mastocron.cpp, example04_update_credentials.cpp, example05_follow_unfollow.cpp, example06_toot_delete-toot.cpp, example07_register_app.cpp, example08_rate_limiting.cpp, example09_streaming_api.cpp, example10_simplify.cpp, example11_post_media.cpp, example12_easy_laststatus.cpp, example13_easy_stream.cpp, example14_easy_treeview.cpp, example15_proxy.cpp, and example16_account_fields.cpp.

Member Typedef Documentation

◆ parametermap

typedef std::map<string, std::vector<string> > Mastodon::API::parametermap

Used for passing parameters.

Example:

{
{"field1", { "value1", "value2" } },
{"field2", { "value" } }
}
Since
before 0.11.0

Member Enumeration Documentation

◆ v1

enum Mastodon::API::v1
strong

A list of all v1 API calls.

The original / are substituted by _.

Since
before 0.11.0
199  {
200  accounts_id,
201  accounts_verify_credentials,
202  accounts_id_followers,
203  accounts_id_following,
204  accounts_id_statuses,
205  accounts_relationships,
206  accounts_search,
207  blocks,
208  domain_blocks,
209  endorsements,
210  favourites,
211  follow_requests,
212  instance,
213  custom_emojis,
214  lists,
215  accounts_id_lists,
216  lists_id_accounts,
217  lists_id,
218  mutes,
219  notifications,
220  notifications_id,
221  reports,
222  search,
223  statuses_id,
224  statuses_id_context,
225  statuses_id_card,
226  statuses_id_reblogged_by,
227  statuses_id_favourited_by,
228  timelines_home,
229  timelines_public,
230  timelines_tag_hashtag,
231  timelines_list_list_id,
232  // PATCH
233  accounts_update_credentials,
234  // POST
235  accounts_id_follow,
236  accounts_id_unfollow,
237  accounts_id_block,
238  accounts_id_unblock,
239  accounts_id_mute,
240  accounts_id_unmute,
241  accounts_id_pin,
242  accounts_id_unpin,
243  apps,
244  follow_requests_id_authorize,
245  follow_requests_id_reject,
246  follows,
247  media,
248  notifications_clear,
249  notifications_dismiss,
250  statuses,
251  statuses_id_reblog,
252  statuses_id_unreblog,
253  statuses_id_favourite,
254  statuses_id_unfavourite,
255  statuses_id_pin,
256  statuses_id_unpin,
257  statuses_id_mute,
258  statuses_id_unmute,
259  // PUT
260  media_id,
261  // Streaming
262  streaming_user,
263  streaming_public,
264  streaming_public_local,
265  streaming_hashtag,
266  streaming_list,
267  // Push
268  push_subscription
269  };

◆ v2

enum Mastodon::API::v2
strong

A list of all v2 API calls.

The original / are substituted by _.

Since
0.16.0
279  {
280  search
281  };

Constructor & Destructor Documentation

◆ API()

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

Constructs a new API object.

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

Parameters
instanceThe hostname of your instance
access_tokenYour access token.
Since
before 0.11.0
Examples:
example10_simplify.cpp.
31 : _instance(instance)
32 , _access_token(access_token)
33 , _useragent(string("mastodon-cpp/") + global::version)
34 , _http(*this, instance, access_token)
35 , _exceptions(false)
36 , _proxy("")
37 , _proxy_userpw("")
38 {
39  //
40 }

Member Function Documentation

◆ del() [1/2]

const uint_fast16_t API::del ( const Mastodon::API::v1 call,
const parametermap parameters 
)

Make a DELETE request which requires parameters.

Parameters
callA call defined in Mastodon::API::v1
parametersA Mastodon::API::parametermap containing parameters
Returns
Error code.
Since
before 0.11.0
Examples:
example06_toot_delete-toot.cpp.
25 {
26  string strcall = "";
27  string strid = "";
28 
29  // The ID is part of the path
30  const auto &it = parameters.find("id");
31  if (it != parameters.end())
32  {
33  strid = it->second[0];
34  }
35 
36  switch (call)
37  {
38  case v1::domain_blocks:
39  strcall = "/api/v1/domain_blocks";
40  break;
41  case v1::lists_id:
42  strcall = "/api/v1/lists/" + strid;
43  break;
44  case v1::lists_id_accounts:
45  strcall = "/api/v1/lists/" + strid + "/accounts";
46  break;
47  case v1::statuses_id:
48  strcall = "/api/v1/statuses/" + strid;
49  break;
50  case v1::push_subscription:
51  strcall = "/api/v1/push/subscription";
52  break;
53  default:
54  ttdebug << "ERROR: Invalid call.\n";
55  return 11;
56  break;
57  }
58 
59  string answer;
60  return del(strcall, parameters, answer);
61 }
const uint_fast16_t del(const Mastodon::API::v1 &call, const parametermap &parameters)
Make a DELETE request which requires parameters.
Definition: delete.cpp:23

◆ del() [2/2]

const uint_fast16_t Mastodon::API::del ( const string &  call,
const parametermap parameters,
string &  answer 
)

Make a custom DELETE request.

Parameters
callString in the form /api/v1/example
parametersA Mastodon::API::parametermap containing parameters
answerThe answer from the server. Usually JSON. On error an empty string.
Returns
Error code. If the URL has permanently changed, 13 is returned and answer is set to the new URL.
Since
before 0.11.0

◆ exceptions()

bool API::exceptions ( const bool &  value)

Turn exceptions on or off. Defaults to off.

This applies to exceptions from curlpp. curlpp::RuntimeError and curlpp::LogicError.

Parameters
valuetrue for on, false for off
Returns
true if exceptions are turned on, false otherwise
Since
before 0.11.0
278 {
279  _exceptions = value;
280  return _exceptions;
281 }

◆ get() [1/4]

const uint_fast16_t API::get ( const Mastodon::API::v1 call,
string &  answer 
)

Make a GET request which doesn't require parameters.

Parameters
callA call defined in Mastodon::API::v1
answerThe answer from the server. Usually JSON. On error an empty string.
Returns
Error code.
Since
before 0.11.0
Examples:
example01_dump_json.cpp, example02_parse_account.cpp, example03_mastocron.cpp, example07_register_app.cpp, example08_rate_limiting.cpp, and example15_proxy.cpp.
205 {
206  const parametermap p;
207  return get(call, p, answer);
208 }
std::map< string, std::vector< string > > parametermap
Used for passing parameters.
Definition: mastodon-cpp.hpp:189

◆ get() [2/4]

const uint_fast16_t API::get ( const Mastodon::API::v1 call,
const parametermap parameters,
string &  answer 
)

Make a GET request which requires parameters.

Parameters
callA call defined in Mastodon::API::v1
parametersA Mastodon::API::parametermap containing parameters
answerThe answer from the server. Usually JSON. On error an empty string.
Returns
Error code. If the URL has permanently changed, 13 is returned and answer is set to the new URL.
26 {
27  string strcall = "";
28  string strid = "";
29 
30  // The ID is part of the path
31  const auto &it = parameters.find("id");
32  if (it != parameters.end())
33  {
34  strid = it->second[0];
35  }
36 
37  switch (call)
38  {
39  case v1::accounts_verify_credentials:
40  strcall = "/api/v1/accounts/verify_credentials";
41  break;
42  case v1::blocks:
43  strcall = "/api/v1/blocks";
44  break;
45  case v1::domain_blocks:
46  strcall = "/api/v1/domain_blocks";
47  break;
48  case v1::favourites:
49  strcall = "/api/v1/favourites";
50  break;
51  case v1::follow_requests:
52  strcall = "/api/v1/follow_requests";
53  break;
54  case v1::instance:
55  strcall = "/api/v1/instance";
56  break;
57  case v1::custom_emojis:
58  strcall = "/api/v1/custom_emojis";
59  break;
60  case v1::lists:
61  strcall = "/api/v1/lists";
62  break;
63  case v1::mutes:
64  strcall = "/api/v1/mutes";
65  break;
66  case v1::notifications:
67  strcall = "/api/v1/notifications";
68  break;
69  case v1::reports:
70  strcall = "/api/v1/reports";
71  break;
72  case v1::timelines_home:
73  strcall = "/api/v1/timelines/home";
74  break;
75  case v1::timelines_public:
76  strcall = "/api/v1/timelines/public";
77  break;
78  case v1::accounts_relationships:
79  strcall = "/api/v1/accounts/relationships";
80  break;
81  case v1::accounts_id:
82  strcall = "/api/v1/accounts/" + strid;
83  break;
84  case v1::accounts_id_followers:
85  strcall = "/api/v1/accounts/" + strid + "/followers";
86  break;
87  case v1::accounts_id_following:
88  strcall = "/api/v1/accounts/" + strid + "/following";
89  break;
90  case v1::accounts_id_statuses:
91  strcall = "/api/v1/accounts/" + strid + "/statuses";
92  break;
93  case v1::accounts_search:
94  strcall = "/api/v1/accounts/search";
95  break;
96  case v1::accounts_id_lists:
97  strcall = "/api/v1/accounts/" + strid + "/lists";
98  break;
99  case v1::lists_id_accounts:
100  strcall = "/api/v1/lists/" + strid + "/accounts";
101  break;
102  case v1::lists_id:
103  strcall = "/api/v1/lists/" + strid;
104  break;
105  case v1::notifications_id:
106  strcall = "/api/v1/notifications/" + strid;
107  break;
108  case v1::search:
109  strcall = "/api/v1/search";
110  break;
111  case v1::statuses_id:
112  strcall = "/api/v1/statuses/" + strid;
113  break;
114  case v1::statuses_id_context:
115  strcall = "/api/v1/statuses/" + strid + "/context";
116  break;
117  case v1::statuses_id_card:
118  strcall = "/api/v1/statuses/" + strid + "/card";
119  break;
120  case v1::statuses_id_reblogged_by:
121  strcall = "/api/v1/statuses/" + strid + "/reblogged_by";
122  break;
123  case v1::statuses_id_favourited_by:
124  strcall = "/api/v1/statuses/" + strid + "/favourited_by";
125  break;
126  case v1::timelines_tag_hashtag:
127  {
128  // The hashtag is part of the path
129  const auto &it = parameters.find("hashtag");
130  if (it != parameters.end())
131  {
132  strcall = "/api/v1/timelines/tag/" + urlencode(it->second[0]);
133  }
134  else
135  {
136  ttdebug << "ERROR: Invalid call.\n";
137  return 11;
138  }
139  }
140  break;
141  case v1::timelines_list_list_id:
142  strcall = "/api/v1/timelines/list/" + strid;
143  break;
144  case v1::push_subscription:
145  strcall = "/api/v1/push/subscription";
146  break;
147  case v1::endorsements:
148  strcall = "/api/v1/endorsements";
149  break;
150  default:
151  ttdebug << "ERROR: Invalid call.\n";
152  return 11;
153  break;
154  }
155 
156  if (parameters.size() > 0)
157  {
158  // Delete the parameters that are already in strcall
159  parametermap newparameters = parameters;
160  newparameters.erase("id");
161  newparameters.erase("hashtag");
162  strcall += maptostr(newparameters);
163  }
164 
165  return get(strcall, answer);
166 }
static const string urlencode(const string &str)
Percent-encodes a string. This is done automatically, unless you make a custom request.
Definition: mastodon-cpp.cpp:141
std::map< string, std::vector< string > > parametermap
Used for passing parameters.
Definition: mastodon-cpp.hpp:189

◆ get() [3/4]

const uint_fast16_t API::get ( const Mastodon::API::v2 call,
const parametermap parameters,
string &  answer 
)

Make a GET request which requires parameters.

Since
0.16.0
170 {
171  string strcall = "";
172  string strid = "";
173 
174  // The ID is part of the path
175  const auto &it = parameters.find("id");
176  if (it != parameters.end())
177  {
178  strid = it->second[0];
179  }
180 
181  switch (call)
182  {
183  case v2::search:
184  strcall = "/api/v2/search";
185  break;
186  default:
187  ttdebug << "ERROR: Invalid call.\n";
188  return 11;
189  break;
190  }
191 
192  if (parameters.size() > 0)
193  {
194  // Delete the parameters that are already in strcall
195  parametermap newparameters = parameters;
196  newparameters.erase("id");
197  newparameters.erase("hashtag");
198  strcall += maptostr(newparameters);
199  }
200 
201  return get(strcall, answer);
202 }
std::map< string, std::vector< string > > parametermap
Used for passing parameters.
Definition: mastodon-cpp.hpp:189

◆ get() [4/4]

const uint_fast16_t Mastodon::API::get ( const string &  call,
string &  answer 
)

Make a custom GET request.

Parameters
callString in the form /api/v1/example
answerThe answer from the server. Usually JSON. On error an empty string.
Returns
Error code. If the URL has permanently changed, 13 is returned and answer is set to the new URL.
Since
before 0.11.0

◆ get_header()

const string API::get_header ( const string &  header) const

Gets the header from the last answer.

Parameters
headerThe header to get
Returns
The header, or "" on error.
Since
before 0.11.0
Examples:
example08_rate_limiting.cpp.
263 {
264  string headers;
265  _http.get_headers(headers);
266  size_t startpos = headers.find(header + ':');
267  if (startpos != std::string::npos)
268  {
269  startpos = headers.find(':', startpos) + 2;
270  size_t endpos = headers.find("\r\n", startpos);
271  return headers.substr(startpos, endpos - startpos);
272  }
273 
274  return "";
275 }
const void get_headers(string &headers) const
Get all headers in a string.
Definition: http.cpp:197

◆ get_instance()

const string API::get_instance ( ) const

Returns the instance.

Returns
The instance.
Since
before 0.11.0
53 {
54  return _instance;
55 }

◆ get_proxy()

const void API::get_proxy ( string &  proxy,
string &  userpw 
) const

For internal use.

Parameters
proxyURL
userpwusername:password
Since
0.15.1
596 {
597  if (!_proxy.empty())
598  {
599  proxy = _proxy;
600  if (!_proxy_userpw.empty())
601  {
602  userpw = _proxy_userpw;
603  }
604  }
605 }

◆ get_stream() [1/3]

const uint_fast16_t API::get_stream ( const Mastodon::API::v1 call,
const parametermap parameters,
string &  answer,
std::unique_ptr< Mastodon::API::http > &  ptr 
)

Make a streaming GET request.

Parameters
callA call defined in Mastodon::API::v1
parametersA Mastodon::API::parametermap containing parameters
answerThe answer from the server. Events with JSON-payload.
ptrPointer to the http object. Can be used to call ptr->cancel_stream()
Returns
Error code. If the URL has permanently changed, 13 is returned and answer is set to the new URL.
Since
before 0.11.0
Examples:
example09_streaming_api.cpp.
28 {
29  string strcall = "";
30 
31  switch (call)
32  {
33  case v1::streaming_user:
34  strcall = "/api/v1/streaming/user";
35  break;
36  case v1::streaming_public:
37  strcall = "/api/v1/streaming/public";
38  break;
39  case v1::streaming_public_local:
40  strcall = "/api/v1/streaming/public/local";
41  break;
42  case v1::streaming_hashtag:
43  strcall = "/api/v1/streaming/hashtag";
44  break;
45  case v1::streaming_list:
46  strcall = "/api/v1/streaming/list";
47  break;
48  default:
49  ttdebug << "ERROR: Invalid call.\n";
50  return 11;
51  break;
52  }
53 
54  if (parameters.size() > 0)
55  {
56  strcall += maptostr(parameters);
57  }
58 
59  return get_stream(strcall, answer, ptr);
60 }
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.
Definition: get_stream.cpp:24

◆ get_stream() [2/3]

const uint_fast16_t API::get_stream ( const Mastodon::API::v1 call,
string &  answer,
std::unique_ptr< Mastodon::API::http > &  ptr 
)

Make a streaming GET request.

Parameters
callA call defined in Mastodon::API::v1
answerThe answer from the server. Events with JSON-payload.
ptrPointer to the http object. Can be used to call ptr->cancel_stream()
Returns
Error code. If the URL has permanently changed, 13 is returned and answer is set to the new URL.
Since
before 0.11.0
65 {
66  parametermap p = {};
67  return get_stream(call, p, answer, ptr);
68 }
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.
Definition: get_stream.cpp:24
std::map< string, std::vector< string > > parametermap
Used for passing parameters.
Definition: mastodon-cpp.hpp:189

◆ get_stream() [3/3]

const uint_fast16_t Mastodon::API::get_stream ( const string &  call,
string &  answer,
std::unique_ptr< Mastodon::API::http > &  ptr 
)

Make a streaming GET request.

Parameters
callString in the form /api/v1/example
answerThe answer from the server. Usually JSON. On error an empty string.
ptrPointer to the http object. Can be used to call ptr->cancel_stream()
Returns
Error code. If the URL has permanently changed, 13 is returned and answer is set to the new URL.
Since
before 0.11.0

◆ get_useragent()

const string API::get_useragent ( ) const

Gets the useragent.

Returns
The useragent.
Since
before 0.11.0
48 {
49  return _useragent;
50 }

◆ patch()

const uint_fast16_t API::patch ( const Mastodon::API::v1 call,
const parametermap parameters,
string &  answer 
)

Make a PATCH request.

Binary data must be base64-encoded or a filename.

Parameters
callA call defined in Mastodon::API::v1
parametersA Mastodon::API::parametermap containing parameters
answerThe answer from the server. Usually JSON. On error an empty string.
Returns
Error code. If the URL has permanently changed, 13 is returned and answer is set to the new URL.
Since
before 0.11.0
Examples:
example04_update_credentials.cpp.
27 {
28  string strcall = "";
29  switch (call)
30  {
31  case v1::accounts_update_credentials:
32  strcall = "/api/v1/accounts/update_credentials";
33  break;
34  default:
35  ttdebug << "ERROR: Invalid call.\n";
36  return 11;
37  break;
38  }
39 
40  return _http.request(API::http::method::PATCH,
41  strcall, maptoformdata(parameters), answer);
42 }

◆ post() [1/3]

const uint_fast16_t API::post ( const Mastodon::API::v1 call,
string &  answer 
)

Make a POST request which doesn't require parameters.

Parameters
callA call defined in Mastodon::API::v1
answerThe answer from the server. Usually JSON. On error an empty string.
Returns
Error code. If the URL has permanently changed, 13 is returned and answer is set to the new URL.
Since
before 0.11.0
Examples:
example05_follow_unfollow.cpp, example06_toot_delete-toot.cpp, example10_simplify.cpp, and example11_post_media.cpp.
135 {
136  const parametermap p;
137  return post(call, p, answer);
138 }
const uint_fast16_t post(const Mastodon::API::v1 &call, string &answer)
Make a POST request which doesn&#39;t require parameters.
Definition: post.cpp:134
std::map< string, std::vector< string > > parametermap
Used for passing parameters.
Definition: mastodon-cpp.hpp:189

◆ post() [2/3]

const uint_fast16_t API::post ( const Mastodon::API::v1 call,
const parametermap parameters,
string &  answer 
)

Make a POST request which requires parameters.

Binary data must be base64-encoded or a filename.

Parameters
callA call defined in Mastodon::API::v1
parametersA Mastodon::API::parametermap containing parameters
answerThe answer from the server. Usually JSON. On error an empty string.
Returns
Error code. If the URL has permanently changed, 13 is returned and answer is set to the new URL.
Since
before 0.11.0
25 {
26  string strcall = "";
27  string strid = "";
28 
29  // The ID is part of the path
30  const auto &it = parameters.find("id");
31  if (it != parameters.end())
32  {
33  strid = it->second[0];
34  }
35 
36  switch (call)
37  {
38  case v1::apps:
39  strcall = "/api/v1/apps";
40  break;
41  case v1::domain_blocks:
42  strcall = "/api/v1/domain_blocks";
43  break;
44  case v1::follows:
45  strcall = "/api/v1/follows";
46  break;
47  case v1::lists:
48  strcall = "/api/v1/lists";
49  break;
50  case v1::media:
51  strcall = "/api/v1/media";
52  break;
53  case v1::notifications_clear:
54  strcall = "/api/v1/notifications/clear";
55  break;
56  case v1::notifications_dismiss:
57  strcall = "/api/v1/notifications/dismiss";
58  break;
59  case v1::reports:
60  strcall = "/api/v1/reports";
61  break;
62  case v1::statuses:
63  strcall = "/api/v1/statuses";
64  break;
65  case v1::accounts_id_follow:
66  strcall = "/api/v1/accounts/" + strid + "/follow";
67  break;
68  case v1::accounts_id_unfollow:
69  strcall = "/api/v1/accounts/" + strid + "/unfollow";
70  break;
71  case v1::accounts_id_block:
72  strcall = "/api/v1/accounts/" + strid + "/block";
73  break;
74  case v1::accounts_id_unblock:
75  strcall = "/api/v1/accounts/" + strid + "/unblock";
76  break;
77  case v1::accounts_id_mute:
78  strcall = "/api/v1/accounts/" + strid + "/mute";
79  break;
80  case v1::accounts_id_unmute:
81  strcall = "/api/v1/accounts/" + strid + "/unmute";
82  break;
83  case v1::follow_requests_id_authorize:
84  strcall = "/api/v1/folow_requests/" + strid + "/authorize";
85  break;
86  case v1::follow_requests_id_reject:
87  strcall = "/api/v1/folow_requests/" + strid + "/reject";
88  break;
89  case v1::lists_id_accounts:
90  strcall = "/api/v1/lists/" + strid + "/accounts";
91  break;
92  case v1::statuses_id_reblog:
93  strcall = "/api/v1/statuses/" + strid + "/reblog";
94  break;
95  case v1::statuses_id_unreblog:
96  strcall = "/api/v1/statuses/" + strid + "/unreblog";
97  break;
98  case v1::statuses_id_favourite:
99  strcall = "/api/v1/statuses/" + strid + "/favourite";
100  break;
101  case v1::statuses_id_unfavourite:
102  strcall = "/api/v1/statuses/" + strid + "/unfavourite";
103  break;
104  case v1::statuses_id_pin:
105  strcall = "/api/v1/statuses/" + strid + "/pin";
106  break;
107  case v1::statuses_id_unpin:
108  strcall = "/api/v1/statuses/" + strid + "/unpin";
109  break;
110  case v1::statuses_id_mute:
111  strcall = "/api/v1/statuses/" + strid + "/mute";
112  break;
113  case v1::statuses_id_unmute:
114  strcall = "/api/v1/statuses/" + strid + "/unmute";
115  break;
116  case v1::push_subscription:
117  strcall = "/api/v1/push/subscription";
118  break;
119  case v1::accounts_id_pin:
120  strcall = "/api/v1/accounts/" + strid + "/pin";
121  break;
122  case v1::accounts_id_unpin:
123  strcall = "/api/v1/accounts/" + strid + "/unpin";
124  break;
125  default:
126  ttdebug << "ERROR: Invalid call.\n";
127  return 11;
128  break;
129  }
130 
131  return post(strcall, parameters, answer);
132 }
const uint_fast16_t post(const Mastodon::API::v1 &call, string &answer)
Make a POST request which doesn&#39;t require parameters.
Definition: post.cpp:134

◆ post() [3/3]

const uint_fast16_t API::post ( const string &  call,
const parametermap parameters,
string &  answer 
)

Make a custom POST request.

Binary data must be base64-encoded or a filename.

Parameters
callString in the form /api/v1/example
parametersA Mastodon::API::parametermap containing parameters
answerThe answer from the server. Usually JSON. On error an empty string.
Returns
Error code. If the URL has permanently changed, 13 is returned and answer is set to the new URL.
Since
before 0.11.0
142 {
143 
144  return _http.request(http::method::POST, call,
145  maptoformdata(parameters), answer);
146 }

◆ put() [1/2]

const uint_fast16_t API::put ( const Mastodon::API::v1 call,
const parametermap parameters,
string &  answer 
)

Make a PUT request which requires a parameters.

Parameters
callA call defined in Mastodon::API::v1
parametersA Mastodon::API::parametermap containing parameters
answerThe answer from the server. Usually JSON. On error an empty string.
Returns
Error code. If the URL has permanently changed, 13 is returned and answer is set to the new URL.
Since
before 0.11.0
25 {
26  string strcall = "";
27  string strid = "";
28 
29  // The ID is part of the path
30  const auto &it = parameters.find("id");
31  if (it != parameters.end())
32  {
33  strid = it->second[0];
34  }
35 
36  switch (call)
37  {
38  case v1::lists_id:
39  strcall = "/api/v1/lists/" + strid;
40  break;
41  case v1::media_id:
42  strcall = "/api/v1/media/" + strid;
43  break;
44  case v1::push_subscription:
45  strcall = "/api/v1/push/subscription";
46  break;
47  default:
48  ttdebug << "ERROR: Invalid call.\n";
49  return 11;
50  break;
51  }
52 
53  return put(strcall, parameters, answer);
54 }
const uint_fast16_t put(const Mastodon::API::v1 &call, const parametermap &parameters, string &answer)
Make a PUT request which requires a parameters.
Definition: put.cpp:23

◆ put() [2/2]

const uint_fast16_t API::put ( const string &  call,
const parametermap parameters,
string &  answer 
)

Make a custom PUT request.

Parameters
callString in the form /api/v1/example
parametersA Mastodon::API::parametermap containing parameters
answerThe answer from the server. Usually JSON. On error an empty string.
Returns
Error code. If the URL has permanently changed, 13 is returned and answer is set to the new URL.
Since
before 0.11.0
58 {
59 
60  return _http.request(http::method::PUT, call,
61  maptoformdata(parameters), answer);
62 }

◆ register_app1()

const uint_fast16_t API::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.

Parameters
client_nameThe name of the application
redirect_uriurn:ietf:wg:oauth:2.0:oob for none
scopesScopes (read, write, follow, push; space separated)
websiteThe website of the application
client_idReturned
client_secretReturned
urlReturned, used to generate code for register_app2
Returns
Error code. If the URL has permanently changed, 13 is returned and url is set to the new URL.
Since
before 0.11.0
Examples:
example07_register_app.cpp.
170 {
171  API::parametermap parameters =
172  {
173  { "client_name", { client_name } },
174  { "redirect_uris", { redirect_uri } },
175  { "scopes", { scopes } },
176  { "website", { website } }
177  };
178 
179  string answer;
180  uint_fast16_t ret = post(API::v1::apps, parameters, answer);
181 
182  if (ret == 0)
183  {
184  std::smatch match;
185  std::regex reid("client_id\":\"([0-9a-fA-F]+)\"");
186  std::regex resecret("client_secret\":\"([0-9a-fA-F]+)\"");
187 
188  std::regex_search(answer, match, reid);
189  client_id = match[1].str();
190  std::regex_search(answer, match, resecret);
191  client_secret = match[1].str();
192 
193  url = "https://" + _instance + "/oauth/authorize" +
194  "?scope=" + urlencode(scopes) + "&response_type=code" +
195  "&redirect_uri=" + urlencode(redirect_uri) +
196  "&client_id=" + client_id;
197  if (!website.empty())
198  {
199  url += "&website=" + urlencode(website);
200  }
201 
202  return 0;
203  }
204  else if (ret == 13)
205  {
206  url = answer;
207  return ret;
208  }
209  else
210  {
211  std::cerr << "Error code: " << ret << '\n';
212  return ret;
213  }
214 
215 }
static const string urlencode(const string &str)
Percent-encodes a string. This is done automatically, unless you make a custom request.
Definition: mastodon-cpp.cpp:141
const uint_fast16_t post(const Mastodon::API::v1 &call, string &answer)
Make a POST request which doesn&#39;t require parameters.
Definition: post.cpp:134
std::map< string, std::vector< string > > parametermap
Used for passing parameters.
Definition: mastodon-cpp.hpp:189

◆ register_app2()

const uint_fast16_t API::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.

The access token will be used in all subsequent calls.

Parameters
client_id
client_secret
redirect_uriurn:ietf:wg:oauth:2.0:oob for none
codeThe code generated by the website
access_tokenReturned
Returns
Error code.
Since
before 0.11.0
Examples:
example07_register_app.cpp.
232 {
233  API::parametermap parameters =
234  {
235  { "client_id", { client_id } },
236  { "client_secret", { client_secret } },
237  { "grant_type", { "authorization_code" } },
238  { "redirect_uri", { redirect_uri } },
239  { "code", { code } },
240  };
241 
242  std::string answer;
243  uint_fast16_t ret = post("/oauth/token", parameters, answer);
244  if (ret == 0)
245  {
246  std::smatch match;
247  std::regex retoken("access_token\":\"([0-9a-fA-F]+)\"");
248 
249  std::regex_search(answer, match, retoken);
250  access_token = match[1].str();
251  _access_token = access_token;
252 
253  return 0;
254  }
255  else
256  {
257  std::cerr << "Error code: " << ret << '\n';
258  return ret;
259  }
260 }
const uint_fast16_t post(const Mastodon::API::v1 &call, string &answer)
Make a POST request which doesn&#39;t require parameters.
Definition: post.cpp:134
std::map< string, std::vector< string > > parametermap
Used for passing parameters.
Definition: mastodon-cpp.hpp:189

◆ set_proxy()

const void API::set_proxy ( const string &  proxy,
const string &  userpw = "" 
)

Sets the proxy.

Since mastodon-cpp is built on libcurl, it respects the same proxy environment variables. See man curl.

Parameters
proxySee man 3 CURLOPT_PROXY
userpwSee man 3 CURLOPT_PROXYUSERPWD (optional)
Since
0.15.0
Examples:
example15_proxy.cpp.
590 {
591  _proxy = proxy;
592  _proxy_userpw = userpw;
593 }

◆ set_useragent()

const void API::set_useragent ( const string &  useragent)

Sets the useragent. Default is mastodon-cpp/version.

Parameters
useragentThe useragent
Since
before 0.11.0
Examples:
example01_dump_json.cpp, example04_update_credentials.cpp, example05_follow_unfollow.cpp, example06_toot_delete-toot.cpp, example07_register_app.cpp, example08_rate_limiting.cpp, and example09_streaming_api.cpp.
43 {
44  _useragent = useragent;
45 }

◆ unescape_html()

const string API::unescape_html ( const string &  html)
static

Replaces HTML entities with UTF-8 characters.

Supports named and numbered entities, decimal and hexadecimal.

Since
0.12.0
289 {
290  string buffer = html;
291  string output = "";
292 
293  // Used to convert int to utf-8 char
294  std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> u8c;
295  // Matches numbered entities between 1 and 8 digits, decimal or hexadecimal
296  std::regex re_entity("&#(x)?(\\d{1,8});");
297  std::smatch match;
298 
299  while (std::regex_search(buffer, match, re_entity))
300  {
301  char32_t codepoint = 0;
302  // 'x' in front of the number means it's hexadecimal, else decimal.
303  if (match[1].length() == 1)
304  {
305  codepoint = std::stoi(match[2].str(), nullptr, 16);
306  }
307  else
308  {
309  codepoint = std::stoi(match[2].str(), nullptr, 10);
310  }
311  output += match.prefix().str() + u8c.to_bytes(codepoint);
312  buffer = match.suffix().str();
313  }
314  output += buffer;
315 
316  // Source: https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_
317  // entity_references#Character_entity_references_in_HTML
318  const std::array<const std::pair<const string, const char32_t>, 258> names =
319  {{
320  { "exclamation", 0x0021 },
321  { "quot", 0x0022 },
322  { "percent", 0x0025 },
323  { "amp", 0x0026 },
324  { "apos", 0x0027 },
325  { "add", 0x002B },
326  { "lt", 0x003C },
327  { "equal", 0x003D },
328  { "gt", 0x003E },
329  { "nbsp", 0x00A0 },
330  { "iexcl", 0x00A1 },
331  { "cent", 0x00A2 },
332  { "pound", 0x00A3 },
333  { "curren", 0x00A4 },
334  { "yen", 0x00A5 },
335  { "brvbar", 0x00A6 },
336  { "sect", 0x00A7 },
337  { "uml", 0x00A8 },
338  { "copy", 0x00A9 },
339  { "ordf", 0x00AA },
340  { "laquo", 0x00AB },
341  { "not", 0x00AC },
342  { "shy", 0x00AD },
343  { "reg", 0x00AE },
344  { "macr", 0x00AF },
345  { "deg", 0x00B0 },
346  { "plusmn", 0x00B1 },
347  { "sup2", 0x00B2 },
348  { "sup3", 0x00B3 },
349  { "acute", 0x00B4 },
350  { "micro", 0x00B5 },
351  { "para", 0x00B6 },
352  { "middot", 0x00B7 },
353  { "cedil", 0x00B8 },
354  { "sup1", 0x00B9 },
355  { "ordm", 0x00BA },
356  { "raquo", 0x00BB },
357  { "frac14", 0x00BC },
358  { "frac12", 0x00BD },
359  { "frac34", 0x00BE },
360  { "iquest", 0x00BF },
361  { "Agrave", 0x00C0 },
362  { "Aacute", 0x00C1 },
363  { "Acirc", 0x00C2 },
364  { "Atilde", 0x00C3 },
365  { "Auml", 0x00C4 },
366  { "Aring", 0x00C5 },
367  { "AElig", 0x00C6 },
368  { "Ccedil", 0x00C7 },
369  { "Egrave", 0x00C8 },
370  { "Eacute", 0x00C9 },
371  { "Ecirc", 0x00CA },
372  { "Euml", 0x00CB },
373  { "Igrave", 0x00CC },
374  { "Iacute", 0x00CD },
375  { "Icirc", 0x00CE },
376  { "Iuml", 0x00CF },
377  { "ETH", 0x00D0 },
378  { "Ntilde", 0x00D1 },
379  { "Ograve", 0x00D2 },
380  { "Oacute", 0x00D3 },
381  { "Ocirc", 0x00D4 },
382  { "Otilde", 0x00D5 },
383  { "Ouml", 0x00D6 },
384  { "times", 0x00D7 },
385  { "Oslash", 0x00D8 },
386  { "Ugrave", 0x00D9 },
387  { "Uacute", 0x00DA },
388  { "Ucirc", 0x00DB },
389  { "Uuml", 0x00DC },
390  { "Yacute", 0x00DD },
391  { "THORN", 0x00DE },
392  { "szlig", 0x00DF },
393  { "agrave", 0x00E0 },
394  { "aacute", 0x00E1 },
395  { "acirc", 0x00E2 },
396  { "atilde", 0x00E3 },
397  { "auml", 0x00E4 },
398  { "aring", 0x00E5 },
399  { "aelig", 0x00E6 },
400  { "ccedil", 0x00E7 },
401  { "egrave", 0x00E8 },
402  { "eacute", 0x00E9 },
403  { "ecirc", 0x00EA },
404  { "euml", 0x00EB },
405  { "igrave", 0x00EC },
406  { "iacute", 0x00ED },
407  { "icirc", 0x00EE },
408  { "iuml", 0x00EF },
409  { "eth", 0x00F0 },
410  { "ntilde", 0x00F1 },
411  { "ograve", 0x00F2 },
412  { "oacute", 0x00F3 },
413  { "ocirc", 0x00F4 },
414  { "otilde", 0x00F5 },
415  { "ouml", 0x00F6 },
416  { "divide", 0x00F7 },
417  { "oslash", 0x00F8 },
418  { "ugrave", 0x00F9 },
419  { "uacute", 0x00FA },
420  { "ucirc", 0x00FB },
421  { "uuml", 0x00FC },
422  { "yacute", 0x00FD },
423  { "thorn", 0x00FE },
424  { "yuml", 0x00FF },
425  { "OElig", 0x0152 },
426  { "oelig", 0x0153 },
427  { "Scaron", 0x0160 },
428  { "scaron", 0x0161 },
429  { "Yuml", 0x0178 },
430  { "fnof", 0x0192 },
431  { "circ", 0x02C6 },
432  { "tilde", 0x02DC },
433  { "Alpha", 0x0391 },
434  { "Beta", 0x0392 },
435  { "Gamma", 0x0393 },
436  { "Delta", 0x0394 },
437  { "Epsilon", 0x0395 },
438  { "Zeta", 0x0396 },
439  { "Eta", 0x0397 },
440  { "Theta", 0x0398 },
441  { "Iota", 0x0399 },
442  { "Kappa", 0x039A },
443  { "Lambda", 0x039B },
444  { "Mu", 0x039C },
445  { "Nu", 0x039D },
446  { "Xi", 0x039E },
447  { "Omicron", 0x039F },
448  { "Pi", 0x03A0 },
449  { "Rho", 0x03A1 },
450  { "Sigma", 0x03A3 },
451  { "Tau", 0x03A4 },
452  { "Upsilon", 0x03A5 },
453  { "Phi", 0x03A6 },
454  { "Chi", 0x03A7 },
455  { "Psi", 0x03A8 },
456  { "Omega", 0x03A9 },
457  { "alpha", 0x03B1 },
458  { "beta", 0x03B2 },
459  { "gamma", 0x03B3 },
460  { "delta", 0x03B4 },
461  { "epsilon", 0x03B5 },
462  { "zeta", 0x03B6 },
463  { "eta", 0x03B7 },
464  { "theta", 0x03B8 },
465  { "iota", 0x03B9 },
466  { "kappa", 0x03BA },
467  { "lambda", 0x03BB },
468  { "mu", 0x03BC },
469  { "nu", 0x03BD },
470  { "xi", 0x03BE },
471  { "omicron", 0x03BF },
472  { "pi", 0x03C0 },
473  { "rho", 0x03C1 },
474  { "sigmaf", 0x03C2 },
475  { "sigma", 0x03C3 },
476  { "tau", 0x03C4 },
477  { "upsilon", 0x03C5 },
478  { "phi", 0x03C6 },
479  { "chi", 0x03C7 },
480  { "psi", 0x03C8 },
481  { "omega", 0x03C9 },
482  { "thetasym", 0x03D1 },
483  { "upsih", 0x03D2 },
484  { "piv", 0x03D6 },
485  { "ensp", 0x2002 },
486  { "emsp", 0x2003 },
487  { "thinsp", 0x2009 },
488  { "zwnj", 0x200C },
489  { "zwj", 0x200D },
490  { "lrm", 0x200E },
491  { "rlm", 0x200F },
492  { "ndash", 0x2013 },
493  { "mdash", 0x2014 },
494  { "horbar", 0x2015 },
495  { "lsquo", 0x2018 },
496  { "rsquo", 0x2019 },
497  { "sbquo", 0x201A },
498  { "ldquo", 0x201C },
499  { "rdquo", 0x201D },
500  { "bdquo", 0x201E },
501  { "dagger", 0x2020 },
502  { "Dagger", 0x2021 },
503  { "bull", 0x2022 },
504  { "hellip", 0x2026 },
505  { "permil", 0x2030 },
506  { "prime", 0x2032 },
507  { "Prime", 0x2033 },
508  { "lsaquo", 0x2039 },
509  { "rsaquo", 0x203A },
510  { "oline", 0x203E },
511  { "frasl", 0x2044 },
512  { "euro", 0x20AC },
513  { "image", 0x2111 },
514  { "weierp", 0x2118 },
515  { "real", 0x211C },
516  { "trade", 0x2122 },
517  { "alefsym", 0x2135 },
518  { "larr", 0x2190 },
519  { "uarr", 0x2191 },
520  { "rarr", 0x2192 },
521  { "darr", 0x2193 },
522  { "harr", 0x2194 },
523  { "crarr", 0x21B5 },
524  { "lArr", 0x21D0 },
525  { "uArr", 0x21D1 },
526  { "rArr", 0x21D2 },
527  { "dArr", 0x21D3 },
528  { "hArr", 0x21D4 },
529  { "forall", 0x2200 },
530  { "part", 0x2202 },
531  { "exist", 0x2203 },
532  { "empty", 0x2205 },
533  { "nabla", 0x2207 },
534  { "isin", 0x2208 },
535  { "notin", 0x2209 },
536  { "ni", 0x220B },
537  { "prod", 0x220F },
538  { "sum", 0x2211 },
539  { "minus", 0x2212 },
540  { "lowast", 0x2217 },
541  { "radic", 0x221A },
542  { "prop", 0x221D },
543  { "infin", 0x221E },
544  { "ang", 0x2220 },
545  { "and", 0x2227 },
546  { "or", 0x2228 },
547  { "cap", 0x2229 },
548  { "cup", 0x222A },
549  { "int", 0x222B },
550  { "there4", 0x2234 },
551  { "sim", 0x223C },
552  { "cong", 0x2245 },
553  { "asymp", 0x2248 },
554  { "ne", 0x2260 },
555  { "equiv", 0x2261 },
556  { "le", 0x2264 },
557  { "ge", 0x2265 },
558  { "sub", 0x2282 },
559  { "sup", 0x2283 },
560  { "nsub", 0x2284 },
561  { "sube", 0x2286 },
562  { "supe", 0x2287 },
563  { "oplus", 0x2295 },
564  { "otimes", 0x2297 },
565  { "perp", 0x22A5 },
566  { "sdot", 0x22C5 },
567  { "lceil", 0x2308 },
568  { "rceil", 0x2309 },
569  { "lfloor", 0x230A },
570  { "rfloor", 0x230B },
571  { "lang", 0x2329 },
572  { "rang", 0x232A },
573  { "loz", 0x25CA },
574  { "spades", 0x2660 },
575  { "clubs", 0x2663 },
576  { "hearts", 0x2665 },
577  { "diams", 0x2666 }
578  }};
579 
580  for (auto &pair : names)
581  {
582  const std::regex re('&' + pair.first + ';');
583  output = std::regex_replace(output, re, u8c.to_bytes(pair.second));
584  }
585 
586  return output;
587 }

◆ urldecode()

const std::string API::urldecode ( const string &  str)
static

Decodes a percent-encoded string.

Calls curlpp::unescape(str)

See RFC 3986 section 2.1 for more info.

Parameters
strThe string
Returns
The decoded string
Since
0.18.0
147 {
148  return curlpp::unescape(str);
149 }

◆ urlencode()

const std::string API::urlencode ( const string &  str)
static

Percent-encodes a string. This is done automatically, unless you make a custom request.

Calls curlpp::escape(str)

The only time you should use this, is if you use get(const string &call, string &answer).

See RFC 3986 section 2.1 for more info.

Parameters
strThe string
Returns
The percent-encoded string
Since
before 0.11.0
142 {
143  return curlpp::escape(str);
144 }

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