From 2ab0018df9b2f8d17278d05095c1ac0428b93aa4 Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 8 Jan 2020 14:04:53 +0100 Subject: [PATCH] Replace arguments in URI. id, nickname, nickname_or_id, hashtag, permission_group. --- src/api.cpp | 2 +- src/curl_wrapper.cpp | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/api.cpp b/src/api.cpp index fd7eede..d0ffefa 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -31,7 +31,7 @@ const map API::_endpoint_map {v1::accounts, "/api/v1/accounts"}, {v1::accounts_verify_credentials, "/api/v1/accounts/verify/credentials"}, {v1::accounts_update_credentials, "/api/v1/accounts/update/credentials"}, - {v1::accounts_id, "/api/v1/accounts/id"}, + {v1::accounts_id, "/api/v1/accounts/"}, {v1::accounts_id_statuses, "/api/v1/accounts//statuses"}, {v1::accounts_id_followers, "/api/v1/accounts//followers"}, {v1::accounts_id_following, "/api/v1/accounts//following"}, diff --git a/src/curl_wrapper.cpp b/src/curl_wrapper.cpp index d153f7e..1e1040b 100644 --- a/src/curl_wrapper.cpp +++ b/src/curl_wrapper.cpp @@ -19,6 +19,8 @@ #include "log.hpp" #include "version.hpp" +#include +#include #include #include #include @@ -28,6 +30,8 @@ namespace mastodonpp using std::get; using std::holds_alternative; +using std::any_of; +using std::array; using std::atomic; using std::uint8_t; using std::uint16_t; @@ -72,6 +76,22 @@ answer_type CURLWrapper::make_request(const http_method &method, string uri, for (const auto ¶m : parameters) { + static constexpr array replace_in_uri + { + "id", "nickname", "nickname_or_id", + "hashtag", "permission_group" + }; + if (any_of(replace_in_uri.begin(), replace_in_uri.end(), + [¶m](const auto &s) { return s == param.first; })) + { + const auto pos{uri.find('<')}; + if (pos != string::npos) + { + uri.replace(pos, param.first.size() + 2, + get(param.second)); + } + continue; + } static bool first{true}; if (first) {