Make _endpoint_map static.

This commit is contained in:
tastytea 2020-01-05 19:00:24 +01:00
parent fba5a576f0
commit 159cd05f5a
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
4 changed files with 12 additions and 12 deletions

View File

@ -302,7 +302,7 @@ public:
*
* @since 0.1.0
*/
explicit API();
explicit API(const endpoint_type &endpoint);
/*!
* @brief Convert #endpoint_type to `std::string_view`.
@ -310,14 +310,14 @@ public:
* @since 0.1.0
*/
[[nodiscard]]
inline string_view endpoint_to_string_view(const endpoint_type &endpoint)
const
inline string_view to_string_view() const
{
return _endpoint_map.at(endpoint).data();
return _endpoint_map.at(_endpoint).data();
}
private:
const map<endpoint_type,string_view> _endpoint_map;
const endpoint_type _endpoint;
static const map<endpoint_type,string_view> _endpoint_map;
};
} // namespace mastodonpp

View File

@ -74,7 +74,6 @@ public:
private:
Instance &_instance;
const string_view _baseuri;
const API _api;
};
} // namespace mastodonpp

View File

@ -19,8 +19,11 @@
namespace mastodonpp
{
API::API()
: _endpoint_map
API::API(const endpoint_type &endpoint)
: _endpoint{endpoint}
{}
const map<API::endpoint_type,string_view> API::_endpoint_map
{
{v1::apps, "/api/v1/apps"},
{v1::apps_verify_credentials, "/api/v1/apps/verify/credentials"},
@ -238,7 +241,6 @@ API::API()
"/api/pleroma/pleroma/notification_settings"},
{pleroma::pleroma_healthcheck, "/api/pleroma/pleroma/healthcheck"},
{pleroma::pleroma_change_email, "/api/pleroma/pleroma/change_email"},
}
{}
};
} // namespace mastodonpp

View File

@ -22,14 +22,13 @@ namespace mastodonpp
Connection::Connection(Instance &instance)
: _instance{instance}
, _baseuri{instance.get_baseuri()}
, _api{}
{}
answer_type Connection::get(const API::endpoint_type &endpoint)
{
return make_request(
http_method::GET,
string(_baseuri).append(_api.endpoint_to_string_view(endpoint)));
string(_baseuri).append(API{endpoint}.to_string_view()));
}
answer_type Connection::get(const string_view &endpoint)