Added support for /api/v1/filters and /api/v1/filters/:id.
This commit is contained in:
parent
cab52b53a0
commit
2527e9523e
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.6)
|
cmake_minimum_required (VERSION 3.6)
|
||||||
project (mastodon-cpp
|
project (mastodon-cpp
|
||||||
VERSION 0.103.0
|
VERSION 0.104.0
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -270,10 +270,11 @@ Run `make package` from the build directory to generate a tar.gz archive.
|
||||||
* [x] GET /api/v1/favourites
|
* [x] GET /api/v1/favourites
|
||||||
* [x] POST /api/v1/statuses/:id/favourite
|
* [x] POST /api/v1/statuses/:id/favourite
|
||||||
* [x] POST /api/v1/statuses/:id/unfavourite
|
* [x] POST /api/v1/statuses/:id/unfavourite
|
||||||
* [ ] GET /api/v1/filters
|
* [x] GET /api/v1/filters
|
||||||
* [ ] POST /api/v1/filters
|
* [x] POST /api/v1/filters
|
||||||
* [ ] GET /api/v1/filters/:id
|
* [x] GET /api/v1/filters/:id
|
||||||
* [ ] DELETE /api/v1/filters/:id
|
* [x] PUT /api/v1/filters/:id
|
||||||
|
* [x] DELETE /api/v1/filters/:id
|
||||||
* [x] GET /api/v1/follow_requests
|
* [x] GET /api/v1/follow_requests
|
||||||
* [x] POST /api/v1/follow_requests/:id/authorize
|
* [x] POST /api/v1/follow_requests/:id/authorize
|
||||||
* [x] POST /api/v1/follow_requests/:id/reject
|
* [x] POST /api/v1/follow_requests/:id/reject
|
||||||
|
|
|
@ -35,25 +35,41 @@ return_call API::del(const Mastodon::API::v1 &call,
|
||||||
|
|
||||||
switch (call)
|
switch (call)
|
||||||
{
|
{
|
||||||
case v1::domain_blocks:
|
case v1::domain_blocks:
|
||||||
strcall = "/api/v1/domain_blocks";
|
{
|
||||||
break;
|
strcall = "/api/v1/domain_blocks";
|
||||||
case v1::lists_id:
|
break;
|
||||||
strcall = "/api/v1/lists/" + strid;
|
}
|
||||||
break;
|
case v1::lists_id:
|
||||||
case v1::lists_id_accounts:
|
{
|
||||||
strcall = "/api/v1/lists/" + strid + "/accounts";
|
strcall = "/api/v1/lists/" + strid;
|
||||||
break;
|
break;
|
||||||
case v1::statuses_id:
|
}
|
||||||
strcall = "/api/v1/statuses/" + strid;
|
case v1::lists_id_accounts:
|
||||||
break;
|
{
|
||||||
case v1::push_subscription:
|
strcall = "/api/v1/lists/" + strid + "/accounts";
|
||||||
strcall = "/api/v1/push/subscription";
|
break;
|
||||||
break;
|
}
|
||||||
default:
|
case v1::statuses_id:
|
||||||
ttdebug << "ERROR: Invalid argument.\n";
|
{
|
||||||
return { 22, "Invalid argument", 0, "" };
|
strcall = "/api/v1/statuses/" + strid;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
case v1::push_subscription:
|
||||||
|
{
|
||||||
|
strcall = "/api/v1/push/subscription";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case v1::filters_id:
|
||||||
|
{
|
||||||
|
strcall = "/api/v1/filters/" + strid;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
ttdebug << "ERROR: Invalid argument.\n";
|
||||||
|
return { 22, "Invalid argument", 0, "" };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return del(strcall, params);
|
return del(strcall, params);
|
||||||
|
|
|
@ -221,6 +221,16 @@ const return_call API::get(const Mastodon::API::v1 &call,
|
||||||
strcall = "/api/v1/apps/verify_credentials";
|
strcall = "/api/v1/apps/verify_credentials";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case v1::filters:
|
||||||
|
{
|
||||||
|
strcall = "/api/v1/filters";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case v1::filters_id:
|
||||||
|
{
|
||||||
|
strcall = "/api/v1/filters/" + strid;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
ttdebug << "ERROR: Invalid argument.\n";
|
ttdebug << "ERROR: Invalid argument.\n";
|
||||||
|
|
|
@ -190,6 +190,11 @@ return_call API::post(const Mastodon::API::v1 &call,
|
||||||
strcall = "/api/v1/statuses/" + strid + "/unbookmark";
|
strcall = "/api/v1/statuses/" + strid + "/unbookmark";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case v1::filters:
|
||||||
|
{
|
||||||
|
strcall = "/api/v1/filters";
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
ttdebug << "ERROR: Invalid argument.\n";
|
ttdebug << "ERROR: Invalid argument.\n";
|
||||||
|
|
|
@ -35,19 +35,31 @@ return_call API::put(const Mastodon::API::v1 &call,
|
||||||
|
|
||||||
switch (call)
|
switch (call)
|
||||||
{
|
{
|
||||||
case v1::lists_id:
|
case v1::lists_id:
|
||||||
strcall = "/api/v1/lists/" + strid;
|
{
|
||||||
break;
|
strcall = "/api/v1/lists/" + strid;
|
||||||
case v1::media_id:
|
break;
|
||||||
strcall = "/api/v1/media/" + strid;
|
}
|
||||||
break;
|
case v1::media_id:
|
||||||
case v1::push_subscription:
|
{
|
||||||
strcall = "/api/v1/push/subscription";
|
strcall = "/api/v1/media/" + strid;
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
ttdebug << "ERROR: Invalid argument.\n";
|
case v1::push_subscription:
|
||||||
return { 22, "Invalid argument", 0, "" };
|
{
|
||||||
break;
|
strcall = "/api/v1/push/subscription";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case v1::filters_id:
|
||||||
|
{
|
||||||
|
strcall = "/api/v1/filters/" + strid;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
ttdebug << "ERROR: Invalid argument.\n";
|
||||||
|
return { 22, "Invalid argument", 0, "" };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return put(strcall, params);
|
return put(strcall, params);
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include "easy/entities/tag.hpp"
|
#include "easy/entities/tag.hpp"
|
||||||
#include "easy/entities/token.hpp"
|
#include "easy/entities/token.hpp"
|
||||||
#include "easy/entities/pushsubscription.hpp"
|
#include "easy/entities/pushsubscription.hpp"
|
||||||
|
#include "easy/entities/filter.hpp"
|
||||||
#else
|
#else
|
||||||
#include <mastodon-cpp/easy/easy.hpp>
|
#include <mastodon-cpp/easy/easy.hpp>
|
||||||
#include <mastodon-cpp/easy/entities/account.hpp>
|
#include <mastodon-cpp/easy/entities/account.hpp>
|
||||||
|
@ -56,6 +57,7 @@
|
||||||
#include <mastodon-cpp/easy/entities/tag.hpp>
|
#include <mastodon-cpp/easy/entities/tag.hpp>
|
||||||
#include <mastodon-cpp/easy/entities/token.hpp>
|
#include <mastodon-cpp/easy/entities/token.hpp>
|
||||||
#include <mastodon-cpp/easy/entities/pushsubscription.hpp>
|
#include <mastodon-cpp/easy/entities/pushsubscription.hpp>
|
||||||
|
#include <mastodon-cpp/easy/entities/filter.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // MASTODON_CPP_EASY_ALL_HPP
|
#endif // MASTODON_CPP_EASY_ALL_HPP
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
/* 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 <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
#include "filter.hpp"
|
||||||
|
|
||||||
|
using std::vector;
|
||||||
|
using namespace Mastodon;
|
||||||
|
using Filter = Easy::Filter;
|
||||||
|
|
||||||
|
bool Filter::valid() const
|
||||||
|
{
|
||||||
|
return Entity::check_valid({ "id",
|
||||||
|
"phrase",
|
||||||
|
"context",
|
||||||
|
"irreversible",
|
||||||
|
"whole_word" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const string Filter::id() const
|
||||||
|
{
|
||||||
|
return get_string("id");
|
||||||
|
}
|
||||||
|
|
||||||
|
const string Filter::phrase() const
|
||||||
|
{
|
||||||
|
return get_string("phrase");
|
||||||
|
}
|
||||||
|
|
||||||
|
const vector<Easy::context_type> Filter::context() const
|
||||||
|
{
|
||||||
|
const Json::Value node = get("context");
|
||||||
|
if (node.isArray())
|
||||||
|
{
|
||||||
|
vector<Easy::context_type> vec;
|
||||||
|
std::transform(node.begin(), node.end(), std::back_inserter(vec),
|
||||||
|
[](const Json::Value &value)
|
||||||
|
{
|
||||||
|
const string strtype = value.asString();
|
||||||
|
if (strtype == "home")
|
||||||
|
return Easy::context_type::Home;
|
||||||
|
else if (strtype == "notifications")
|
||||||
|
return Easy::context_type::Notifications;
|
||||||
|
else if (strtype == "public")
|
||||||
|
return Easy::context_type::Public;
|
||||||
|
else if (strtype == "thread")
|
||||||
|
return Easy::context_type::Thread;
|
||||||
|
else
|
||||||
|
return context_type::Undefined;
|
||||||
|
});
|
||||||
|
return vec;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const Easy::time Filter::expires_at() const
|
||||||
|
{
|
||||||
|
return get_time("expires_at");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Filter::irreversible() const
|
||||||
|
{
|
||||||
|
return get_bool("irreversible");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Filter::whole_word() const
|
||||||
|
{
|
||||||
|
return get_bool("whole_word");
|
||||||
|
}
|
|
@ -0,0 +1,98 @@
|
||||||
|
/* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MASTODON_CPP_EASY_FILTER_HPP
|
||||||
|
#define MASTODON_CPP_EASY_FILTER_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// If we are compiling mastodon-cpp, use another include path
|
||||||
|
#ifdef MASTODON_CPP
|
||||||
|
#include "mastodon-cpp.hpp"
|
||||||
|
#include "easy/entity.hpp"
|
||||||
|
#else
|
||||||
|
#include <mastodon-cpp/mastodon-cpp.hpp>
|
||||||
|
#include <mastodon-cpp/easy/entity.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
|
||||||
|
namespace Mastodon
|
||||||
|
{
|
||||||
|
namespace Easy
|
||||||
|
{
|
||||||
|
/*!
|
||||||
|
* @brief Class to hold filters.
|
||||||
|
*
|
||||||
|
* @since 0.104.0
|
||||||
|
*/
|
||||||
|
class Filter : public Entity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using Entity::Entity;
|
||||||
|
|
||||||
|
virtual bool valid() const override;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns the id of the filter
|
||||||
|
*
|
||||||
|
* @since 0.104.0
|
||||||
|
*/
|
||||||
|
const string id() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns the phrase to filter.
|
||||||
|
*
|
||||||
|
* @since 0.104.0
|
||||||
|
*/
|
||||||
|
const string phrase() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns the contexts in which to filter.
|
||||||
|
*
|
||||||
|
* @since 0.104.0
|
||||||
|
*/
|
||||||
|
const vector<Easy::context_type> context() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns the expiration time of the filter.
|
||||||
|
*
|
||||||
|
* @since 0.104.0
|
||||||
|
*/
|
||||||
|
const Easy::time expires_at() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns if the phrase should disappear irreversibly.
|
||||||
|
*
|
||||||
|
* If set to true, the filtered posts will be hidden even if filter is
|
||||||
|
* later removed.
|
||||||
|
*
|
||||||
|
* @since 0.104.0
|
||||||
|
*/
|
||||||
|
bool irreversible() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns if the filter should only be applied if it matches
|
||||||
|
* the whole word.
|
||||||
|
*
|
||||||
|
* @since 0.104.0
|
||||||
|
*/
|
||||||
|
bool whole_word() const;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // MASTODON_CPP_EASY_FILTER_HPP
|
|
@ -32,6 +32,7 @@
|
||||||
#include "easy/entities/tag.hpp"
|
#include "easy/entities/tag.hpp"
|
||||||
#include "easy/entities/token.hpp"
|
#include "easy/entities/token.hpp"
|
||||||
#include "easy/entities/pushsubscription.hpp"
|
#include "easy/entities/pushsubscription.hpp"
|
||||||
|
#include "easy/entities/filter.hpp"
|
||||||
|
|
||||||
using namespace Mastodon;
|
using namespace Mastodon;
|
||||||
|
|
||||||
|
@ -88,6 +89,7 @@ template struct Easy::return_entity<Easy::Status>;
|
||||||
template struct Easy::return_entity<Easy::Tag>;
|
template struct Easy::return_entity<Easy::Tag>;
|
||||||
template struct Easy::return_entity<Easy::Token>;
|
template struct Easy::return_entity<Easy::Token>;
|
||||||
template struct Easy::return_entity<Easy::PushSubscription>;
|
template struct Easy::return_entity<Easy::PushSubscription>;
|
||||||
|
template struct Easy::return_entity<Easy::Filter>;
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -132,3 +134,4 @@ template struct Easy::return_entity_vector<Easy::Status>;
|
||||||
template struct Easy::return_entity_vector<Easy::Tag>;
|
template struct Easy::return_entity_vector<Easy::Tag>;
|
||||||
template struct Easy::return_entity_vector<Easy::Token>;
|
template struct Easy::return_entity_vector<Easy::Token>;
|
||||||
template struct Easy::return_entity_vector<Easy::PushSubscription>;
|
template struct Easy::return_entity_vector<Easy::PushSubscription>;
|
||||||
|
template struct Easy::return_entity_vector<Easy::Filter>;
|
||||||
|
|
|
@ -102,6 +102,20 @@ namespace Easy
|
||||||
Undefined
|
Undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Describes the context.
|
||||||
|
*
|
||||||
|
* @since 0.104.0
|
||||||
|
*/
|
||||||
|
enum class context_type
|
||||||
|
{
|
||||||
|
Home,
|
||||||
|
Notifications,
|
||||||
|
Public,
|
||||||
|
Thread,
|
||||||
|
Undefined
|
||||||
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Used for stream events.
|
* @brief Used for stream events.
|
||||||
*
|
*
|
||||||
|
|
|
@ -115,15 +115,17 @@ const curlpp::Forms API::maptoformdata(const parameters &map)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string key = it.key;
|
// Append [] to array keys.
|
||||||
if (key == "account_ids" ||
|
string key = it.key;
|
||||||
key == "exclude_types" ||
|
if (key == "account_ids"
|
||||||
key == "media_ids")
|
|| key == "exclude_types"
|
||||||
{
|
|| key == "media_ids"
|
||||||
key += "[]";
|
|| key == "context")
|
||||||
}
|
{
|
||||||
formdata.push_back(
|
key += "[]";
|
||||||
new curlpp::FormParts::Content(key, it.values.front()));
|
}
|
||||||
|
formdata.push_back(
|
||||||
|
new curlpp::FormParts::Content(key, it.values.front()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -209,8 +209,8 @@ namespace Mastodon
|
||||||
statuses_id_favourite,
|
statuses_id_favourite,
|
||||||
statuses_id_unfavourite,
|
statuses_id_unfavourite,
|
||||||
|
|
||||||
// filters,
|
filters,
|
||||||
// filters_id,
|
filters_id,
|
||||||
|
|
||||||
follow_requests,
|
follow_requests,
|
||||||
follow_requests_id_authorize,
|
follow_requests_id_authorize,
|
||||||
|
|
Reference in New Issue