2018-03-21 16:45: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-03-21 16:45: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_EASY_CPP_HPP
|
|
|
|
#define MASTODON_EASY_CPP_HPP
|
|
|
|
|
|
|
|
#include <string>
|
2018-03-25 22:46:38 +02:00
|
|
|
#include <cstdint>
|
2018-03-30 20:08:47 +02:00
|
|
|
#include <vector>
|
2018-04-03 01:20:15 +02:00
|
|
|
#include <functional>
|
2019-03-02 20:21:31 +01:00
|
|
|
#include <ostream>
|
2018-03-21 16:45:52 +01:00
|
|
|
#include <jsoncpp/json/json.h>
|
2018-03-22 00:33:36 +01:00
|
|
|
|
2018-03-21 20:12:45 +01:00
|
|
|
// If we are compiling mastodon-cpp, use another include path
|
|
|
|
#ifdef MASTODON_CPP
|
|
|
|
#include "mastodon-cpp.hpp"
|
2019-03-29 14:44:39 +01:00
|
|
|
#include "easy/return_types_easy.hpp"
|
2019-04-02 11:16:52 +02:00
|
|
|
#include "easy/types_easy.hpp"
|
2019-03-31 22:24:14 +02:00
|
|
|
#include "easy/entities/notification.hpp"
|
|
|
|
#include "easy/entities/status.hpp"
|
2018-03-21 20:12:45 +01:00
|
|
|
#else
|
|
|
|
#include <mastodon-cpp/mastodon-cpp.hpp>
|
2019-03-29 14:44:39 +01:00
|
|
|
#include <mastodon-cpp/easy/return_types_easy.hpp>
|
2019-04-02 11:16:52 +02:00
|
|
|
#include <mastodon-cpp/easy/types_easy.hpp>
|
2019-03-31 22:24:14 +02:00
|
|
|
#include <mastodon-cpp/easy/entities/notification.hpp>
|
|
|
|
#include <mastodon-cpp/easy/entities/status.hpp>
|
2018-03-21 20:12:45 +01:00
|
|
|
#endif
|
2018-03-21 16:45:52 +01:00
|
|
|
|
|
|
|
using std::string;
|
2019-01-26 06:54:47 +01:00
|
|
|
using std::vector;
|
2019-02-22 08:29:54 +01:00
|
|
|
using std::uint64_t;
|
|
|
|
using std::uint16_t;
|
2018-03-21 16:45:52 +01:00
|
|
|
|
|
|
|
namespace Mastodon
|
|
|
|
{
|
|
|
|
/*!
|
2019-04-13 21:50:20 +02:00
|
|
|
* @brief Collection of things that make it easier to interface with server
|
|
|
|
* software that implements the Mastodon API.
|
2018-03-21 16:45:52 +01:00
|
|
|
*/
|
2019-03-28 15:30:56 +01:00
|
|
|
namespace Easy
|
2018-03-21 16:45:52 +01:00
|
|
|
{
|
2018-04-03 00:04:47 +02:00
|
|
|
/*!
|
|
|
|
* @brief Class to hold the `Link`-header.
|
2019-03-28 21:23:24 +01:00
|
|
|
*
|
2018-04-03 01:20:15 +02:00
|
|
|
* Extracts max_id and since_id from the `Link`-header
|
2019-03-28 21:23:24 +01:00
|
|
|
*
|
2018-06-14 11:17:26 +02:00
|
|
|
* @since before 0.11.0
|
2018-04-03 00:04:47 +02:00
|
|
|
*/
|
2019-03-28 15:30:56 +01:00
|
|
|
// TODO: Convert to struct?
|
2018-04-03 00:04:47 +02:00
|
|
|
class Link
|
|
|
|
{
|
|
|
|
public:
|
2018-04-04 04:38:04 +02:00
|
|
|
/*!
|
|
|
|
* @param link_header The content of the `Link` header
|
2019-03-28 21:23:24 +01:00
|
|
|
*
|
2018-06-14 11:17:26 +02:00
|
|
|
* @since before 0.11.0
|
2018-04-04 04:38:04 +02:00
|
|
|
*/
|
2018-04-03 00:04:47 +02:00
|
|
|
explicit Link(const string &link_header);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Returns max_id
|
2019-03-28 21:23:24 +01:00
|
|
|
*
|
2018-06-14 11:17:26 +02:00
|
|
|
* @since before 0.11.0
|
2018-04-03 00:04:47 +02:00
|
|
|
*/
|
2019-01-27 03:50:28 +01:00
|
|
|
const string next() const;
|
2018-04-03 00:04:47 +02:00
|
|
|
|
2018-04-03 01:20:15 +02:00
|
|
|
/*!
|
|
|
|
* @brief Returns max_id
|
2019-03-28 21:23:24 +01:00
|
|
|
*
|
2018-06-14 11:17:26 +02:00
|
|
|
* @since before 0.11.0
|
2018-04-03 01:20:15 +02:00
|
|
|
*/
|
2019-01-27 03:50:28 +01:00
|
|
|
const string max_id() const;
|
2018-04-03 01:20:15 +02:00
|
|
|
|
2018-04-03 00:04:47 +02:00
|
|
|
/*!
|
|
|
|
* @brief Returns since_id
|
2019-03-28 21:23:24 +01:00
|
|
|
*
|
2018-06-14 11:17:26 +02:00
|
|
|
* @since before 0.11.0
|
2018-04-03 00:04:47 +02:00
|
|
|
*/
|
2019-01-27 03:50:28 +01:00
|
|
|
const string prev() const;
|
2018-04-03 00:04:47 +02:00
|
|
|
|
2018-04-03 01:20:15 +02:00
|
|
|
/*!
|
|
|
|
* @brief Returns since_id
|
2019-03-28 21:23:24 +01:00
|
|
|
*
|
2018-06-14 11:17:26 +02:00
|
|
|
* @since before 0.11.0
|
2018-04-03 01:20:15 +02:00
|
|
|
*/
|
2019-01-27 03:50:28 +01:00
|
|
|
const string since_id() const;
|
2018-04-03 01:20:15 +02:00
|
|
|
|
2018-04-03 00:04:47 +02:00
|
|
|
private:
|
2019-01-27 03:50:28 +01:00
|
|
|
string _next;
|
|
|
|
string _prev;
|
2018-04-03 00:04:47 +02:00
|
|
|
};
|
|
|
|
|
2018-03-31 20:03:31 +02:00
|
|
|
/*!
|
2018-04-01 02:20:10 +02:00
|
|
|
* @brief Turns a JSON array into a vector of strings
|
2018-03-31 20:03:31 +02:00
|
|
|
*
|
|
|
|
* @param json JSON string holding the array
|
|
|
|
*
|
|
|
|
* @return vector of strings or an empty vector on error
|
2019-03-28 21:23:24 +01:00
|
|
|
*
|
2018-06-14 11:17:26 +02:00
|
|
|
* @since before 0.11.0
|
2018-03-31 20:03:31 +02:00
|
|
|
*/
|
2019-03-28 15:30:56 +01:00
|
|
|
const std::vector<string> json_array_to_vector(const string &json);
|
2018-03-31 20:03:31 +02:00
|
|
|
|
2018-04-01 03:08:22 +02:00
|
|
|
/*!
|
|
|
|
* @brief Split stream into a vector of events
|
|
|
|
*
|
|
|
|
* @param streamdata Data from get_stream()
|
|
|
|
*
|
2019-04-13 21:04:59 +02:00
|
|
|
* @return vector of Easy::stream_event
|
2019-03-28 21:23:24 +01:00
|
|
|
*
|
2018-06-14 11:17:26 +02:00
|
|
|
* @since before 0.11.0
|
2018-04-01 03:08:22 +02:00
|
|
|
*/
|
2019-03-28 21:23:24 +01:00
|
|
|
const std::vector<stream_event> parse_stream(const std::string &streamdata);
|
2018-04-01 03:08:22 +02:00
|
|
|
|
2019-03-28 15:30:56 +01:00
|
|
|
/*!
|
2019-04-13 21:50:20 +02:00
|
|
|
* @brief Child of Mastodon::API with abstract methods.
|
2019-03-28 15:30:56 +01:00
|
|
|
*
|
2019-03-28 21:23:24 +01:00
|
|
|
* Provides convenient functions to deal with the responses you get.
|
2019-03-28 15:30:56 +01:00
|
|
|
*/
|
2019-03-28 21:23:24 +01:00
|
|
|
class API : public Mastodon::API
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/*!
|
|
|
|
* @brief Constructs a new Easy object.
|
|
|
|
*
|
|
|
|
* 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 The access token
|
|
|
|
*
|
2019-04-10 20:52:36 +02:00
|
|
|
* @since 0.100.0
|
2019-03-28 21:23:24 +01:00
|
|
|
*/
|
|
|
|
explicit API(const string &instance, const string &access_token);
|
2019-03-28 15:30:56 +01:00
|
|
|
|
2019-03-28 21:23:24 +01:00
|
|
|
/*!
|
|
|
|
* @brief Gets the links from the last answer
|
|
|
|
*
|
2019-04-10 20:52:36 +02:00
|
|
|
* @since 0.100.0
|
2019-03-28 21:23:24 +01:00
|
|
|
*/
|
|
|
|
const Link get_link() const;
|
2018-04-03 00:04:47 +02:00
|
|
|
|
2019-03-28 21:23:24 +01:00
|
|
|
/*!
|
|
|
|
* @brief Sends a post.
|
|
|
|
*
|
|
|
|
* @param status The status to send
|
|
|
|
*
|
|
|
|
* @return The new Easy::Status
|
|
|
|
*
|
2019-04-10 20:52:36 +02:00
|
|
|
* @since 0.100.0
|
2019-03-28 21:23:24 +01:00
|
|
|
*/
|
|
|
|
const return_entity<Easy::Status> send_post(const Status &status);
|
2018-06-14 04:11:28 +02:00
|
|
|
|
2019-03-28 21:23:24 +01:00
|
|
|
/*!
|
|
|
|
* @brief Alias for send_post()
|
|
|
|
*
|
2019-04-10 20:52:36 +02:00
|
|
|
* @since 0.100.0
|
2019-03-28 21:23:24 +01:00
|
|
|
*/
|
|
|
|
const return_entity<Easy::Status> send_toot(const Status &status);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Gets notifications.
|
|
|
|
*
|
|
|
|
* @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.
|
|
|
|
*
|
2019-04-10 20:52:36 +02:00
|
|
|
* @since 0.100.0
|
2019-03-28 21:23:24 +01:00
|
|
|
*/
|
|
|
|
const return_entity_vector<Easy::Notification> get_notifications(
|
|
|
|
const uint16_t limit = 20, const string since_id = "",
|
|
|
|
const string max_id = "");
|
2019-03-29 14:44:39 +01:00
|
|
|
};
|
2019-03-28 15:30:56 +01:00
|
|
|
}
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MASTODON_EASY_CPP_HPP
|