Added Easy::PushSubscription
This commit is contained in:
parent
a0435e37d3
commit
d7043c06a6
@ -1,6 +1,6 @@
|
||||
cmake_minimum_required (VERSION 3.7)
|
||||
project (mastodon-cpp
|
||||
VERSION 0.13.2
|
||||
VERSION 0.13.3
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "easy/entities/results.hpp"
|
||||
#include "easy/entities/status.hpp"
|
||||
#include "easy/entities/tag.hpp"
|
||||
#include "easy/entities/pushsubscription.hpp"
|
||||
#else
|
||||
#include <mastodon-cpp/easy/easy.hpp>
|
||||
#include <mastodon-cpp/easy/entities/account.hpp>
|
||||
@ -52,6 +53,7 @@
|
||||
#include <mastodon-cpp/easy/entities/results.hpp>
|
||||
#include <mastodon-cpp/easy/entities/status.hpp>
|
||||
#include <mastodon-cpp/easy/entities/tag.hpp>
|
||||
#include <mastodon-cpp/easy/entities/pushsubscription.hpp>
|
||||
#endif
|
||||
|
||||
#endif // MASTODON_CPP_EASY_ALL_HPP
|
||||
|
@ -108,6 +108,13 @@ public:
|
||||
*/
|
||||
typedef std::pair<event_type, string> stream_event;
|
||||
|
||||
/*!
|
||||
* @brief Map of 'notification type' and 'push is requested or not'
|
||||
*
|
||||
* Used in PushSubscription::alerts().
|
||||
*/
|
||||
typedef std::map<Easy::notification_type, bool> alertmap;
|
||||
|
||||
/*!
|
||||
* @brief Class to hold the `Link`-header.
|
||||
*
|
||||
@ -358,6 +365,7 @@ public:
|
||||
class Results;
|
||||
class Status;
|
||||
class Tag;
|
||||
class PushSubscription;
|
||||
|
||||
protected:
|
||||
inline static const string strtime
|
||||
|
89
src/easy/entities/pushsubscription.cpp
Normal file
89
src/easy/entities/pushsubscription.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
#include "pushsubscription.hpp"
|
||||
|
||||
using namespace Mastodon;
|
||||
using PushSubscription = Easy::PushSubscription;
|
||||
|
||||
PushSubscription::PushSubscription(const string &json)
|
||||
: Entity(json)
|
||||
{}
|
||||
|
||||
const uint_fast64_t PushSubscription::id() const
|
||||
{
|
||||
return stouint64(get_string("id"));
|
||||
}
|
||||
|
||||
PushSubscription::PushSubscription()
|
||||
: Entity()
|
||||
{}
|
||||
|
||||
const string PushSubscription::endpoint() const
|
||||
{
|
||||
return get_string("endpoint");
|
||||
}
|
||||
|
||||
const string PushSubscription::server_key() const
|
||||
{
|
||||
return get_string("server_key");
|
||||
}
|
||||
|
||||
const Easy::alertmap PushSubscription::alerts() const
|
||||
{
|
||||
alertmap alerts;
|
||||
const Json::Value node = get("alerts");
|
||||
for (auto it = node.begin(); it != node.end(); ++it)
|
||||
{
|
||||
const string &str = it.name();
|
||||
Easy::notification_type type;
|
||||
if (str.compare("mention") == 0)
|
||||
{
|
||||
type = notification_type::Mention;
|
||||
}
|
||||
else if (str.compare("reblog") == 0)
|
||||
{
|
||||
type = notification_type::Reblog;
|
||||
}
|
||||
else if (str.compare("favourite") == 0)
|
||||
{
|
||||
type = notification_type::Favourite;
|
||||
}
|
||||
else if (str.compare("follow") == 0)
|
||||
{
|
||||
type = notification_type::Follow;
|
||||
}
|
||||
else
|
||||
{
|
||||
type = notification_type::Undefined;
|
||||
}
|
||||
|
||||
alerts.insert({{ type, s_to_b(it->asString()) }});
|
||||
}
|
||||
return alerts;
|
||||
}
|
||||
|
||||
const bool PushSubscription::s_to_b(const string &str) const
|
||||
{
|
||||
if (str.compare("true") == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
88
src/easy/entities/pushsubscription.hpp
Normal file
88
src/easy/entities/pushsubscription.hpp
Normal file
@ -0,0 +1,88 @@
|
||||
/* 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_CPP_EASY_PUSHSUBSCRIPTION_HPP
|
||||
#define MASTODON_CPP_EASY_PUSHSUBSCRIPTION_HPP
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
|
||||
// If we are compiling mastodon-cpp, use another include path
|
||||
#ifdef MASTODON_CPP
|
||||
#include "mastodon-cpp.hpp"
|
||||
#include "easy/easy.hpp"
|
||||
#else
|
||||
#include <mastodon-cpp/mastodon-cpp.hpp>
|
||||
#include <mastodon-cpp/easy/easy.hpp>
|
||||
#endif
|
||||
|
||||
using std::string;
|
||||
using std::uint_fast64_t;
|
||||
|
||||
namespace Mastodon
|
||||
{
|
||||
/*!
|
||||
* @brief Class to hold push subscriptions.
|
||||
*/
|
||||
class Easy::PushSubscription : public Easy::Entity
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* @brief Constructs an PushSubscription object from a JSON string.
|
||||
*
|
||||
* @param json JSON string
|
||||
*/
|
||||
explicit PushSubscription(const string &json);
|
||||
|
||||
/*!
|
||||
* @brief Constructs an empty PushSubscription object.
|
||||
*/
|
||||
PushSubscription();
|
||||
|
||||
/*!
|
||||
* @brief Returns push subscription ID
|
||||
*/
|
||||
const uint_fast64_t id() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the endpoint URL
|
||||
*/
|
||||
const string endpoint() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the server public key for signature verification
|
||||
*/
|
||||
const string server_key() const;
|
||||
|
||||
// TODO: Look up what the data looks like
|
||||
/*!
|
||||
* @brief Returns a map of 'notification event type' and
|
||||
* 'push is requested or not'
|
||||
*/
|
||||
const Easy::alertmap alerts() const;
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* @brief Converts string to bool
|
||||
*
|
||||
* @return `true` if str is equal to "true", `false` otherwise
|
||||
*/
|
||||
const bool s_to_b(const string &str) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // MASTODON_CPP_EASY_PUSHSUBSCRIPTION_HPP
|
@ -69,6 +69,7 @@ const Json::Value Easy::Entity::to_object() const
|
||||
|
||||
Easy::Entity::Entity()
|
||||
: _valid(false)
|
||||
, _was_set(false)
|
||||
{}
|
||||
|
||||
const bool Easy::Entity::valid() const
|
||||
|
Reference in New Issue
Block a user