mastodon-cpp
0.18.8
|
Class for the Mastodon API. More...
#include <mastodon-cpp.hpp>
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, 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 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 ¶meters, string &answer) |
Make a GET request which requires parameters. More... | |
const uint_fast16_t | get (const Mastodon::API::v2 &call, const parametermap ¶meters, 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 ¶meters, string &answer) |
const uint_fast16_t | get_stream (const Mastodon::API::v1 &call, const parametermap ¶meters, 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 ¶meters, 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 ¶meters, string &answer) |
Make a POST request which requires parameters. More... | |
const uint_fast16_t | post (const string &call, const parametermap ¶meters, 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 ¶meters, string &answer) |
const uint_fast16_t | put (const Mastodon::API::v1 &call, const parametermap ¶meters, string &answer) |
Make a PUT request which requires a parameters. More... | |
const uint_fast16_t | put (const string &call, const parametermap ¶meters, string &answer) |
Make a custom PUT request. More... | |
const uint_fast16_t | put (const Mastodon::API::v1 &call, const string &argument, const parametermap ¶meters, string &answer) |
const uint_fast16_t | del (const Mastodon::API::v1 &call, const parametermap ¶meters) |
Make a DELETE request which requires parameters. More... | |
const uint_fast16_t | del (const string &call, const parametermap ¶meters, 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 ¶meters) |
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... | |
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.
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 |
typedef std::map<string, std::vector<string> > Mastodon::API::parametermap |
Used for passing parameters.
Example:
|
strong |
|
strong |
|
explicit |
Constructs a new API object.
To register your application, leave access_token blank and call register_app1() and register_app2().
instance | The hostname of your instance |
access_token | Your access token. |
const uint_fast16_t API::del | ( | const Mastodon::API::v1 & | call, |
const parametermap & | parameters | ||
) |
Make a DELETE request which requires parameters.
call | A call defined in Mastodon::API::v1 |
parameters | A Mastodon::API::parametermap containing parameters |
const uint_fast16_t Mastodon::API::del | ( | const string & | call, |
const parametermap & | parameters, | ||
string & | answer | ||
) |
Make a custom DELETE request.
call | String in the form /api/v1/example |
parameters | A Mastodon::API::parametermap containing parameters |
answer | The answer from the server. Usually JSON. On error an empty string. |
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.
value | true for on, false for off |
const uint_fast16_t API::get | ( | const Mastodon::API::v1 & | call, |
string & | answer | ||
) |
Make a GET request which doesn't require parameters.
call | A call defined in Mastodon::API::v1 |
answer | The answer from the server. Usually JSON. On error an empty string. |
const uint_fast16_t API::get | ( | const Mastodon::API::v1 & | call, |
const parametermap & | parameters, | ||
string & | answer | ||
) |
Make a GET request which requires parameters.
call | A call defined in Mastodon::API::v1 |
parameters | A Mastodon::API::parametermap containing parameters |
answer | The answer from the server. Usually JSON. On error an empty string. |
const uint_fast16_t API::get | ( | const Mastodon::API::v2 & | call, |
const parametermap & | parameters, | ||
string & | answer | ||
) |
Make a GET request which requires parameters.
const uint_fast16_t Mastodon::API::get | ( | const string & | call, |
string & | answer | ||
) |
Make a custom GET request.
call | String in the form /api/v1/example |
answer | The answer from the server. Usually JSON. On error an empty string. |
const string API::get_header | ( | const string & | header | ) | const |
Gets the header from the last answer.
header | The header to get |
const string API::get_instance | ( | ) | const |
const void API::get_proxy | ( | string & | proxy, |
string & | userpw | ||
) | const |
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.
call | A call defined in Mastodon::API::v1 |
parameters | A Mastodon::API::parametermap containing parameters |
answer | The answer from the server. Events with JSON-payload. |
ptr | Pointer to the http object. Can be used to call ptr->cancel_stream() |
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.
call | A call defined in Mastodon::API::v1 |
answer | The answer from the server. Events with JSON-payload. |
ptr | Pointer to the http object. Can be used to call ptr->cancel_stream() |
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.
call | String in the form /api/v1/example |
answer | The answer from the server. Usually JSON. On error an empty string. |
ptr | Pointer to the http object. Can be used to call ptr->cancel_stream() |
const string API::get_useragent | ( | ) | const |
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.
call | A call defined in Mastodon::API::v1 |
parameters | A Mastodon::API::parametermap containing parameters |
answer | The answer from the server. Usually JSON. On error an empty string. |
const uint_fast16_t API::post | ( | const Mastodon::API::v1 & | call, |
string & | answer | ||
) |
Make a POST request which doesn't require parameters.
call | A call defined in Mastodon::API::v1 |
answer | The answer from the server. Usually JSON. On error an empty string. |
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.
call | A call defined in Mastodon::API::v1 |
parameters | A Mastodon::API::parametermap containing parameters |
answer | The answer from the server. Usually JSON. On error an empty string. |
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.
call | String in the form /api/v1/example |
parameters | A Mastodon::API::parametermap containing parameters |
answer | The answer from the server. Usually JSON. On error an empty string. |
const uint_fast16_t API::put | ( | const Mastodon::API::v1 & | call, |
const parametermap & | parameters, | ||
string & | answer | ||
) |
Make a PUT request which requires a parameters.
call | A call defined in Mastodon::API::v1 |
parameters | A Mastodon::API::parametermap containing parameters |
answer | The answer from the server. Usually JSON. On error an empty string. |
const uint_fast16_t API::put | ( | const string & | call, |
const parametermap & | parameters, | ||
string & | answer | ||
) |
Make a custom PUT request.
call | String in the form /api/v1/example |
parameters | A Mastodon::API::parametermap containing parameters |
answer | The answer from the server. Usually JSON. On error an empty string. |
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.
client_name | The name of the application |
redirect_uri | urn:ietf:wg:oauth:2.0:oob for none |
scopes | Scopes (read , write , follow , push ; space separated) |
website | The website of the application |
client_id | Returned |
client_secret | Returned |
url | Returned, used to generate code for 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.
client_id | |
client_secret | |
redirect_uri | urn:ietf:wg:oauth:2.0:oob for none |
code | The code generated by the website |
access_token | Returned |
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
.
proxy | See man 3 CURLOPT_PROXY |
userpw | See man 3 CURLOPT_PROXYUSERPWD (optional) |
const void API::set_useragent | ( | const string & | useragent | ) |
Sets the useragent. Default is mastodon-cpp/version.
useragent | The useragent |
|
static |
Replaces HTML entities with UTF-8 characters.
Supports named and numbered entities, decimal and hexadecimal.
|
static |
|
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.
str | The string |