2018-01-06 21:33:52 +01:00
|
|
|
/* This file is part of mastodon-cpp.
|
2019-02-22 12:33:03 +01:00
|
|
|
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
|
|
|
|
*
|
2018-01-06 21:33:52 +01:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MASTODON_CPP_HPP
|
|
|
|
#define MASTODON_CPP_HPP
|
|
|
|
|
2018-01-09 22:12:11 +01:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2018-02-26 07:57:30 +01:00
|
|
|
#include <memory>
|
2018-04-03 00:04:47 +02:00
|
|
|
#include <array>
|
2018-05-17 17:59:44 +02:00
|
|
|
#include <mutex>
|
2019-02-22 11:33:36 +01:00
|
|
|
#include <ostream>
|
2019-04-10 02:25:55 +02:00
|
|
|
#include <thread>
|
|
|
|
#include <cstdint>
|
2018-02-09 16:01:24 +01:00
|
|
|
#include <curlpp/cURLpp.hpp>
|
|
|
|
#include <curlpp/Easy.hpp>
|
2018-01-09 22:12:11 +01:00
|
|
|
|
2019-08-12 04:06:43 +02:00
|
|
|
#include "return_types.hpp"
|
|
|
|
#include "types.hpp"
|
2019-04-02 10:37:27 +02:00
|
|
|
|
2018-04-02 01:47:44 +02:00
|
|
|
using std::string;
|
2019-04-10 02:25:55 +02:00
|
|
|
using std::uint8_t;
|
2018-04-02 01:47:44 +02:00
|
|
|
|
2018-01-15 15:34:18 +01:00
|
|
|
/*!
|
2019-03-02 13:48:10 +01:00
|
|
|
* @example example01_get_public_timeline.cpp
|
2019-04-10 02:34:21 +02:00
|
|
|
* @example example02_stream.cpp
|
2018-01-15 15:34:18 +01:00
|
|
|
*/
|
2018-04-01 04:27:29 +02:00
|
|
|
|
2019-04-13 21:50:20 +02:00
|
|
|
/*!
|
|
|
|
* @brief Collection of things to interface with server software that
|
|
|
|
* implements the Mastodon API.
|
|
|
|
*/
|
2018-01-09 22:12:11 +01:00
|
|
|
namespace Mastodon
|
2018-01-06 21:33:52 +01:00
|
|
|
{
|
2018-02-28 06:21:47 +01:00
|
|
|
/*!
|
2019-04-02 11:16:52 +02:00
|
|
|
* @brief Interface to the Mastodon API.
|
|
|
|
*
|
2019-04-27 21:48:15 +02:00
|
|
|
* All input is expected to be UTF-8. Binary data must be a
|
|
|
|
* filename.
|
2019-04-02 11:16:52 +02:00
|
|
|
*
|
|
|
|
* @section error Error codes
|
|
|
|
* | Code | Explanation |
|
|
|
|
* | --------: |:-------------------------------------------|
|
|
|
|
* | 0 | No error |
|
|
|
|
* | 22 | Invalid argument |
|
|
|
|
* | 78 | URL changed (HTTP 301 or 308) |
|
|
|
|
* | 110 | Connection timed out |
|
|
|
|
* | 111 | Connection refused (check http_error_code) |
|
2019-04-10 20:52:36 +02:00
|
|
|
* | 113 | No route to host / Could not resolve host |
|
2019-04-02 11:16:52 +02:00
|
|
|
* | 192 | curlpp runtime error |
|
|
|
|
* | 193 | curlpp logic error |
|
|
|
|
* | 255 | Unknown error |
|
2019-03-30 13:06:57 +01:00
|
|
|
*
|
2018-06-14 11:17:26 +02:00
|
|
|
* @since before 0.11.0
|
2018-02-28 06:21:47 +01:00
|
|
|
*/
|
2019-04-02 11:16:52 +02:00
|
|
|
class API
|
2018-02-28 06:21:47 +01:00
|
|
|
{
|
|
|
|
public:
|
2018-04-04 04:38:04 +02:00
|
|
|
/*!
|
2019-04-02 11:16:52 +02:00
|
|
|
* @brief http class. Do not use this directly.
|
|
|
|
*
|
|
|
|
* @since before 0.11.0
|
2018-04-04 04:38:04 +02:00
|
|
|
*/
|
2019-04-02 11:16:52 +02:00
|
|
|
class http
|
2018-02-28 06:21:47 +01:00
|
|
|
{
|
2019-04-02 11:16:52 +02:00
|
|
|
public:
|
|
|
|
/*!
|
2019-04-05 14:40:54 +02:00
|
|
|
* @brief Constructs new http object.
|
|
|
|
*
|
|
|
|
* @param API Parent object.
|
|
|
|
* @param instance Instance domain name
|
|
|
|
* @param access_token Access token
|
|
|
|
*
|
|
|
|
* @since before 0.11.0
|
2019-04-02 11:16:52 +02:00
|
|
|
*/
|
|
|
|
explicit http(const API &api, const string &instance,
|
|
|
|
const string &access_token);
|
|
|
|
~http();
|
2019-04-05 14:40:54 +02:00
|
|
|
return_call request(const http_method &meth, const string &path);
|
2019-04-02 11:16:52 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief HTTP Request.
|
|
|
|
*
|
2019-04-10 02:25:55 +02:00
|
|
|
* @param meth A method defined in http::method.
|
|
|
|
* @param path The API call as string.
|
2019-04-02 11:16:52 +02:00
|
|
|
* @param formdata The form data for PATCH and POST requests.
|
|
|
|
*
|
2019-04-13 02:27:21 +02:00
|
|
|
* @since 0.100.0
|
2019-04-02 11:16:52 +02:00
|
|
|
*/
|
2019-04-05 14:40:54 +02:00
|
|
|
return_call request(const http_method &meth,
|
2019-04-02 11:16:52 +02:00
|
|
|
const string &path,
|
|
|
|
const curlpp::Forms &formdata);
|
|
|
|
|
2019-04-10 02:25:55 +02:00
|
|
|
/*!
|
|
|
|
* @brief HTTP Request for streams.
|
|
|
|
*
|
|
|
|
* @param path The API call as string.
|
|
|
|
* @param stream The stream of data that is returned.
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
2019-04-10 20:52:36 +02:00
|
|
|
void request_stream(const string &path, string &stream);
|
2019-04-10 02:25:55 +02:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Get all headers in a string
|
|
|
|
*/
|
|
|
|
void get_headers(string &headers) const;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Cancels the stream. Use only with streams.
|
|
|
|
*
|
|
|
|
* Cancels the stream next time data comes in. Can take a
|
|
|
|
* few seconds. This works only with streams, because only
|
|
|
|
* streams have an own http object.
|
|
|
|
*
|
|
|
|
* @since 0.12.2
|
|
|
|
*/
|
|
|
|
void cancel_stream();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Gets the mutex guarding the string that is written to.
|
|
|
|
*
|
|
|
|
* The mutex guards the function that writes to the string
|
|
|
|
* you specified in get_stream().
|
|
|
|
*
|
|
|
|
* @return A reference of the mutex.
|
|
|
|
*
|
|
|
|
* @since 0.12.3
|
|
|
|
*/
|
|
|
|
std::mutex &get_mutex();
|
|
|
|
|
|
|
|
private:
|
|
|
|
const API &parent;
|
|
|
|
const string _instance;
|
|
|
|
const string _access_token;
|
|
|
|
string _headers;
|
|
|
|
bool _cancel_stream;
|
|
|
|
std::mutex _mutex;
|
2019-04-10 02:25:55 +02:00
|
|
|
std::thread _streamthread;
|
2019-04-02 11:16:52 +02:00
|
|
|
|
2019-04-10 02:25:55 +02:00
|
|
|
return_call request_common(const http_method &meth,
|
|
|
|
const string &path,
|
|
|
|
const curlpp::Forms &formdata,
|
|
|
|
string &answer);
|
2019-04-02 11:16:52 +02:00
|
|
|
size_t callback_write(char* data, size_t size, size_t nmemb,
|
|
|
|
string *oss);
|
|
|
|
double callback_progress(double /* dltotal */, double /* dlnow */,
|
|
|
|
double /* ultotal */, double /* ulnow */);
|
2018-02-28 06:21:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
2019-04-02 11:16:52 +02:00
|
|
|
* @brief A list of all v1 API calls.
|
2018-02-28 06:21:47 +01:00
|
|
|
*
|
2019-04-02 11:16:52 +02:00
|
|
|
* The original `/` are substituted by `_`.
|
2019-03-30 13:06:57 +01:00
|
|
|
*
|
2018-06-14 11:17:26 +02:00
|
|
|
* @since before 0.11.0
|
2018-02-28 06:21:47 +01:00
|
|
|
*/
|
2019-04-02 11:16:52 +02:00
|
|
|
enum class v1
|
|
|
|
{
|
|
|
|
// Mastodon
|
|
|
|
accounts_id,
|
2019-04-16 18:41:09 +02:00
|
|
|
accounts,
|
2019-04-02 11:16:52 +02:00
|
|
|
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,
|
2019-04-16 02:51:29 +02:00
|
|
|
apps_verify_credentials,
|
2019-04-02 11:16:52 +02:00
|
|
|
|
|
|
|
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,
|
|
|
|
|
2019-04-19 04:39:46 +02:00
|
|
|
filters,
|
|
|
|
filters_id,
|
2019-04-02 11:16:52 +02:00
|
|
|
|
|
|
|
follow_requests,
|
|
|
|
follow_requests_id_authorize,
|
|
|
|
follow_requests_id_reject,
|
|
|
|
|
2019-04-20 00:39:52 +02:00
|
|
|
suggestions,
|
|
|
|
suggestions_accountid,
|
2019-04-02 11:16:52 +02:00
|
|
|
|
|
|
|
instance,
|
|
|
|
|
|
|
|
lists,
|
|
|
|
accounts_id_lists,
|
|
|
|
lists_id,
|
|
|
|
lists_id_accounts,
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
reports,
|
|
|
|
|
|
|
|
// scheduled_statuses,
|
|
|
|
// scheduled_statuses_id,
|
|
|
|
|
|
|
|
search,
|
|
|
|
|
|
|
|
statuses,
|
|
|
|
statuses_id,
|
|
|
|
statuses_id_context,
|
|
|
|
statuses_id_card,
|
|
|
|
statuses_id_reblogged_by,
|
|
|
|
statuses_id_favourited_by,
|
|
|
|
statuses_id_reblog,
|
|
|
|
statuses_id_unreblog,
|
|
|
|
statuses_id_pin,
|
|
|
|
statuses_id_unpin,
|
|
|
|
|
|
|
|
timelines_home,
|
|
|
|
// timelines_conversations,
|
|
|
|
timelines_public,
|
|
|
|
timelines_tag_hashtag,
|
|
|
|
timelines_list_list_id,
|
|
|
|
|
|
|
|
streaming_user,
|
|
|
|
streaming_public,
|
|
|
|
streaming_public_local,
|
|
|
|
streaming_hashtag,
|
|
|
|
// streaming_hashtag_local,
|
|
|
|
streaming_list,
|
|
|
|
// streaming_direct,
|
|
|
|
|
|
|
|
// Glitch-Soc
|
|
|
|
bookmarks,
|
|
|
|
statuses_id_bookmark,
|
|
|
|
statuses_id_unbookmark
|
|
|
|
};
|
2018-02-28 06:21:47 +01:00
|
|
|
|
2018-04-04 04:38:04 +02:00
|
|
|
/*!
|
2019-04-02 11:16:52 +02:00
|
|
|
* @brief A list of all v2 API calls.
|
|
|
|
*
|
|
|
|
* The original `/` are substituted by `_`.
|
|
|
|
*
|
|
|
|
* @since 0.16.0
|
2018-04-04 04:38:04 +02:00
|
|
|
*/
|
2019-04-02 11:16:52 +02:00
|
|
|
enum class v2
|
|
|
|
{
|
|
|
|
search
|
|
|
|
};
|
2018-02-28 06:21:47 +01:00
|
|
|
|
|
|
|
/*!
|
2019-04-02 11:16:52 +02:00
|
|
|
* @brief Constructs a new API object.
|
|
|
|
*
|
|
|
|
* To register your application, leave access_token blank and
|
|
|
|
* call register_app1() and register_app2().
|
2019-03-30 13:06:57 +01:00
|
|
|
*
|
2019-04-02 11:16:52 +02:00
|
|
|
* @param instance The hostname of your instance
|
|
|
|
* @param access_token Your access token.
|
2019-03-30 13:06:57 +01:00
|
|
|
*
|
2019-04-02 11:16:52 +02:00
|
|
|
* @since before 0.11.0
|
2019-03-30 13:06:57 +01:00
|
|
|
*/
|
2019-04-02 11:16:52 +02:00
|
|
|
explicit API(const string &instance, const string &access_token);
|
2018-05-13 15:41:19 +02:00
|
|
|
|
2018-05-17 17:59:44 +02:00
|
|
|
/*!
|
2019-04-02 11:16:52 +02:00
|
|
|
* @brief Destroys the object.
|
2019-03-30 13:06:57 +01:00
|
|
|
*
|
2019-04-02 11:16:52 +02:00
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
|
|
|
virtual ~API();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Sets the useragent. Default is mastodon-cpp/version.
|
2018-05-17 17:59:44 +02:00
|
|
|
*
|
2019-04-02 11:16:52 +02:00
|
|
|
* @param useragent The useragent
|
2019-03-30 13:06:57 +01:00
|
|
|
*
|
2019-04-02 11:16:52 +02:00
|
|
|
* @since before 0.11.0
|
2018-05-17 17:59:44 +02:00
|
|
|
*/
|
2019-04-02 11:16:52 +02:00
|
|
|
void set_useragent(const string &useragent);
|
2018-02-26 07:57:30 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Gets the useragent.
|
|
|
|
*
|
|
|
|
* @return The useragent.
|
|
|
|
*
|
|
|
|
* @since before 0.11.0
|
|
|
|
*/
|
|
|
|
const string get_useragent() const;
|
2018-06-14 11:17:26 +02:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Returns the instance.
|
|
|
|
*
|
|
|
|
* @return The instance.
|
|
|
|
*
|
|
|
|
* @since before 0.11.0
|
|
|
|
*/
|
|
|
|
const string get_instance() const;
|
2018-01-13 00:34:16 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
2019-04-19 09:11:37 +02:00
|
|
|
* @brief Alias for Mastodon::urlencode.
|
2019-04-02 11:16:52 +02:00
|
|
|
*
|
|
|
|
* @param str The string
|
|
|
|
*
|
|
|
|
* @return The percent-encoded string
|
|
|
|
*
|
|
|
|
* @since before 0.11.0
|
|
|
|
*/
|
2019-04-19 09:11:37 +02:00
|
|
|
[[deprecated("Replaced by Mastodon::urlencode")]]
|
2019-04-02 11:16:52 +02:00
|
|
|
static const string urlencode(const string &str);
|
2018-06-11 00:28:28 +02:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
2019-04-19 09:11:37 +02:00
|
|
|
* @brief Alias for Mastodon::urldecode.
|
2019-04-02 11:16:52 +02:00
|
|
|
*
|
|
|
|
* @param str The string
|
|
|
|
*
|
|
|
|
* @return The decoded string
|
|
|
|
*
|
|
|
|
* @since 0.18.0
|
|
|
|
*/
|
2019-04-19 09:11:37 +02:00
|
|
|
[[deprecated("Replaced by Mastodon::urldecode")]]
|
2019-04-02 11:16:52 +02:00
|
|
|
static const string urldecode(const string &str);
|
2018-01-13 00:34:16 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Register application, step 1/2
|
|
|
|
*
|
|
|
|
* @param client_name The name of the application
|
|
|
|
* @param redirect_uri urn:ietf:wg:oauth:2.0:oob for none
|
|
|
|
* @param scopes Scopes (`read`, `write`, `follow`, `push`;
|
|
|
|
* space separated)
|
|
|
|
* @param website The website of the application
|
|
|
|
* @param client_id Returned
|
|
|
|
* @param client_secret Returned
|
|
|
|
* @param url Returned, used to generate code for
|
|
|
|
* register_app2
|
|
|
|
*
|
2019-04-13 02:27:21 +02:00
|
|
|
* @since before 0.100.0
|
2019-04-02 11:16:52 +02:00
|
|
|
*/
|
|
|
|
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);
|
2019-02-25 14:36:49 +01:00
|
|
|
|
2018-01-21 23:54:42 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Register application, step 2/2
|
|
|
|
*
|
|
|
|
* The access token will be used in all subsequent calls.
|
|
|
|
*
|
|
|
|
* @param client_id
|
|
|
|
* @param client_secret
|
|
|
|
* @param redirect_uri urn:ietf:wg:oauth:2.0:oob for none
|
|
|
|
* @param code The code generated by the website
|
|
|
|
* @param access_token Returned
|
|
|
|
*
|
2019-04-13 02:27:21 +02:00
|
|
|
* @since before 0.100.0
|
2019-04-02 11:16:52 +02:00
|
|
|
*/
|
|
|
|
return_call register_app2(const string &client_id,
|
|
|
|
const string &client_secret,
|
|
|
|
const string &redirect_uri,
|
|
|
|
const string &code,
|
|
|
|
string &access_token);
|
2018-03-07 10:27:27 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Gets the header from the last answer.
|
|
|
|
*
|
|
|
|
* @param header The header to get
|
|
|
|
*
|
|
|
|
* @return The header, or "" on error.
|
|
|
|
*
|
|
|
|
* @since before 0.11.0
|
|
|
|
*/
|
|
|
|
const string get_header(const string &header) const;
|
2018-01-21 23:54:42 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Turn exceptions on or off. Defaults to off.
|
|
|
|
*
|
|
|
|
* This applies to exceptions from curlpp. curlpp::RuntimeError
|
|
|
|
* and curlpp::LogicError.
|
|
|
|
*
|
|
|
|
* @param value true for on, false for off
|
|
|
|
*
|
|
|
|
* @return true if exceptions are turned on, false otherwise
|
|
|
|
*
|
|
|
|
* @since before 0.11.0
|
|
|
|
*/
|
|
|
|
bool exceptions(const bool &value);
|
2018-06-28 14:19:43 +02:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Returns true if exceptions are turned on, false otherwise
|
|
|
|
*/
|
|
|
|
bool exceptions() const;
|
2018-02-28 07:00:24 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
2019-04-19 09:11:37 +02:00
|
|
|
* @brief Alias for Mastodon::unescape_html.
|
2019-04-02 11:16:52 +02:00
|
|
|
*
|
|
|
|
* @since 0.12.0
|
|
|
|
*/
|
2019-04-19 09:11:37 +02:00
|
|
|
[[deprecated("Replaced by Mastodon::unescape_html")]]
|
2019-04-02 11:16:52 +02:00
|
|
|
static const string unescape_html(const string &html);
|
2018-02-09 22:37:57 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Sets the proxy.
|
|
|
|
*
|
|
|
|
* Since mastodon-cpp is built on libcurl, it respects the same
|
|
|
|
* proxy environment variables. See `man curl`.
|
|
|
|
*
|
|
|
|
* @param proxy See `man 3 CURLOPT_PROXY`
|
|
|
|
* @param userpw See `man 3 CURLOPT_PROXYUSERPWD` (optional)
|
|
|
|
*
|
|
|
|
* @since 0.15.0
|
|
|
|
*/
|
|
|
|
void set_proxy(const string &proxy, const string &userpw = "");
|
2018-02-28 07:00:24 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief For internal use
|
|
|
|
*
|
|
|
|
* @param proxy URL
|
|
|
|
* @param userpw username:password
|
|
|
|
*
|
|
|
|
* @since 0.15.1
|
|
|
|
*/
|
|
|
|
void get_proxy(string &proxy, string &userpw) const;
|
2018-04-03 00:04:47 +02:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
2019-05-01 01:28:46 +02:00
|
|
|
* @brief Make a GET request that doesn't require parameters.
|
2019-04-02 11:16:52 +02:00
|
|
|
*
|
|
|
|
* @param call A call defined in Mastodon::API::v1
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
|
|
|
const return_call get(const Mastodon::API::v1 &call);
|
2018-04-10 10:17:30 +02:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
2019-05-01 01:28:46 +02:00
|
|
|
* @brief Make a GET request that requires parameters.
|
2019-04-02 11:16:52 +02:00
|
|
|
*
|
|
|
|
* @param call A call defined in Mastodon::API::v1
|
|
|
|
* @param parameters A Mastodon::parametermap containing
|
|
|
|
* parameters
|
|
|
|
*
|
2019-04-13 02:27:21 +02:00
|
|
|
* @since 0.100.0
|
2019-04-02 11:16:52 +02:00
|
|
|
*/
|
|
|
|
const return_call get(const Mastodon::API::v1 &call,
|
2019-04-12 01:10:33 +02:00
|
|
|
const parameters ¶meters);
|
2018-04-10 10:17:30 +02:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
2019-05-01 01:28:46 +02:00
|
|
|
* @brief Make a GET request that requires parameters.
|
2019-04-02 11:16:52 +02:00
|
|
|
*
|
|
|
|
* @param call A call defined in Mastodon::API::v2
|
|
|
|
* @param parameters A Mastodon::parametermap containing
|
|
|
|
* parameters
|
|
|
|
*
|
2019-04-13 02:27:21 +02:00
|
|
|
* @since 0.100.0
|
2019-04-02 11:16:52 +02:00
|
|
|
*/
|
|
|
|
const return_call get(const Mastodon::API::v2 &call,
|
2019-04-12 01:10:33 +02:00
|
|
|
const parameters ¶meters);
|
2018-05-09 06:09:47 +02:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Make a custom GET request.
|
|
|
|
*
|
|
|
|
* @param call String in the form `/api/v1/example`
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
|
|
|
const return_call get(const string &call);
|
2018-05-26 22:34:31 +02:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Make a streaming GET request.
|
|
|
|
*
|
|
|
|
* @param call A call defined in Mastodon::API::v1
|
|
|
|
* @param parameters A Mastodon::parametermap containing
|
|
|
|
* parameters
|
|
|
|
* @param ptr Pointer to the http object. Can be used to call
|
|
|
|
* ptr->cancel_stream()
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
2019-04-10 20:52:36 +02:00
|
|
|
void get_stream(const Mastodon::API::v1 &call,
|
2019-04-12 01:10:33 +02:00
|
|
|
const parameters ¶meters,
|
2019-04-10 20:52:36 +02:00
|
|
|
std::unique_ptr<Mastodon::API::http> &ptr,
|
|
|
|
string &stream);
|
2018-05-26 23:48:03 +02:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Make a streaming GET request.
|
|
|
|
*
|
|
|
|
* @param call A call defined in Mastodon::API::v1
|
|
|
|
* @param ptr Pointer to the http object. Can be used to call
|
|
|
|
* ptr->cancel_stream()
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
2019-04-10 20:52:36 +02:00
|
|
|
void get_stream(const Mastodon::API::v1 &call,
|
2019-04-10 02:25:55 +02:00
|
|
|
std::unique_ptr<Mastodon::API::http> &ptr,
|
|
|
|
string &stream);
|
2018-01-13 00:34:16 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Make a streaming GET request.
|
|
|
|
*
|
|
|
|
* @param call String in the form `/api/v1/example`
|
|
|
|
* @param ptr Pointer to the http object. Can be used to call
|
|
|
|
* ptr->cancel_stream()
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
2019-04-10 20:52:36 +02:00
|
|
|
void get_stream(const string &call,
|
2019-04-10 02:25:55 +02:00
|
|
|
std::unique_ptr<Mastodon::API::http> &ptr,
|
|
|
|
string &stream);
|
2018-01-13 00:34:16 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Make a PATCH request.
|
|
|
|
*
|
2019-04-27 21:48:15 +02:00
|
|
|
* Binary data must be a filename.
|
2019-04-02 11:16:52 +02:00
|
|
|
*
|
|
|
|
* @param call A call defined in Mastodon::API::v1
|
|
|
|
* @param parameters A Mastodon::parametermap containing
|
|
|
|
* parameters
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
|
|
|
return_call patch(const Mastodon::API::v1 &call,
|
2019-04-12 01:10:33 +02:00
|
|
|
const parameters ¶meters);
|
2018-06-11 00:28:28 +02:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
2019-05-01 01:28:46 +02:00
|
|
|
* @brief Make a POST request that doesn't require parameters.
|
2019-04-02 11:16:52 +02:00
|
|
|
*
|
|
|
|
* @param call A call defined in Mastodon::API::v1
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
|
|
|
return_call post(const Mastodon::API::v1 &call);
|
2018-01-13 00:34:16 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
2019-05-01 01:28:46 +02:00
|
|
|
* @brief Make a POST request that requires parameters.
|
2019-04-02 11:16:52 +02:00
|
|
|
*
|
2019-04-27 21:48:15 +02:00
|
|
|
* Binary data must be a filename.
|
2019-04-02 11:16:52 +02:00
|
|
|
*
|
|
|
|
* @param call A call defined in Mastodon::API::v1
|
|
|
|
* @param parameters A Mastodon::parametermap containing
|
|
|
|
* parameters
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
|
|
|
return_call post(const Mastodon::API::v1 &call,
|
2019-04-12 01:10:33 +02:00
|
|
|
const parameters ¶meters);
|
2018-01-13 00:34:16 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Make a custom POST request.
|
|
|
|
*
|
2019-04-27 21:48:15 +02:00
|
|
|
* Binary data must be a filename.
|
2019-04-02 11:16:52 +02:00
|
|
|
*
|
|
|
|
* @param call String in the form `/api/v1/example`
|
|
|
|
* @param parameters A Mastodon::parametermap containing
|
|
|
|
* parameters
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
|
|
|
return_call post(const string &call,
|
2019-04-12 01:10:33 +02:00
|
|
|
const parameters ¶meters);
|
2018-01-21 23:54:42 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
2019-05-01 01:28:46 +02:00
|
|
|
* @brief Make a PUT request that requires parameters.
|
2019-04-02 11:16:52 +02:00
|
|
|
*
|
|
|
|
* @param call A call defined in Mastodon::API::v1
|
|
|
|
* @param parameters A Mastodon::parametermap containing
|
|
|
|
* parameters
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
|
|
|
return_call put(const Mastodon::API::v1 &call,
|
2019-04-12 01:10:33 +02:00
|
|
|
const parameters ¶meters);
|
2018-01-21 23:54:42 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Make a custom PUT request.
|
|
|
|
*
|
|
|
|
* @param call String in the form `/api/v1/example`
|
|
|
|
* @param parameters A Mastodon::parametermap containing
|
|
|
|
* parameters
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
2019-04-12 01:10:33 +02:00
|
|
|
return_call put(const string &call, const parameters ¶meters);
|
2018-01-17 23:51:59 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
2019-05-01 01:28:46 +02:00
|
|
|
* @brief Make a DELETE request that requires parameters.
|
2019-04-02 11:16:52 +02:00
|
|
|
*
|
|
|
|
* @param call A call defined in Mastodon::API::v1
|
|
|
|
* @param parameters A Mastodon::parametermap containing
|
|
|
|
* parameters
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
|
|
|
return_call del(const Mastodon::API::v1 &call,
|
2019-04-12 01:10:33 +02:00
|
|
|
const parameters ¶meters);
|
2018-04-19 00:20:43 +02:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Make a custom DELETE request.
|
|
|
|
*
|
|
|
|
* @param call String in the form `/api/v1/example`
|
|
|
|
* @param parameters A Mastodon::parametermap containing
|
|
|
|
* parameters
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
2019-04-12 01:10:33 +02:00
|
|
|
return_call del(const string &call, const parameters ¶meters);
|
2018-01-24 18:52:24 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
private:
|
|
|
|
const string _instance;
|
|
|
|
string _access_token;
|
|
|
|
string _useragent;
|
|
|
|
http _http;
|
|
|
|
bool _exceptions;
|
|
|
|
string _proxy;
|
|
|
|
string _proxy_userpw;
|
2018-01-13 00:34:16 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Converts map of parameters into a string.
|
|
|
|
*
|
|
|
|
* @param map Map of parameters
|
|
|
|
* @param firstparam Contains this map the first parameter?
|
|
|
|
*
|
|
|
|
* @return String of parameters
|
|
|
|
*/
|
2019-04-12 01:10:33 +02:00
|
|
|
const string maptostr(const parameters &map,
|
2019-04-02 11:16:52 +02:00
|
|
|
const bool &firstparam = true);
|
2018-02-09 16:17:32 +01:00
|
|
|
|
2019-04-02 11:16:52 +02:00
|
|
|
/*!
|
|
|
|
* @brief Converts map of parameters into form data
|
|
|
|
*
|
|
|
|
* @param map Map of parameters
|
|
|
|
*
|
|
|
|
* @return Form data as curlpp::Forms
|
|
|
|
*/
|
2019-04-12 01:10:33 +02:00
|
|
|
const curlpp::Forms maptoformdata(const parameters &map);
|
2019-04-14 19:57:39 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Delete Mastodon::param from Mastodon::parameters.
|
|
|
|
*
|
|
|
|
* @param params Old vector of parameters.
|
|
|
|
* @param key keys of Mastodon::param to delete.
|
|
|
|
*
|
|
|
|
* @return New vector of parameters.
|
|
|
|
*
|
|
|
|
* @since 0.102.0
|
|
|
|
*/
|
|
|
|
const parameters delete_params(const parameters ¶ms,
|
|
|
|
const vector<string> &keys);
|
2019-04-02 11:16:52 +02:00
|
|
|
};
|
2019-04-19 09:11:37 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief 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.
|
|
|
|
*
|
|
|
|
* @param str The string to encode.
|
|
|
|
*
|
|
|
|
* @return The percent-encoded string.
|
|
|
|
*
|
|
|
|
* @since 0.105.0
|
|
|
|
*/
|
|
|
|
const string urlencode(const string &str);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Decodes a percent-encoded string.
|
|
|
|
*
|
|
|
|
* Calls curlpp::unescape(str).
|
|
|
|
*
|
|
|
|
* See RFC 3986 section 2.1 for more info.
|
|
|
|
*
|
|
|
|
* @param str The string to decode.
|
|
|
|
*
|
|
|
|
* @return The decoded string.
|
|
|
|
*
|
|
|
|
* @since 0.105.0
|
|
|
|
*/
|
|
|
|
const string urldecode(const string &str);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Replaces HTML entities with UTF-8 characters.
|
|
|
|
*
|
|
|
|
* Supports named and numbered entities, decimal and
|
|
|
|
* hexadecimal.
|
|
|
|
*
|
|
|
|
* @param html The html to unescape.
|
|
|
|
*
|
|
|
|
* @return The unescaped string.
|
|
|
|
*
|
|
|
|
* @since 0.105.0
|
|
|
|
*/
|
|
|
|
const string unescape_html(const string &html);
|
2018-01-09 22:12:11 +01:00
|
|
|
}
|
2018-01-06 21:33:52 +01:00
|
|
|
|
|
|
|
#endif
|