summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortastytea2020-01-05 19:00:24 +0100
committertastytea2020-01-05 19:00:24 +0100
commit159cd05f5a1651cc3e9b2ac830f251828b8c6cd7 (patch)
tree77bdf4ed72ce4fd5205bb93c436d582da5067ee2
parentfba5a576f0646afe726eead936d9046274a4b692 (diff)
downloadmastodonpp-159cd05f5a1651cc3e9b2ac830f251828b8c6cd7.tar
mastodonpp-159cd05f5a1651cc3e9b2ac830f251828b8c6cd7.tar.gz
mastodonpp-159cd05f5a1651cc3e9b2ac830f251828b8c6cd7.zip
Make _endpoint_map static.
-rw-r--r--include/api.hpp10
-rw-r--r--include/connection.hpp1
-rw-r--r--src/api.cpp10
-rw-r--r--src/connection.cpp3
4 files changed, 12 insertions, 12 deletions
diff --git a/include/api.hpp b/include/api.hpp
index 00a6dc3..e508fa1 100644
--- a/include/api.hpp
+++ b/include/api.hpp
@@ -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
diff --git a/include/connection.hpp b/include/connection.hpp
index 1a6c11f..a26120c 100644
--- a/include/connection.hpp
+++ b/include/connection.hpp
@@ -74,7 +74,6 @@ public:
private:
Instance &_instance;
const string_view _baseuri;
- const API _api;
};
} // namespace mastodonpp
diff --git a/src/api.cpp b/src/api.cpp
index 98a1d7f..fd7eede 100644
--- a/src/api.cpp
+++ b/src/api.cpp
@@ -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
diff --git a/src/connection.cpp b/src/connection.cpp
index cc956e0..e6bca95 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -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)