Moved types to types.hpp and reformatted mastodon-cpp.hpp.
Also renamed easy/types.hpp to easy/types_easy.hpp.
This commit is contained in:
parent
38e8809b92
commit
b49e8600ac
|
@ -28,13 +28,13 @@
|
|||
#ifdef MASTODON_CPP
|
||||
#include "mastodon-cpp.hpp"
|
||||
#include "easy/return_types_easy.hpp"
|
||||
#include "easy/types.hpp"
|
||||
#include "easy/types_easy.hpp"
|
||||
#include "easy/entities/notification.hpp"
|
||||
#include "easy/entities/status.hpp"
|
||||
#else
|
||||
#include <mastodon-cpp/mastodon-cpp.hpp>
|
||||
#include <mastodon-cpp/easy/return_types_easy.hpp>
|
||||
#include <mastodon-cpp/easy/types.hpp>
|
||||
#include <mastodon-cpp/easy/types_easy.hpp>
|
||||
#include <mastodon-cpp/easy/entities/notification.hpp>
|
||||
#include <mastodon-cpp/easy/entities/status.hpp>
|
||||
#endif
|
||||
|
|
|
@ -14,17 +14,17 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ENTITY_HPP
|
||||
#define ENTITY_HPP
|
||||
#ifndef MASTODON_CPP_EASY_ENTITY_HPP
|
||||
#define MASTODON_CPP_EASY_ENTITY_HPP
|
||||
|
||||
#include <string>
|
||||
#include <jsoncpp/json/json.h>
|
||||
|
||||
// If we are compiling mastodon-cpp, use another include path
|
||||
#ifdef MASTODON_CPP
|
||||
#include "easy/types.hpp"
|
||||
#include "easy/types_easy.hpp"
|
||||
#else
|
||||
#include <mastodon-cpp/easy/types.hpp>
|
||||
#include <mastodon-cpp/easy/types_easy.hpp>
|
||||
#endif
|
||||
|
||||
using std::string;
|
||||
|
@ -240,4 +240,4 @@ namespace Easy
|
|||
}
|
||||
}
|
||||
|
||||
#endif // ENTITY_HPP
|
||||
#endif // MASTODON_CPP_EASY_ENTITY_HPP
|
||||
|
|
|
@ -30,7 +30,7 @@ const return_entity<Status> API::send_toot(const Status &status)
|
|||
|
||||
const return_entity<Status> API::send_post(const Status &status)
|
||||
{
|
||||
API::parametermap parameters;
|
||||
parametermap parameters;
|
||||
|
||||
if (!status.content().empty())
|
||||
{
|
||||
|
@ -86,7 +86,7 @@ const return_entity<Status> API::send_post(const Status &status)
|
|||
std::vector<string> media_ids;
|
||||
for (const Attachment &att : status.media_attachments())
|
||||
{
|
||||
API::parametermap param_att;
|
||||
parametermap param_att;
|
||||
if (!att.file().empty())
|
||||
{
|
||||
param_att.insert({ "file", { att.file() }});
|
||||
|
@ -132,7 +132,7 @@ const return_entity<Status> API::send_post(const Status &status)
|
|||
const return_entity_vector<Notification> API::get_notifications(
|
||||
const uint16_t limit, const string since_id, const string max_id)
|
||||
{
|
||||
API::parametermap parameters;
|
||||
parametermap parameters;
|
||||
|
||||
parameters.insert({ "limit", { std::to_string(limit) } });
|
||||
if (!since_id.empty())
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "types.hpp"
|
||||
#include "types_easy.hpp"
|
||||
|
||||
using namespace Mastodon;
|
||||
|
|
@ -14,8 +14,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MASTODON_CPP_TYPES_HPP
|
||||
#define MASTODON_CPP_TYPES_HPP
|
||||
#ifndef MASTODON_CPP_EASY_TYPES_EASY_HPP
|
||||
#define MASTODON_CPP_EASY_TYPES_EASY_HPP
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
@ -152,4 +152,4 @@ namespace Easy
|
|||
};
|
||||
}
|
||||
}
|
||||
#endif // MASTODON_CPP_TYPES_HPP
|
||||
#endif // MASTODON_CPP_EASY_TYPES_EASY_HPP
|
|
@ -159,7 +159,7 @@ return_call API::register_app1(const string &client_name,
|
|||
string &client_secret,
|
||||
string &url)
|
||||
{
|
||||
API::parametermap parameters =
|
||||
parametermap parameters =
|
||||
{
|
||||
{ "client_name", { client_name } },
|
||||
{ "redirect_uris", { redirect_uri } },
|
||||
|
@ -207,7 +207,7 @@ return_call API::register_app2(const string &client_id,
|
|||
const string &code,
|
||||
string &access_token)
|
||||
{
|
||||
API::parametermap parameters =
|
||||
parametermap parameters =
|
||||
{
|
||||
{ "client_id", { client_id } },
|
||||
{ "client_secret", { client_secret } },
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
|
@ -30,8 +29,10 @@
|
|||
// If we are compiling mastodon-cpp, use another include path
|
||||
#ifdef MASTODON_CPP
|
||||
#include "return_types.hpp"
|
||||
#include "types.hpp"
|
||||
#else
|
||||
#include <mastodon-cpp/return_types.hpp>
|
||||
#include <mastodon-cpp/types.hpp>
|
||||
#endif
|
||||
|
||||
using std::string;
|
||||
|
@ -42,7 +43,7 @@ using std::string;
|
|||
|
||||
namespace Mastodon
|
||||
{
|
||||
/*!
|
||||
/*!
|
||||
* @brief Interface to the Mastodon API.
|
||||
*
|
||||
* All input is expected to be UTF-8. Binary data must be
|
||||
|
@ -63,9 +64,9 @@ namespace Mastodon
|
|||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
class API
|
||||
{
|
||||
public:
|
||||
class API
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* @brief http class. Do not use this directly.
|
||||
*
|
||||
|
@ -100,8 +101,8 @@ public:
|
|||
* @param formdata The form data for PATCH and POST requests.
|
||||
* @param answer The answer from the server
|
||||
*
|
||||
* @return @ref error "Error code". If the URL has permanently changed,
|
||||
* 13 is returned and answer is set to the new URL.
|
||||
* @return @ref error "Error code". If the URL has permanently
|
||||
* changed, 13 is returned and answer is set to the new URL.
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
|
@ -117,10 +118,9 @@ public:
|
|||
/*!
|
||||
* @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.
|
||||
* 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
|
||||
*/
|
||||
|
@ -129,8 +129,8 @@ public:
|
|||
/*!
|
||||
* @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().
|
||||
* The mutex guards the function that writes to the string
|
||||
* you specified in get_stream().
|
||||
*
|
||||
* @return A reference of the mutex.
|
||||
*
|
||||
|
@ -152,22 +152,6 @@ public:
|
|||
double /* ultotal */, double /* ulnow */);
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Used for passing parameters.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* parametermap p =
|
||||
* {
|
||||
* {"field1", { "value1", "value2" } },
|
||||
* {"field2", { "value" } }
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
typedef std::map<string, std::vector<string>> parametermap;
|
||||
|
||||
/*!
|
||||
* @brief A list of all v1 API calls.
|
||||
*
|
||||
|
@ -294,8 +278,8 @@ public:
|
|||
/*!
|
||||
* @brief Constructs a new API object.
|
||||
*
|
||||
* To register your application, leave access_token blank and call
|
||||
* register_app1() and register_app2().
|
||||
* To register your application, leave access_token blank and
|
||||
* call register_app1() and register_app2().
|
||||
*
|
||||
* @param instance The hostname of your instance
|
||||
* @param access_token Your access token.
|
||||
|
@ -339,8 +323,8 @@ public:
|
|||
const string get_instance() const;
|
||||
|
||||
/*!
|
||||
* @brief Percent-encodes a string. This is done automatically, unless you
|
||||
* make a custom request.
|
||||
* @brief Percent-encodes a string. This is done automatically, unless
|
||||
* you make a custom request.
|
||||
*
|
||||
* Calls curlpp::escape(str)
|
||||
*
|
||||
|
@ -377,15 +361,16 @@ public:
|
|||
*
|
||||
* @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 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
|
||||
* @param url Returned, used to generate code for
|
||||
* register_app2
|
||||
*
|
||||
* @return @ref error "Error code". If the URL has permanently changed, 13
|
||||
* is returned and url is set to the new URL.
|
||||
* @return @ref error "Error code". If the URL has permanently changed,
|
||||
* 13 is returned and url is set to the new URL.
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
|
@ -433,8 +418,8 @@ public:
|
|||
/*!
|
||||
* @brief Turn exceptions on or off. Defaults to off.
|
||||
*
|
||||
* This applies to exceptions from curlpp. curlpp::RuntimeError and
|
||||
* curlpp::LogicError.
|
||||
* This applies to exceptions from curlpp. curlpp::RuntimeError
|
||||
* and curlpp::LogicError.
|
||||
*
|
||||
* @param value true for on, false for off
|
||||
*
|
||||
|
@ -452,7 +437,8 @@ public:
|
|||
/*!
|
||||
* @brief Replaces HTML entities with UTF-8 characters
|
||||
*
|
||||
* Supports named and numbered entities, decimal and hexadecimal.
|
||||
* Supports named and numbered entities, decimal and
|
||||
* hexadecimal.
|
||||
*
|
||||
* @since 0.12.0
|
||||
*/
|
||||
|
@ -496,7 +482,8 @@ public:
|
|||
* @brief Make a GET request which requires parameters.
|
||||
*
|
||||
* @param call A call defined in Mastodon::API::v1
|
||||
* @param parameters A Mastodon::API::parametermap containing parameters
|
||||
* @param parameters A Mastodon::parametermap containing
|
||||
* parameters
|
||||
*
|
||||
* @return @ref error "Error code".
|
||||
*/
|
||||
|
@ -509,7 +496,8 @@ public:
|
|||
* @since 0.100.0
|
||||
*
|
||||
* @param call A call defined in Mastodon::API::v2
|
||||
* @param parameters A Mastodon::API::parametermap containing parameters
|
||||
* @param parameters A Mastodon::parametermap containing
|
||||
* parameters
|
||||
*
|
||||
* @return @ref error "Error code".
|
||||
*/
|
||||
|
@ -531,7 +519,8 @@ public:
|
|||
* @brief Make a streaming GET request.
|
||||
*
|
||||
* @param call A call defined in Mastodon::API::v1
|
||||
* @param parameters A Mastodon::API::parametermap containing parameters
|
||||
* @param parameters A Mastodon::parametermap containing
|
||||
* parameters
|
||||
* @param ptr Pointer to the http object. Can be used to call
|
||||
* ptr->cancel_stream()
|
||||
*
|
||||
|
@ -577,7 +566,8 @@ public:
|
|||
* Binary data must be base64-encoded or a filename.
|
||||
*
|
||||
* @param call A call defined in Mastodon::API::v1
|
||||
* @param parameters A Mastodon::API::parametermap containing parameters
|
||||
* @param parameters A Mastodon::parametermap containing
|
||||
* parameters
|
||||
*
|
||||
* @return @ref error "Error code".
|
||||
*
|
||||
|
@ -603,7 +593,8 @@ public:
|
|||
* Binary data must be base64-encoded or a filename.
|
||||
*
|
||||
* @param call A call defined in Mastodon::API::v1
|
||||
* @param parameters A Mastodon::API::parametermap containing parameters
|
||||
* @param parameters A Mastodon::parametermap containing
|
||||
* parameters
|
||||
*
|
||||
* @return @ref error "Error code".
|
||||
*
|
||||
|
@ -618,7 +609,8 @@ public:
|
|||
* Binary data must be base64-encoded or a filename.
|
||||
*
|
||||
* @param call String in the form `/api/v1/example`
|
||||
* @param parameters A Mastodon::API::parametermap containing parameters
|
||||
* @param parameters A Mastodon::parametermap containing
|
||||
* parameters
|
||||
*
|
||||
* @return @ref error "Error code".
|
||||
*
|
||||
|
@ -631,7 +623,8 @@ public:
|
|||
* @brief Make a PUT request which requires a parameters.
|
||||
*
|
||||
* @param call A call defined in Mastodon::API::v1
|
||||
* @param parameters A Mastodon::API::parametermap containing parameters
|
||||
* @param parameters A Mastodon::parametermap containing
|
||||
* parameters
|
||||
*
|
||||
* @return @ref error "Error code".
|
||||
*
|
||||
|
@ -644,7 +637,8 @@ public:
|
|||
* @brief Make a custom PUT request.
|
||||
*
|
||||
* @param call String in the form `/api/v1/example`
|
||||
* @param parameters A Mastodon::API::parametermap containing parameters
|
||||
* @param parameters A Mastodon::parametermap containing
|
||||
* parameters
|
||||
*
|
||||
* @return @ref error "Error code".
|
||||
*
|
||||
|
@ -656,7 +650,8 @@ public:
|
|||
* @brief Make a DELETE request which requires parameters.
|
||||
*
|
||||
* @param call A call defined in Mastodon::API::v1
|
||||
* @param parameters A Mastodon::API::parametermap containing parameters
|
||||
* @param parameters A Mastodon::parametermap containing
|
||||
* parameters
|
||||
*
|
||||
* @return @ref error "Error code".
|
||||
*
|
||||
|
@ -669,7 +664,8 @@ public:
|
|||
* @brief Make a custom DELETE request.
|
||||
*
|
||||
* @param call String in the form `/api/v1/example`
|
||||
* @param parameters A Mastodon::API::parametermap containing parameters
|
||||
* @param parameters A Mastodon::parametermap containing
|
||||
* parameters
|
||||
*
|
||||
* @return @ref error "Error code".
|
||||
*
|
||||
|
@ -677,7 +673,7 @@ public:
|
|||
*/
|
||||
return_call del(const string &call, const parametermap ¶meters);
|
||||
|
||||
private:
|
||||
private:
|
||||
const string _instance;
|
||||
string _access_token;
|
||||
string _useragent;
|
||||
|
@ -705,7 +701,7 @@ private:
|
|||
* @return Form data as curlpp::Forms
|
||||
*/
|
||||
const curlpp::Forms maptoformdata(const parametermap &map);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/* This file is part of mastodon-cpp.
|
||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
||||
*
|
||||
* 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_TYPES_HPP
|
||||
#define MASTODON_CPP_TYPES_HPP
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace Mastodon
|
||||
{
|
||||
/*!
|
||||
* @brief Used for passing parameters.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* parametermap p =
|
||||
* {
|
||||
* {"field1", { "value1", "value2" } },
|
||||
* {"field2", { "value" } }
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
typedef std::map<string, std::vector<string>> parametermap;
|
||||
}
|
||||
|
||||
#endif // MASTODON_CPP_TYPES_HPP
|
Reference in New Issue