Cleaned up, fixed formatting and so on.
the build was successful
Details
the build was successful
Details
This commit is contained in:
parent
76dc6a623c
commit
dff3b11c00
|
@ -1,6 +1,6 @@
|
||||||
/* This file is part of mastodon-cpp.
|
/* This file is part of mastodon-cpp.
|
||||||
* Copyright © 2018 tastytea <tastytea@tastytea.de>
|
* Copyright © 2018 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include "debug.hpp"
|
#include "debug.hpp"
|
||||||
|
|
||||||
using namespace Mastodon;
|
using namespace Mastodon;
|
||||||
using namespace Mastodon::Easy;
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
Easy::API::API(const string &instance, const string &access_token)
|
Easy::API::API(const string &instance, const string &access_token)
|
||||||
|
@ -51,8 +50,8 @@ const std::vector<string> Easy::json_array_to_vector(const string &json)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<Easy::stream_event>
|
const vector<Easy::stream_event> Easy::parse_stream(
|
||||||
Easy::parse_stream(const std::string &streamdata)
|
const std::string &streamdata)
|
||||||
{
|
{
|
||||||
string stream = streamdata;
|
string stream = streamdata;
|
||||||
std::regex reevent("event: (update|notification|delete)\ndata: (.*)\n");
|
std::regex reevent("event: (update|notification|delete)\ndata: (.*)\n");
|
||||||
|
@ -85,19 +84,19 @@ const Easy::Link Easy::API::get_link() const
|
||||||
}
|
}
|
||||||
|
|
||||||
const string Easy::API::strtime_utc(const system_clock::time_point &timepoint,
|
const string Easy::API::strtime_utc(const system_clock::time_point &timepoint,
|
||||||
const string &format)
|
const string &format)
|
||||||
{
|
{
|
||||||
return strtime(timepoint, format, true);
|
return strtime(timepoint, format, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const string Easy::API::strtime_local(const system_clock::time_point &timepoint,
|
const string Easy::API::strtime_local(const system_clock::time_point &timepoint,
|
||||||
const string &format)
|
const string &format)
|
||||||
{
|
{
|
||||||
return strtime(timepoint, format, false);
|
return strtime(timepoint, format, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const string Easy::API::strtime(const system_clock::time_point &timepoint,
|
const string Easy::API::strtime(const system_clock::time_point &timepoint,
|
||||||
const string &format, const bool &utc)
|
const string &format, const bool &utc)
|
||||||
{
|
{
|
||||||
constexpr std::uint16_t bufsize = 1024;
|
constexpr std::uint16_t bufsize = 1024;
|
||||||
std::time_t time = system_clock::to_time_t(timepoint);
|
std::time_t time = system_clock::to_time_t(timepoint);
|
||||||
|
|
|
@ -44,14 +44,14 @@ namespace Mastodon
|
||||||
{
|
{
|
||||||
/*!
|
/*!
|
||||||
* @brief Child of Mastodon::API with abstract methods.
|
* @brief Child of Mastodon::API with abstract methods.
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
namespace Easy
|
namespace Easy
|
||||||
{
|
{
|
||||||
/*!
|
/*!
|
||||||
* @brief Describes the event type
|
* @brief Describes the event type
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
enum class event_type
|
enum class event_type
|
||||||
|
@ -64,7 +64,7 @@ namespace Easy
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Describes visibility of toots.
|
* @brief Describes visibility of toots.
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
enum class visibility_type
|
enum class visibility_type
|
||||||
|
@ -78,7 +78,7 @@ namespace Easy
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Describes the attachment type
|
* @brief Describes the attachment type
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
enum class attachment_type
|
enum class attachment_type
|
||||||
|
@ -92,7 +92,7 @@ namespace Easy
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Describes the card type
|
* @brief Describes the card type
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
enum class card_type
|
enum class card_type
|
||||||
|
@ -106,7 +106,7 @@ namespace Easy
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Describes the notification type
|
* @brief Describes the notification type
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
enum class notification_type
|
enum class notification_type
|
||||||
|
@ -120,7 +120,7 @@ namespace Easy
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Used for stream events.
|
* @brief Used for stream events.
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
typedef std::pair<event_type, string> stream_event;
|
typedef std::pair<event_type, string> stream_event;
|
||||||
|
@ -129,11 +129,12 @@ namespace Easy
|
||||||
* @brief Map of 'notification type' and 'push is requested or not'
|
* @brief Map of 'notification type' and 'push is requested or not'
|
||||||
*
|
*
|
||||||
* Used in PushSubscription::alerts().
|
* Used in PushSubscription::alerts().
|
||||||
*
|
*
|
||||||
* @since 0.13.3
|
* @since 0.13.3
|
||||||
*/
|
*/
|
||||||
typedef std::map<Easy::notification_type, bool> alertmap;
|
typedef std::map<Easy::notification_type, bool> alertmap;
|
||||||
|
|
||||||
|
// TODO: Get rid of forward declarations.
|
||||||
class Account;
|
class Account;
|
||||||
class Application;
|
class Application;
|
||||||
class Attachment;
|
class Attachment;
|
||||||
|
@ -153,9 +154,9 @@ namespace Easy
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Class to hold the `Link`-header.
|
* @brief Class to hold the `Link`-header.
|
||||||
*
|
*
|
||||||
* Extracts max_id and since_id from the `Link`-header
|
* Extracts max_id and since_id from the `Link`-header
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
// TODO: Convert to struct?
|
// TODO: Convert to struct?
|
||||||
|
@ -164,35 +165,35 @@ namespace Easy
|
||||||
public:
|
public:
|
||||||
/*!
|
/*!
|
||||||
* @param link_header The content of the `Link` header
|
* @param link_header The content of the `Link` header
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
explicit Link(const string &link_header);
|
explicit Link(const string &link_header);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns max_id
|
* @brief Returns max_id
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
const string next() const;
|
const string next() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns max_id
|
* @brief Returns max_id
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
const string max_id() const;
|
const string max_id() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns since_id
|
* @brief Returns since_id
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
const string prev() const;
|
const string prev() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns since_id
|
* @brief Returns since_id
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
const string since_id() const;
|
const string since_id() const;
|
||||||
|
@ -208,7 +209,7 @@ namespace Easy
|
||||||
* @param json JSON string holding the array
|
* @param json JSON string holding the array
|
||||||
*
|
*
|
||||||
* @return vector of strings or an empty vector on error
|
* @return vector of strings or an empty vector on error
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
const std::vector<string> json_array_to_vector(const string &json);
|
const std::vector<string> json_array_to_vector(const string &json);
|
||||||
|
@ -219,106 +220,112 @@ namespace Easy
|
||||||
* @param streamdata Data from get_stream()
|
* @param streamdata Data from get_stream()
|
||||||
*
|
*
|
||||||
* @return vector of stream events
|
* @return vector of stream events
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
const std::vector<stream_event>
|
const std::vector<stream_event> parse_stream(const std::string &streamdata);
|
||||||
parse_stream(const std::string &streamdata);
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Interface to the Mastodon API, easy version.
|
||||||
|
*
|
||||||
|
* Provides convenient functions to deal with the responses you get.
|
||||||
|
*/
|
||||||
class API : public Mastodon::API
|
class API : public Mastodon::API
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/*!
|
/*!
|
||||||
* @brief Constructs a new Easy object.
|
* @brief Constructs a new Easy 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 The access token
|
* @param access_token The access token
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
explicit API(const string &instance, const string &access_token);
|
explicit API(const string &instance, const string &access_token);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Gets the links from the last answer
|
* @brief Gets the links from the last answer
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
const Link get_link() const;
|
const Link get_link() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Converts a time_point to a string
|
* @brief Converts a time_point to a string
|
||||||
*
|
*
|
||||||
* The return value can not exceed 1023 chars.
|
* The return value can not exceed 1023 chars.
|
||||||
*
|
*
|
||||||
* @param timepoint The timepoint
|
* @param timepoint The timepoint
|
||||||
* @param format The format of the string, same as with `strftime`.
|
* @param format The format of the string, same as with
|
||||||
*
|
* `strftime`.
|
||||||
* Example:
|
*
|
||||||
* @code
|
* Example:
|
||||||
* auto timepoint = status.created_at();
|
* @code
|
||||||
* cout << Easy::strtime_utc(timepoint, "%F, %T") << '\n';
|
* auto timepoint = status.created_at();
|
||||||
* @endcode
|
* cout << Easy::strtime_utc(timepoint, "%F, %T") << '\n';
|
||||||
*
|
* @endcode
|
||||||
* @return The UTC time as string
|
*
|
||||||
*
|
* @return The UTC time as string
|
||||||
* @since 0.11.0
|
*
|
||||||
*/
|
* @since 0.11.0
|
||||||
|
*/
|
||||||
// TODO: Time type, convertible to time_point, str_utc and str_local.
|
// TODO: Time type, convertible to time_point, str_utc and str_local.
|
||||||
static const string strtime_utc(const system_clock::time_point &timepoint,
|
static const string strtime_utc(const system_clock::time_point &timepoint,
|
||||||
const string &format);
|
const string &format);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief See strtime_utc
|
* @brief See strtime_utc
|
||||||
*
|
*
|
||||||
* @return The local time as string
|
* @return The local time as string
|
||||||
*
|
*
|
||||||
* @since 0.11.0
|
* @since 0.11.0
|
||||||
*/
|
*/
|
||||||
static const string strtime_local(const system_clock::time_point &timepoint,
|
static const string strtime_local(const system_clock::time_point &timepoint,
|
||||||
const string &format);
|
const string &format);
|
||||||
|
|
||||||
// #### simple calls ####
|
// #### simple calls ####
|
||||||
|
// TODO: Own file.
|
||||||
/*!
|
|
||||||
* @brief Sends a toot.
|
|
||||||
*
|
|
||||||
* @param status The status to send
|
|
||||||
* @param error @ref error "Error code"
|
|
||||||
*
|
|
||||||
* @return The new Easy::Status
|
|
||||||
*
|
|
||||||
* @since 0.18.1
|
|
||||||
*/
|
|
||||||
const return_entity<Easy::Status> send_post(const Status &status);
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Alias for send_post()
|
* @brief Sends a post.
|
||||||
*
|
*
|
||||||
* @since 0.17.0
|
* @param status The status to send
|
||||||
*/
|
* @param error @ref error "Error code"
|
||||||
const return_entity<Easy::Status> send_toot(const Status &status);
|
*
|
||||||
|
* @return The new Easy::Status
|
||||||
|
*
|
||||||
|
* @since 0.18.1
|
||||||
|
*/
|
||||||
|
const return_entity<Easy::Status> send_post(const Status &status);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Gets notifications.
|
* @brief Alias for send_post()
|
||||||
*
|
*
|
||||||
* @param error @ref error "Error code"
|
* @since 0.17.0
|
||||||
* @param limit Maximum number of notifications
|
*/
|
||||||
* @param since_id Return notifications newer than ID
|
const return_entity<Easy::Status> send_toot(const Status &status);
|
||||||
* @param max_id Return notifications older than ID
|
|
||||||
*
|
|
||||||
* @return vector of Easy::Notification.
|
|
||||||
*
|
|
||||||
* @since 0.21.0
|
|
||||||
*/
|
|
||||||
const return_entity_vector<Easy::Notification> get_notifications(
|
|
||||||
const uint16_t limit = 20, const string since_id = "",
|
|
||||||
const string max_id = "");
|
|
||||||
|
|
||||||
protected:
|
/*!
|
||||||
inline static const string strtime
|
* @brief Gets notifications.
|
||||||
|
*
|
||||||
|
* @param error @ref error "Error code"
|
||||||
|
* @param limit Maximum number of notifications
|
||||||
|
* @param since_id Return notifications newer than ID
|
||||||
|
* @param max_id Return notifications older than ID
|
||||||
|
*
|
||||||
|
* @return vector of Easy::Notification.
|
||||||
|
*
|
||||||
|
* @since 0.21.0
|
||||||
|
*/
|
||||||
|
const return_entity_vector<Easy::Notification> get_notifications(
|
||||||
|
const uint16_t limit = 20, const string since_id = "",
|
||||||
|
const string max_id = "");
|
||||||
|
|
||||||
|
protected:
|
||||||
|
inline static const string strtime
|
||||||
(const system_clock::time_point &timepoint,
|
(const system_clock::time_point &timepoint,
|
||||||
const string &format, const bool &utc);
|
const string &format, const bool &utc);
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,209 +28,209 @@ namespace Mastodon
|
||||||
{
|
{
|
||||||
namespace Easy
|
namespace Easy
|
||||||
{
|
{
|
||||||
/*!
|
|
||||||
* @brief Base class for all entities.
|
|
||||||
*
|
|
||||||
* @since before 0.11.0
|
|
||||||
*/
|
|
||||||
class Entity
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Constructs an Entity object from a JSON string.
|
* @brief Base class for all entities.
|
||||||
*
|
*
|
||||||
* @param json JSON string
|
|
||||||
*
|
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
explicit Entity(const string &json);
|
class Entity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*!
|
||||||
|
* @brief Constructs an Entity object from a JSON string.
|
||||||
|
*
|
||||||
|
* @param json JSON string
|
||||||
|
*
|
||||||
|
* @since before 0.11.0
|
||||||
|
*/
|
||||||
|
explicit Entity(const string &json);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Constructs an Entity object from a JSON object.
|
* @brief Constructs an Entity object from a JSON object.
|
||||||
*
|
*
|
||||||
* @param object JSON object
|
* @param object JSON object
|
||||||
*
|
*
|
||||||
* @since 0.100.0
|
* @since 0.100.0
|
||||||
*/
|
*/
|
||||||
explicit Entity(const Json::Value &object);
|
explicit Entity(const Json::Value &object);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Constructs an empty Entity object.
|
* @brief Constructs an empty Entity object.
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
Entity();
|
Entity();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Destroys the object.
|
* @brief Destroys the object.
|
||||||
*
|
*
|
||||||
* @since 0.100.0
|
* @since 0.100.0
|
||||||
*/
|
*/
|
||||||
virtual ~Entity();
|
virtual ~Entity();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Returns the JSON object of the Entity
|
* Returns the JSON object of the Entity
|
||||||
*
|
*
|
||||||
* @since 0.100.0
|
* @since 0.100.0
|
||||||
*/
|
*/
|
||||||
operator const Json::Value() const;
|
operator const Json::Value() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Replaces the Entity with a new one from a JSON string.
|
* @brief Replaces the Entity with a new one from a JSON string.
|
||||||
*
|
*
|
||||||
* @param json JSON string
|
* @param json JSON string
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
void from_string(const string &json);
|
void from_string(const string &json);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns the JSON object of the Entity
|
* @brief Returns the JSON object of the Entity
|
||||||
*
|
*
|
||||||
* @return JSON object
|
* @return JSON object
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
const string to_string() const;
|
const string to_string() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Replaces the Entity with a new one from a JSON object.
|
* @brief Replaces the Entity with a new one from a JSON object.
|
||||||
*
|
*
|
||||||
* @param object JSON object
|
* @param object JSON object
|
||||||
*
|
*
|
||||||
* @since 0.100.0
|
* @since 0.100.0
|
||||||
*/
|
*/
|
||||||
void from_object(const Json::Value &object);
|
void from_object(const Json::Value &object);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns the JSON object of the Entity
|
* @brief Returns the JSON object of the Entity
|
||||||
*
|
*
|
||||||
* @return JSON object
|
* @return JSON object
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
const Json::Value to_object() const;
|
const Json::Value to_object() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns true if the Entity holds valid data
|
* @brief Returns true if the Entity holds valid data
|
||||||
*
|
*
|
||||||
* @since before 0.11.0 (virtual since 0.18.2)
|
* @since before 0.11.0 (virtual since 0.18.2)
|
||||||
*/
|
*/
|
||||||
virtual bool valid() const = 0;
|
virtual bool valid() const = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns error string sent by the server
|
* @brief Returns error string sent by the server
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
const string error() const;
|
const string error() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns true if the last requested value was set, false if
|
* @brief Returns true if the last requested value was set, false if
|
||||||
* it was unset.
|
* it was unset.
|
||||||
*
|
*
|
||||||
* Members of Easy::Entity-derived classes return a default
|
* Members of Easy::Entity-derived classes return a default
|
||||||
* value depending on its type when the requested value is not
|
* value depending on its type when the requested value is not
|
||||||
* found in the JSON. "" for strings, false for bools and so
|
* found in the JSON. "" for strings, false for bools and so
|
||||||
* on. Most of the time this is no problem, but sometimes you
|
* on. Most of the time this is no problem, but sometimes you
|
||||||
* need to know for sure.
|
* need to know for sure.
|
||||||
*
|
*
|
||||||
* Example:
|
* Example:
|
||||||
* @code
|
* @code
|
||||||
* Easy::Account a(jsonstring);
|
* Easy::Account a(jsonstring);
|
||||||
* if (a.note().empty())
|
* if (a.note().empty())
|
||||||
* {
|
* {
|
||||||
* if (a.was_set())
|
* if (a.was_set())
|
||||||
* {
|
* {
|
||||||
* cout << "Account has an empty description.\n";
|
* cout << "Account has an empty description.\n";
|
||||||
* }
|
* }
|
||||||
* else
|
* else
|
||||||
* {
|
* {
|
||||||
* cout << "Account has no description.\n";
|
* cout << "Account has no description.\n";
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
bool was_set() const;
|
bool was_set() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns the value of key as Json::Value
|
* @brief Returns the value of key as Json::Value
|
||||||
*
|
*
|
||||||
* Returns an empty object if the value does not exist or is
|
* Returns an empty object if the value does not exist or is
|
||||||
* null.
|
* null.
|
||||||
*/
|
*/
|
||||||
const Json::Value get(const string &key) const;
|
const Json::Value get(const string &key) const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns the value of key as std::string
|
* @brief Returns the value of key as std::string
|
||||||
*
|
*
|
||||||
* returns "" if the value does not exist or is null.
|
* returns "" if the value does not exist or is null.
|
||||||
*/
|
*/
|
||||||
const string get_string(const string &key) const;
|
const string get_string(const string &key) const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns the value of key as std::uint64_t
|
* @brief Returns the value of key as std::uint64_t
|
||||||
*
|
*
|
||||||
* Returns 0 if the value does not exist or is null.
|
* Returns 0 if the value does not exist or is null.
|
||||||
*/
|
*/
|
||||||
uint64_t get_uint64(const string &key) const;
|
uint64_t get_uint64(const string &key) const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns the value of key as double
|
* @brief Returns the value of key as double
|
||||||
*
|
*
|
||||||
* Returns 0.0 if the value does not exist or is null.
|
* Returns 0.0 if the value does not exist or is null.
|
||||||
*/
|
*/
|
||||||
double get_double(const string &key) const;
|
double get_double(const string &key) const;
|
||||||
|
|
||||||
// TODO: Maybe an enum would be better?
|
// TODO: Maybe an enum would be better?
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns the value of key as bool
|
* @brief Returns the value of key as bool
|
||||||
*
|
*
|
||||||
* Returns false if the value does not exist or is null.
|
* Returns false if the value does not exist or is null.
|
||||||
*/
|
*/
|
||||||
bool get_bool(const string &key) const;
|
bool get_bool(const string &key) const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns the value of key as time_point
|
* @brief Returns the value of key as time_point
|
||||||
*
|
*
|
||||||
* Returns clocks epoch if the value does not exist or is null.
|
* Returns clocks epoch if the value does not exist or is null.
|
||||||
*/
|
*/
|
||||||
const system_clock::time_point get_time_point(const string &key) const;
|
const system_clock::time_point get_time_point(const string &key) const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns the value of key as vector
|
* @brief Returns the value of key as vector
|
||||||
*
|
*
|
||||||
* Returns an empty vector if the value does not exist or is
|
* Returns an empty vector if the value does not exist or is
|
||||||
* null.
|
* null.
|
||||||
*/
|
*/
|
||||||
const std::vector<string> get_vector(const string &key) const;
|
const std::vector<string> get_vector(const string &key) const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Sets the value of key
|
* @brief Sets the value of key
|
||||||
*
|
*
|
||||||
* @since 0.17.0
|
* @since 0.17.0
|
||||||
*/
|
*/
|
||||||
void set(const string &key, const Json::Value &value);
|
void set(const string &key, const Json::Value &value);
|
||||||
|
|
||||||
std::uint64_t stouint64(const string &str) const;
|
std::uint64_t stouint64(const string &str) const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Checks if an Entity is valid
|
* @brief Checks if an Entity is valid
|
||||||
*
|
*
|
||||||
* @param attributes The attributes to check
|
* @param attributes The attributes to check
|
||||||
*
|
*
|
||||||
* @return true if all attributes are set
|
* @return true if all attributes are set
|
||||||
*
|
*
|
||||||
* @since 0.18.2
|
* @since 0.18.2
|
||||||
*/
|
*/
|
||||||
bool check_valid(const std::vector<string> &attributes) const;
|
bool check_valid(const std::vector<string> &attributes) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Json::Value _tree;
|
Json::Value _tree;
|
||||||
mutable bool _was_set;
|
mutable bool _was_set;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
/* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "return_types_easy.hpp"
|
||||||
|
#include "easy/entities/status.hpp"
|
||||||
|
#include "easy/entities/notification.hpp"
|
||||||
|
|
||||||
|
using namespace Mastodon;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Easy::return_entity<T>::return_entity()
|
||||||
|
: entity()
|
||||||
|
{}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Easy::return_entity<T>::return_entity(const uint8_t ec, const string &em,
|
||||||
|
const T &ent)
|
||||||
|
: entity(ent)
|
||||||
|
{
|
||||||
|
error_code = ec;
|
||||||
|
error_message = em;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Easy::return_entity<T>::return_entity::operator const T() const
|
||||||
|
{
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Easy::return_entity<T>::return_entity::operator const string() const
|
||||||
|
{
|
||||||
|
return entity.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::ostream &Easy::operator <<(std::ostream &out,
|
||||||
|
const Easy::return_entity<T> &ret)
|
||||||
|
{
|
||||||
|
out << ret.entity.to_string();
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Explicit instantiations, so it can be used from outside.
|
||||||
|
// TODO: Complete this.
|
||||||
|
template struct Easy::return_entity<Easy::Status>;
|
||||||
|
template struct Easy::return_entity<Easy::Notification>;
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Easy::return_entity_vector<T>::
|
||||||
|
return_entity_vector::return_entity_vector()
|
||||||
|
: entities()
|
||||||
|
{}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Easy::return_entity_vector<T>::return_entity_vector::return_entity_vector(
|
||||||
|
const uint8_t ec, const string &em, const vector<T> &vec)
|
||||||
|
: entities(vec)
|
||||||
|
{
|
||||||
|
error_code = ec;
|
||||||
|
error_message = em;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Easy::return_entity_vector<T>::return_entity_vector::operator const vector<T>()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return entities;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Explicit instantiations, so it can be used from outside.
|
||||||
|
// TODO: Complete this.
|
||||||
|
template struct Easy::return_entity_vector<Easy::Status>;
|
||||||
|
template struct Easy::return_entity_vector<Easy::Notification>;
|
|
@ -20,101 +20,55 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
#include <cstdint>
|
||||||
#include "mastodon-cpp.hpp"
|
#include "mastodon-cpp.hpp"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
using std::uint8_t;
|
||||||
|
|
||||||
namespace Mastodon
|
namespace Mastodon
|
||||||
{
|
{
|
||||||
template <typename T>
|
namespace Easy
|
||||||
struct return_entity;
|
|
||||||
// https://stackoverflow.com/a/4661372/5965450
|
|
||||||
template <typename T>
|
|
||||||
std::ostream &operator <<(std::ostream&, const return_entity<T>&);
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct return_entity : return_base
|
|
||||||
{
|
{
|
||||||
T entity;
|
template <typename T>
|
||||||
|
struct return_entity;
|
||||||
|
template <typename T> // https://stackoverflow.com/a/4661372/5965450
|
||||||
|
std::ostream &operator <<(std::ostream&, const return_entity<T>&);
|
||||||
|
|
||||||
return_entity();
|
/*!
|
||||||
return_entity(const uint8_t ec, const string &em, const T &ent);
|
* @brief Return types for calls that return a single `Easy::Entity`.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
struct return_entity : return_base
|
||||||
|
{
|
||||||
|
T entity;
|
||||||
|
|
||||||
operator const T() const;
|
return_entity();
|
||||||
operator const string() const;
|
return_entity(const uint8_t ec, const string &em, const T &ent);
|
||||||
|
|
||||||
friend std::ostream &operator <<<T>(std::ostream &out,
|
operator const T() const;
|
||||||
const return_entity<T> &ret);
|
operator const string() const;
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
// FIXME: Can't get it to work, don't know why.
|
||||||
struct return_entity_vector : return_base
|
friend std::ostream &operator <<<T>(std::ostream &out,
|
||||||
{
|
const return_entity<T> &ret);
|
||||||
vector<T> entities;
|
};
|
||||||
|
|
||||||
return_entity_vector();
|
/*!
|
||||||
return_entity_vector(const uint8_t ec, const string &em,
|
* @brief Return types for calls that return multiple `Easy::Entity`s.
|
||||||
const vector<T> &vec);
|
*/
|
||||||
|
template <typename T>
|
||||||
|
struct return_entity_vector : return_base
|
||||||
|
{
|
||||||
|
vector<T> entities;
|
||||||
|
|
||||||
operator const vector<T>() const;
|
return_entity_vector();
|
||||||
};
|
return_entity_vector(const uint8_t ec, const string &em,
|
||||||
|
const vector<T> &vec);
|
||||||
|
|
||||||
|
operator const vector<T>() const;
|
||||||
template<typename T>
|
};
|
||||||
return_entity<T>::return_entity()
|
|
||||||
: entity()
|
|
||||||
{}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
return_entity<T>::return_entity(const uint8_t ec, const string &em,
|
|
||||||
const T &ent)
|
|
||||||
: entity(ent)
|
|
||||||
{
|
|
||||||
error_code = ec;
|
|
||||||
error_message = em;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
return_entity<T>::return_entity::operator const T() const
|
|
||||||
{
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
return_entity<T>::return_entity::operator const string() const
|
|
||||||
{
|
|
||||||
return entity.to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
std::ostream &operator <<(std::ostream &out, const return_entity<T> &ret)
|
|
||||||
{
|
|
||||||
out << ret.entity.to_string();
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Explicit instantiation
|
|
||||||
// template struct Mastodon::return_entity<Easy::Status>;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
return_entity_vector<T>::return_entity_vector::return_entity_vector()
|
|
||||||
: entities()
|
|
||||||
{}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
return_entity_vector<T>::return_entity_vector::return_entity_vector(
|
|
||||||
const uint8_t ec, const string &em, const vector<T> &vec)
|
|
||||||
: entities(vec)
|
|
||||||
{
|
|
||||||
error_code = ec;
|
|
||||||
error_message = em;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
return_entity_vector<T>::return_entity_vector::operator const vector<T>() const
|
|
||||||
{
|
|
||||||
return entities;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,14 +21,14 @@
|
||||||
#include "easy/entities/attachment.hpp"
|
#include "easy/entities/attachment.hpp"
|
||||||
#include "easy/entities/notification.hpp"
|
#include "easy/entities/notification.hpp"
|
||||||
|
|
||||||
using namespace Mastodon;
|
using namespace Mastodon::Easy;
|
||||||
|
|
||||||
const return_entity<Easy::Status> Easy::API::send_toot(const Status &status)
|
const return_entity<Status> API::send_toot(const Status &status)
|
||||||
{
|
{
|
||||||
return send_post(status);
|
return send_post(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
const return_entity<Easy::Status> Easy::API::send_post(const Status &status)
|
const return_entity<Status> API::send_post(const Status &status)
|
||||||
{
|
{
|
||||||
API::parametermap parameters;
|
API::parametermap parameters;
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ const return_entity<Easy::Status> Easy::API::send_post(const Status &status)
|
||||||
return { ret.error_code, ret.error_message, Status(ret.answer) };
|
return { ret.error_code, ret.error_message, Status(ret.answer) };
|
||||||
}
|
}
|
||||||
|
|
||||||
const return_entity_vector<Easy::Notification> Easy::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;
|
API::parametermap parameters;
|
||||||
|
|
|
@ -70,7 +70,7 @@ namespace Mastodon
|
||||||
} return_call;
|
} return_call;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Class for 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
|
||||||
* base64-encoded or a filename.
|
* base64-encoded or a filename.
|
||||||
|
|
Reference in New Issue