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

202 lines
4.8 KiB
C++
Raw Normal View History

2018-03-21 16:45:52 +01:00
/* This file is part of mastodon-cpp.
* Copyright © 2018 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_EASY_CPP_HPP
#define MASTODON_EASY_CPP_HPP
#include <string>
2018-03-25 22:46:38 +02:00
#include <cstdint>
#include <chrono>
2018-03-30 20:08:47 +02:00
#include <vector>
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"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
2018-03-21 16:45:52 +01:00
using std::string;
2018-03-25 22:46:38 +02:00
using std::uint64_t;
using std::chrono::system_clock;
2018-03-21 16:45:52 +01:00
namespace Mastodon
{
/*!
* @brief Child of Mastodon::API with abstract methods.
*/
class Easy : public API
{
public:
/*!
* @brief Describes visibility of toots.
*
* The names begin with a capital letter because some of them
* are reserved keywords when written in all-lowercase.
*/
enum class visibility
{
Direct,
Private,
Unlisted,
Public,
Undefined
};
2018-03-21 20:12:45 +01:00
/*!
* @brief Describes the attachment type
*/
enum class attachment_type
{
image,
video,
gifv,
unknown
};
2018-03-25 19:43:48 +02:00
/*!
* @brief Describes the card type
*/
enum class card_type
{
link,
photo,
video,
rich,
unknown
};
2018-03-30 23:51:09 +02:00
/*!
* @brief Describes the notification type
*/
enum class notification_type
{
mention,
reblog,
favourite,
follow,
unknown
};
2018-03-21 16:45:52 +01:00
/*!
* @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
*/
explicit Easy(const string &instance, const string &access_token);
2018-03-23 00:53:41 +01:00
/*!
* @brief Base class for entities.
*/
2018-03-22 00:33:36 +01:00
class Entity
2018-03-21 16:45:52 +01:00
{
public:
2018-03-25 22:46:38 +02:00
/*!
* @brief Constructs an Entity object from a JSON string.
*
* @param json JSON string
*/
2018-03-30 19:01:09 +02:00
explicit Entity(const string &json);
/*!
* @brief Constructs an empty Entity object.
*/
2018-03-30 20:08:47 +02:00
Entity();
2018-03-21 16:45:52 +01:00
/*!
2018-03-22 00:33:36 +01:00
* @brief Returns true if the Entity holds valid data
2018-03-21 16:45:52 +01:00
*/
const bool valid() const;
2018-03-30 19:01:09 +02:00
/*!
* @brief Returns error string
*/
const string error() const;
2018-03-25 22:46:38 +02:00
/*!
* @brief Returns the value of node as Json::Value
*
* Returns an empty object on error.
*/
const Json::Value get(const string &key) const;
/*!
* @brief Returns the value of node as std::string
*
* returns "" on error.
*/
const string get_string(const string &key) const;
/*!
* @brief Returns the value of node as std::uint64_t
*
* Returns 0 on error.
*/
const uint64_t get_uint64(const string &key) const;
/*!
* @brief Returns the value of node as double
*
* Returns 0.0 on error.
*/
const double get_double(const string &key) const;
// TODO: Investigate if uint8_t would be better
/*!
* @brief Returns the value of node as bool
*
* Returns false on error.
*/
const bool get_bool(const string &key) const;
/*!
* @brief Returns the value of node as time_point
*
* Returns clocks epoch on error.
*/
const system_clock::time_point get_time_point(const string &key) const;
2018-03-30 20:08:47 +02:00
/*!
* @brief Returns the value of node as vector
*
* Returns false on error.
*/
const std::vector<string> get_vector(const string &key) const;
2018-03-22 00:33:36 +01:00
protected:
2018-03-21 16:45:52 +01:00
Json::Value _tree;
bool _valid;
};
2018-03-21 20:12:45 +01:00
2018-03-22 00:33:36 +01:00
class Account;
class Attachment;
class Card;
2018-03-30 18:41:28 +02:00
class Context;
class Emoji;
2018-03-30 19:01:09 +02:00
class Instance;
class List;
2018-03-30 23:51:09 +02:00
class Mention;
class Notification;
2018-03-21 16:45:52 +01:00
};
}
#endif // MASTODON_EASY_CPP_HPP