This repository has been archived on 2020-05-10. You can view files and clone it, but cannot push or open issues or pull requests.
mastodon-cpp/src/easy/easy.hpp

193 lines
5.1 KiB
C++
Raw Normal View History

2018-03-21 16:45:52 +01:00
/* This file is part of mastodon-cpp.
* 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>
#include <functional>
#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"
#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>
#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;
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
*/
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.
*
* Extracts max_id and since_id from the `Link`-header
*
* @since before 0.11.0
2018-04-03 00:04:47 +02: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
*
* @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
*
* @since before 0.11.0
2018-04-03 00:04:47 +02:00
*/
const string next() const;
2018-04-03 00:04:47 +02:00
/*!
* @brief Returns max_id
*
* @since before 0.11.0
*/
const string max_id() const;
2018-04-03 00:04:47 +02:00
/*!
* @brief Returns since_id
*
* @since before 0.11.0
2018-04-03 00:04:47 +02:00
*/
const string prev() const;
2018-04-03 00:04:47 +02:00
/*!
* @brief Returns since_id
*
* @since before 0.11.0
*/
const string since_id() const;
2018-04-03 00:04:47 +02:00
private:
string _next;
string _prev;
2018-04-03 00:04:47 +02:00
};
/*!
2018-04-01 02:20:10 +02:00
* @brief Turns a JSON array into a vector of strings
*
* @param json JSON string holding the array
*
* @return vector of strings or an empty vector on error
*
* @since before 0.11.0
*/
const std::vector<string> json_array_to_vector(const string &json);
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
*
* @since before 0.11.0
2018-04-01 03:08:22 +02:00
*/
const std::vector<stream_event> parse_stream(const std::string &streamdata);
2018-04-01 03:08:22 +02:00
/*!
2019-04-13 21:50:20 +02:00
* @brief Child of Mastodon::API with abstract methods.
*
* Provides convenient functions to deal with the responses you get.
*/
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
*
* @since 0.100.0
*/
explicit API(const string &instance, const string &access_token);
/*!
* @brief Gets the links from the last answer
*
* @since 0.100.0
*/
const Link get_link() const;
2018-04-03 00:04:47 +02:00
/*!
* @brief Sends a post.
*
* @param status The status to send
*
* @return The new Easy::Status
*
* @since 0.100.0
*/
const return_entity<Easy::Status> send_post(const Status &status);
2018-06-14 04:11:28 +02:00
/*!
* @brief Alias for send_post()
*
* @since 0.100.0
*/
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.
*
* @since 0.100.0
*/
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
};
}
2018-03-21 16:45:52 +01:00
}
#endif // MASTODON_EASY_CPP_HPP