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:
tastytea 2019-04-02 11:16:52 +02:00
parent 38e8809b92
commit b49e8600ac
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
8 changed files with 693 additions and 652 deletions

View File

@ -28,13 +28,13 @@
#ifdef MASTODON_CPP #ifdef MASTODON_CPP
#include "mastodon-cpp.hpp" #include "mastodon-cpp.hpp"
#include "easy/return_types_easy.hpp" #include "easy/return_types_easy.hpp"
#include "easy/types.hpp" #include "easy/types_easy.hpp"
#include "easy/entities/notification.hpp" #include "easy/entities/notification.hpp"
#include "easy/entities/status.hpp" #include "easy/entities/status.hpp"
#else #else
#include <mastodon-cpp/mastodon-cpp.hpp> #include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/return_types_easy.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/notification.hpp>
#include <mastodon-cpp/easy/entities/status.hpp> #include <mastodon-cpp/easy/entities/status.hpp>
#endif #endif

View File

@ -14,17 +14,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ENTITY_HPP #ifndef MASTODON_CPP_EASY_ENTITY_HPP
#define ENTITY_HPP #define MASTODON_CPP_EASY_ENTITY_HPP
#include <string> #include <string>
#include <jsoncpp/json/json.h> #include <jsoncpp/json/json.h>
// If we are compiling mastodon-cpp, use another include path // If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP #ifdef MASTODON_CPP
#include "easy/types.hpp" #include "easy/types_easy.hpp"
#else #else
#include <mastodon-cpp/easy/types.hpp> #include <mastodon-cpp/easy/types_easy.hpp>
#endif #endif
using std::string; using std::string;
@ -240,4 +240,4 @@ namespace Easy
} }
} }
#endif // ENTITY_HPP #endif // MASTODON_CPP_EASY_ENTITY_HPP

View File

@ -30,7 +30,7 @@ const return_entity<Status> API::send_toot(const Status &status)
const return_entity<Status> API::send_post(const Status &status) const return_entity<Status> API::send_post(const Status &status)
{ {
API::parametermap parameters; parametermap parameters;
if (!status.content().empty()) if (!status.content().empty())
{ {
@ -86,7 +86,7 @@ const return_entity<Status> API::send_post(const Status &status)
std::vector<string> media_ids; std::vector<string> media_ids;
for (const Attachment &att : status.media_attachments()) for (const Attachment &att : status.media_attachments())
{ {
API::parametermap param_att; parametermap param_att;
if (!att.file().empty()) if (!att.file().empty())
{ {
param_att.insert({ "file", { att.file() }}); 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 return_entity_vector<Notification> API::get_notifications(
const uint16_t limit, const string since_id, const string max_id) const uint16_t limit, const string since_id, const string max_id)
{ {
API::parametermap parameters; parametermap parameters;
parameters.insert({ "limit", { std::to_string(limit) } }); parameters.insert({ "limit", { std::to_string(limit) } });
if (!since_id.empty()) if (!since_id.empty())

View File

@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "types.hpp" #include "types_easy.hpp"
using namespace Mastodon; using namespace Mastodon;

View File

@ -14,8 +14,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef MASTODON_CPP_TYPES_HPP #ifndef MASTODON_CPP_EASY_TYPES_EASY_HPP
#define MASTODON_CPP_TYPES_HPP #define MASTODON_CPP_EASY_TYPES_EASY_HPP
#include <string> #include <string>
#include <utility> #include <utility>
@ -152,4 +152,4 @@ namespace Easy
}; };
} }
} }
#endif // MASTODON_CPP_TYPES_HPP #endif // MASTODON_CPP_EASY_TYPES_EASY_HPP

View File

@ -159,7 +159,7 @@ return_call API::register_app1(const string &client_name,
string &client_secret, string &client_secret,
string &url) string &url)
{ {
API::parametermap parameters = parametermap parameters =
{ {
{ "client_name", { client_name } }, { "client_name", { client_name } },
{ "redirect_uris", { redirect_uri } }, { "redirect_uris", { redirect_uri } },
@ -207,7 +207,7 @@ return_call API::register_app2(const string &client_id,
const string &code, const string &code,
string &access_token) string &access_token)
{ {
API::parametermap parameters = parametermap parameters =
{ {
{ "client_id", { client_id } }, { "client_id", { client_id } },
{ "client_secret", { client_secret } }, { "client_secret", { client_secret } },

View File

@ -19,7 +19,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <map>
#include <memory> #include <memory>
#include <array> #include <array>
#include <mutex> #include <mutex>
@ -30,8 +29,10 @@
// If we are compiling mastodon-cpp, use another include path // If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP #ifdef MASTODON_CPP
#include "return_types.hpp" #include "return_types.hpp"
#include "types.hpp"
#else #else
#include <mastodon-cpp/return_types.hpp> #include <mastodon-cpp/return_types.hpp>
#include <mastodon-cpp/types.hpp>
#endif #endif
using std::string; using std::string;
@ -42,7 +43,7 @@ using std::string;
namespace Mastodon namespace Mastodon
{ {
/*! /*!
* @brief Interface to the Mastodon API. * @brief Interface to the Mastodon API.
* *
* All input is expected to be UTF-8. Binary data must be * All input is expected to be UTF-8. Binary data must be
@ -63,9 +64,9 @@ namespace Mastodon
* *
* @since before 0.11.0 * @since before 0.11.0
*/ */
class API class API
{ {
public: public:
/*! /*!
* @brief http class. Do not use this directly. * @brief http class. Do not use this directly.
* *
@ -100,8 +101,8 @@ public:
* @param formdata The form data for PATCH and POST requests. * @param formdata The form data for PATCH and POST requests.
* @param answer The answer from the server * @param answer The answer from the server
* *
* @return @ref error "Error code". If the URL has permanently changed, * @return @ref error "Error code". If the URL has permanently
* 13 is returned and answer is set to the new URL. * changed, 13 is returned and answer is set to the new URL.
* *
* @since before 0.11.0 * @since before 0.11.0
*/ */
@ -117,10 +118,9 @@ public:
/*! /*!
* @brief Cancels the stream. Use only with streams. * @brief Cancels the stream. Use only with streams.
* *
* Cancels the stream next time data comes in. Can take a few * Cancels the stream next time data comes in. Can take a
* seconds. * few seconds. This works only with streams, because only
* This works only with streams, because only streams have an * streams have an own http object.
* own http object.
* *
* @since 0.12.2 * @since 0.12.2
*/ */
@ -129,8 +129,8 @@ public:
/*! /*!
* @brief Gets the mutex guarding the string that is written to. * @brief Gets the mutex guarding the string that is written to.
* *
* The mutex guards the function that writes to the string you * The mutex guards the function that writes to the string
* specified in get_stream(). * you specified in get_stream().
* *
* @return A reference of the mutex. * @return A reference of the mutex.
* *
@ -152,22 +152,6 @@ public:
double /* ultotal */, double /* ulnow */); 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. * @brief A list of all v1 API calls.
* *
@ -294,8 +278,8 @@ public:
/*! /*!
* @brief Constructs a new API object. * @brief Constructs a new API object.
* *
* To register your application, leave access_token blank and call * To register your application, leave access_token blank and
* register_app1() and register_app2(). * call register_app1() and register_app2().
* *
* @param instance The hostname of your instance * @param instance The hostname of your instance
* @param access_token Your access token. * @param access_token Your access token.
@ -339,8 +323,8 @@ public:
const string get_instance() const; const string get_instance() const;
/*! /*!
* @brief Percent-encodes a string. This is done automatically, unless you * @brief Percent-encodes a string. This is done automatically, unless
* make a custom request. * you make a custom request.
* *
* Calls curlpp::escape(str) * Calls curlpp::escape(str)
* *
@ -377,15 +361,16 @@ public:
* *
* @param client_name The name of the application * @param client_name The name of the application
* @param redirect_uri urn:ietf:wg:oauth:2.0:oob for none * @param redirect_uri urn:ietf:wg:oauth:2.0:oob for none
* @param scopes Scopes (`read`, `write`, `follow`, `push`; space * @param scopes Scopes (`read`, `write`, `follow`, `push`;
* separated) * space separated)
* @param website The website of the application * @param website The website of the application
* @param client_id Returned * @param client_id Returned
* @param client_secret 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 * @return @ref error "Error code". If the URL has permanently changed,
* is returned and url is set to the new URL. * 13 is returned and url is set to the new URL.
* *
* @since before 0.11.0 * @since before 0.11.0
*/ */
@ -433,8 +418,8 @@ public:
/*! /*!
* @brief Turn exceptions on or off. Defaults to off. * @brief Turn exceptions on or off. Defaults to off.
* *
* This applies to exceptions from curlpp. curlpp::RuntimeError and * This applies to exceptions from curlpp. curlpp::RuntimeError
* curlpp::LogicError. * and curlpp::LogicError.
* *
* @param value true for on, false for off * @param value true for on, false for off
* *
@ -452,7 +437,8 @@ public:
/*! /*!
* @brief Replaces HTML entities with UTF-8 characters * @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 * @since 0.12.0
*/ */
@ -496,7 +482,8 @@ public:
* @brief Make a GET request which requires parameters. * @brief Make a GET request which requires parameters.
* *
* @param call A call defined in Mastodon::API::v1 * @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". * @return @ref error "Error code".
*/ */
@ -509,7 +496,8 @@ public:
* @since 0.100.0 * @since 0.100.0
* *
* @param call A call defined in Mastodon::API::v2 * @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". * @return @ref error "Error code".
*/ */
@ -531,7 +519,8 @@ public:
* @brief Make a streaming GET request. * @brief Make a streaming GET request.
* *
* @param call A call defined in Mastodon::API::v1 * @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 * @param ptr Pointer to the http object. Can be used to call
* ptr->cancel_stream() * ptr->cancel_stream()
* *
@ -577,7 +566,8 @@ public:
* Binary data must be base64-encoded or a filename. * Binary data must be base64-encoded or a filename.
* *
* @param call A call defined in Mastodon::API::v1 * @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". * @return @ref error "Error code".
* *
@ -603,7 +593,8 @@ public:
* Binary data must be base64-encoded or a filename. * Binary data must be base64-encoded or a filename.
* *
* @param call A call defined in Mastodon::API::v1 * @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". * @return @ref error "Error code".
* *
@ -618,7 +609,8 @@ public:
* Binary data must be base64-encoded or a filename. * Binary data must be base64-encoded or a filename.
* *
* @param call String in the form `/api/v1/example` * @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". * @return @ref error "Error code".
* *
@ -631,7 +623,8 @@ public:
* @brief Make a PUT request which requires a parameters. * @brief Make a PUT request which requires a parameters.
* *
* @param call A call defined in Mastodon::API::v1 * @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". * @return @ref error "Error code".
* *
@ -644,7 +637,8 @@ public:
* @brief Make a custom PUT request. * @brief Make a custom PUT request.
* *
* @param call String in the form `/api/v1/example` * @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". * @return @ref error "Error code".
* *
@ -656,7 +650,8 @@ public:
* @brief Make a DELETE request which requires parameters. * @brief Make a DELETE request which requires parameters.
* *
* @param call A call defined in Mastodon::API::v1 * @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". * @return @ref error "Error code".
* *
@ -669,7 +664,8 @@ public:
* @brief Make a custom DELETE request. * @brief Make a custom DELETE request.
* *
* @param call String in the form `/api/v1/example` * @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". * @return @ref error "Error code".
* *
@ -677,7 +673,7 @@ public:
*/ */
return_call del(const string &call, const parametermap &parameters); return_call del(const string &call, const parametermap &parameters);
private: private:
const string _instance; const string _instance;
string _access_token; string _access_token;
string _useragent; string _useragent;
@ -705,7 +701,7 @@ private:
* @return Form data as curlpp::Forms * @return Form data as curlpp::Forms
*/ */
const curlpp::Forms maptoformdata(const parametermap &map); const curlpp::Forms maptoformdata(const parametermap &map);
}; };
} }
#endif #endif

45
src/types.hpp Normal file
View File

@ -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