diff options
author | tastytea | 2020-01-08 12:56:16 +0100 |
---|---|---|
committer | tastytea | 2020-01-08 13:06:12 +0100 |
commit | c07fb1db71e8b4bc7f446f5f1945bfd1e09edd88 (patch) | |
tree | e498ee7a5575a6839b48e64720ff98e4a9c6e542 /include | |
parent | 15c1e154668da639b7b1766ae3f352615b7a5561 (diff) | |
download | mastodonpp-c07fb1db71e8b4bc7f446f5f1945bfd1e09edd88.tar mastodonpp-c07fb1db71e8b4bc7f446f5f1945bfd1e09edd88.tar.gz mastodonpp-c07fb1db71e8b4bc7f446f5f1945bfd1e09edd88.zip |
Add support for parameters (GET).
Diffstat (limited to 'include')
-rw-r--r-- | include/connection.hpp | 34 | ||||
-rw-r--r-- | include/curl_wrapper.hpp | 10 |
2 files changed, 34 insertions, 10 deletions
diff --git a/include/connection.hpp b/include/connection.hpp index 6e43bc6..90027fb 100644 --- a/include/connection.hpp +++ b/include/connection.hpp @@ -24,12 +24,16 @@ #include <string> #include <string_view> +#include <variant> namespace mastodonpp { using std::string; using std::string_view; +using std::variant; + +using endpoint_variant = variant<API::endpoint_type,string>; /*! * @brief Represents a connection to an instance. Used for requests. @@ -51,25 +55,43 @@ public: explicit Connection(Instance &instance); /*! - * @brief Make a HTTP GET call. + * @brief Make a HTTP GET call with parameters. + * + * Example: + * @code + * auto answer{connection.get(mastodonpp::API::v1::accounts_id_followers, + * { + * {"id", "12"}, + * {"limit", "10"} + * })}; + * @endcode + * + * @param endpoint Endpoint as API::endpoint_type or `std::string`. + * @param parameters A map of parameters. * - * @param endpoint Endpoint as API::endpoint_type, for example: - * `mastodonpp::API::v1::instance`. * * @since 0.1.0 */ [[nodiscard]] - answer_type get(const API::endpoint_type &endpoint); + answer_type get(const endpoint_variant &endpoint, + const parametermap ¶meters); /*! * @brief Make a HTTP GET call. + * Example: + * @code + * auto answer{connection.get("/api/v1/instance")}; + * @endcode * - * @param endpoint Endpoint as string, for example: "/api/v1/instance". + * @param endpoint Endpoint as API::endpoint_type or `std::string`. * * @since 0.1.0 */ [[nodiscard]] - answer_type get(const string_view &endpoint); + inline answer_type get(const endpoint_variant &endpoint) + { + return get(endpoint, {}); + } private: Instance &_instance; diff --git a/include/curl_wrapper.hpp b/include/curl_wrapper.hpp index 01a753e..146e481 100644 --- a/include/curl_wrapper.hpp +++ b/include/curl_wrapper.hpp @@ -129,15 +129,17 @@ public: protected: /*! - * @brief Make a request. + * @brief Make a HTTP request. * - * @param method The HTTP method. - * @param uri The full URI. + * @param method The HTTP method. + * @param uri The full URI. + * @param parameters A map of parameters. * * @since 0.1.0 */ [[nodiscard]] - answer_type make_request(const http_method &method, const string_view &uri); + answer_type make_request(const http_method &method, string uri, + const parametermap ¶meters); private: CURL *_connection; |