From 14a1d92442a1d441a8fce054a290c94b80960c29 Mon Sep 17 00:00:00 2001 From: tastytea Date: Fri, 20 Sep 2019 02:26:47 +0200 Subject: [PATCH] Added /api/v1/conversations. --- README.adoc | 2 +- src/api/get.cpp | 5 ++ src/mastodon-cpp.hpp | 2 +- tests/api/test_api_v1_conversations.cpp | 74 +++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 tests/api/test_api_v1_conversations.cpp diff --git a/README.adoc b/README.adoc index f16834b..6a87af7 100644 --- a/README.adoc +++ b/README.adoc @@ -370,7 +370,7 @@ strings and you can use unsupported fields in an `Entity` by converting it to ** [x] POST /api/v1/statuses/:id/unpin * Timelines ** [x] GET /api/v1/timelines/home - ** [ ] GET /api/v1/conversations + ** [x] GET /api/v1/conversations ** [x] GET /api/v1/timelines/public ** [x] GET /api/v1/timelines/tag/:hashtag ** [x] GET /api/v1/timelines/list/:list_id diff --git a/src/api/get.cpp b/src/api/get.cpp index 38c74eb..d80a60c 100644 --- a/src/api/get.cpp +++ b/src/api/get.cpp @@ -236,6 +236,11 @@ const return_call API::get(const Mastodon::API::v1 &call, strcall = "/api/v1/polls/" + strid; break; } + case v1::conversations: + { + strcall = "/api/v1/conversations"; + break; + } default: { ttdebug << "ERROR: Invalid argument.\n"; diff --git a/src/mastodon-cpp.hpp b/src/mastodon-cpp.hpp index 0a7bb51..2d1e12f 100644 --- a/src/mastodon-cpp.hpp +++ b/src/mastodon-cpp.hpp @@ -264,7 +264,7 @@ namespace Mastodon statuses_id_unpin, timelines_home, - // timelines_conversations, + conversations, timelines_public, timelines_tag_hashtag, timelines_list_list_id, diff --git a/tests/api/test_api_v1_conversations.cpp b/tests/api/test_api_v1_conversations.cpp new file mode 100644 index 0000000..69a728a --- /dev/null +++ b/tests/api/test_api_v1_conversations.cpp @@ -0,0 +1,74 @@ +/* This file is part of mastodon-cpp. + * Copyright © 2019 tastytea + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include "mastodon-cpp.hpp" +#include "easy/easy.hpp" +#include "easy/entities/conversation.hpp" +#include "../environment_variables.hpp" + +using namespace Mastodon; + +SCENARIO ("/api/v1/conversations can be called successfully", + "[api][auth][mastodon][glitch-soc]") +{ + REQUIRE (access_token != nullptr); + + GIVEN ("instance = " + instance) + { + Mastodon::Easy::API masto(instance, access_token); + return_call ret; + Easy::Conversation conversation; + bool exception = false; + + WHEN ("GET /api/v1/conversations is called") + { + try + { + ret = masto.get(API::v1::conversations, {{ "limit", { "2" }}}); + if (ret.answer == "[]") + { + WARN("No Conversations found."); + } + else + { + conversation.from_string( + Easy::json_array_to_vector(ret.answer).front()); + } + } + catch (const std::exception &e) + { + exception = true; + WARN(e.what()); + } + + THEN("No exception is thrown") + AND_THEN ("No error is returned") + AND_THEN ("Answer is valid") + { + REQUIRE_FALSE(exception); + + REQUIRE(ret.error_code == 0); + REQUIRE(ret.http_error_code == 200); + REQUIRE(conversation.valid()); + REQUIRE(conversation.id() != ""); + } + } + } +} +