mastodon-cpp
0.110.0
|
Interface to 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, accounts_verify_credentials, accounts_update_credentials, accounts_id_followers, accounts_id_following, accounts_id_statuses, accounts_id_follow, accounts_id_unfollow, accounts_relationships, accounts_search, apps, apps_verify_credentials, blocks, accounts_id_block, accounts_id_unblock, custom_emojis, domain_blocks, endorsements, accounts_id_pin, accounts_id_unpin, favourites, statuses_id_favourite, statuses_id_unfavourite, filters, filters_id, follow_requests, follow_requests_id_authorize, follow_requests_id_reject, suggestions, suggestions_accountid, instance, lists, accounts_id_lists, lists_id_accounts, lists_id, media, media_id, mutes, accounts_id_mute, accounts_id_unmute, statuses_id_mute, statuses_id_unmute, notifications, notifications_id, notifications_clear, notifications_dismiss, push_subscription, polls_id, polls_id_votes, reports, statuses_id, statuses_id_context, statuses_id_card, statuses_id_reblogged_by, statuses_id_favourited_by, statuses, statuses_id_reblog, statuses_id_unreblog, statuses_id_pin, statuses_id_unpin, timelines_home, conversations, timelines_public, timelines_tag_hashtag, timelines_list_list_id, streaming_health, streaming_user, streaming_public, streaming_public_local, streaming_hashtag, streaming_hashtag_local, streaming_list, streaming_direct, bookmarks, statuses_id_bookmark, statuses_id_unbookmark } |
A list of all v1 API calls. More... | |
enum | v2 { search } |
A list of all v2 API calls. More... | |
Public Member Functions | |
API (const string &instance, const string &access_token) | |
Constructs a new API object. More... | |
virtual | ~API () |
Destroys the object. More... | |
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... | |
return_call | 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... | |
return_call | 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 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... | |
bool | exceptions () const |
Returns true if exceptions are turned on, false otherwise. | |
void | set_proxy (const string &hostport, const string &userpw="") |
Sets the proxy. More... | |
const return_call | get (const Mastodon::API::v1 &call) |
Make a GET request that doesn't require parameters. More... | |
const return_call | get (const Mastodon::API::v1 &call, const parameters ¶meters) |
Make a GET request that requires parameters. More... | |
const return_call | get (const Mastodon::API::v2 &call, const parameters ¶meters) |
Make a GET request that requires parameters. More... | |
const return_call | get (const string &call) |
Make a custom GET request. More... | |
void | get_stream (const Mastodon::API::v1 &call, const parameters ¶meters, unique_ptr< Mastodon::API::http > &ptr, string &stream) |
Make a streaming GET request. More... | |
void | get_stream (const Mastodon::API::v1 &call, unique_ptr< Mastodon::API::http > &ptr, string &stream) |
Make a streaming GET request. More... | |
void | get_stream (const string &call, unique_ptr< Mastodon::API::http > &ptr, string &stream) |
Make a streaming GET request. More... | |
return_call | patch (const Mastodon::API::v1 &call, const parameters ¶meters) |
Make a PATCH request. More... | |
return_call | post (const Mastodon::API::v1 &call) |
Make a POST request that doesn't require parameters. More... | |
return_call | post (const Mastodon::API::v1 &call, const parameters ¶meters) |
Make a POST request that requires parameters. More... | |
return_call | post (const string &call, const parameters ¶meters) |
Make a custom POST request. More... | |
return_call | put (const Mastodon::API::v1 &call, const parameters ¶meters) |
Make a PUT request that requires parameters. More... | |
return_call | put (const string &call, const parameters ¶meters) |
Make a custom PUT request. More... | |
return_call | del (const Mastodon::API::v1 &call, const parameters ¶meters) |
Make a DELETE request that requires parameters. More... | |
return_call | del (const string &call, const parameters ¶meters) |
Make a custom DELETE request. More... | |
Static Public Member Functions | |
static const string | urlencode (const string &str) |
Alias for Mastodon::urlencode. More... | |
static const string | urldecode (const string &str) |
Alias for Mastodon::urldecode. More... | |
static const string | unescape_html (const string &html) |
Alias for Mastodon::unescape_html. More... | |
Interface to the Mastodon API.
All input is expected to be UTF-8. Binary data must be a filename.
Code | Explanation |
---|---|
0 | No error |
1 | Invalid argument |
10 | URL changed (HTTP 301 or 308) |
11 | Connection timed out |
12 | Connection refused (check http_error_code) |
13 | No route to host / Could not resolve host |
14 | Encryption error |
127 | Unknown error |
|
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. |
return_call API::del | ( | const Mastodon::API::v1 & | call, |
const parameters & | parameters | ||
) |
Make a DELETE request that requires parameters.
call | A call defined in Mastodon::API::v1 |
parameters | A Mastodon::parametermap containing parameters |
return_call Mastodon::API::del | ( | const string & | call, |
const parameters & | parameters | ||
) |
Make a custom DELETE request.
call | String in the form /api/v1/example |
parameters | A Mastodon::parametermap containing parameters |
bool API::exceptions | ( | const bool & | value | ) |
const return_call API::get | ( | const Mastodon::API::v1 & | call | ) |
Make a GET request that doesn't require parameters.
call | A call defined in Mastodon::API::v1 |
const return_call API::get | ( | const Mastodon::API::v1 & | call, |
const parameters & | parameters | ||
) |
Make a GET request that requires parameters.
call | A call defined in Mastodon::API::v1 |
parameters | A Mastodon::parametermap containing parameters |
const return_call API::get | ( | const Mastodon::API::v2 & | call, |
const parameters & | parameters | ||
) |
Make a GET request that requires parameters.
call | A call defined in Mastodon::API::v2 |
parameters | A Mastodon::parametermap containing parameters |
const return_call Mastodon::API::get | ( | const string & | call | ) |
Make a custom GET request.
call | String in the form /api/v1/example |
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 |
void Mastodon::API::get_stream | ( | const Mastodon::API::v1 & | call, |
const parameters & | parameters, | ||
unique_ptr< Mastodon::API::http > & | ptr, | ||
string & | stream | ||
) |
Make a streaming GET request.
call | A call defined in Mastodon::API::v1 |
parameters | A Mastodon::parametermap containing parameters |
ptr | Pointer to the http object. Can be used to call ptr->cancel_stream() |
void Mastodon::API::get_stream | ( | const Mastodon::API::v1 & | call, |
unique_ptr< Mastodon::API::http > & | ptr, | ||
string & | stream | ||
) |
Make a streaming GET request.
call | A call defined in Mastodon::API::v1 |
ptr | Pointer to the http object. Can be used to call ptr->cancel_stream() |
void Mastodon::API::get_stream | ( | const string & | call, |
unique_ptr< Mastodon::API::http > & | ptr, | ||
string & | stream | ||
) |
Make a streaming GET request.
call | String in the form /api/v1/example |
ptr | Pointer to the http object. Can be used to call ptr->cancel_stream() |
const string API::get_useragent | ( | ) | const |
return_call API::patch | ( | const Mastodon::API::v1 & | call, |
const parameters & | parameters | ||
) |
Make a PATCH request.
Binary data must be a filename.
call | A call defined in Mastodon::API::v1 |
parameters | A Mastodon::parametermap containing parameters |
return_call API::post | ( | const Mastodon::API::v1 & | call | ) |
Make a POST request that doesn't require parameters.
call | A call defined in Mastodon::API::v1 |
return_call API::post | ( | const Mastodon::API::v1 & | call, |
const parameters & | parameters | ||
) |
Make a POST request that requires parameters.
Binary data must be a filename.
call | A call defined in Mastodon::API::v1 |
parameters | A Mastodon::parametermap containing parameters |
return_call API::post | ( | const string & | call, |
const parameters & | parameters | ||
) |
return_call API::put | ( | const Mastodon::API::v1 & | call, |
const parameters & | parameters | ||
) |
Make a PUT request that requires parameters.
call | A call defined in Mastodon::API::v1 |
parameters | A Mastodon::parametermap containing parameters |
return_call API::put | ( | const string & | call, |
const parameters & | parameters | ||
) |
return_call 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 |
return_call 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 |
void API::set_proxy | ( | const string & | hostport, |
const string & | userpw = "" |
||
) |
Sets the proxy.
Both the username and the password will be URL decoded before use.
hostport | host[:port] |
userpw | username[:password] (optional) |
void API::set_useragent | ( | const string & | useragent | ) |
|
static |
Alias for Mastodon::unescape_html.
|
static |
|
static |
Alias for Mastodon::urlencode.
str | The string |