diff --git a/src/api/delete.cpp b/src/api/delete.cpp index eff70e2..69707fa 100644 --- a/src/api/delete.cpp +++ b/src/api/delete.cpp @@ -62,5 +62,5 @@ return_call API::del(const Mastodon::API::v1 &call, return_call API::del(const std::string &call, const parametermap ¶meters) { - return _http.request(http::method::DELETE, call, maptoformdata(parameters)); + return _http.request(http_method::DELETE, call, maptoformdata(parameters)); } diff --git a/src/api/get.cpp b/src/api/get.cpp index 769e54c..b7006b1 100644 --- a/src/api/get.cpp +++ b/src/api/get.cpp @@ -280,5 +280,5 @@ const return_call API::get(const Mastodon::API::v1 &call) const return_call API::get(const std::string &call) { - return _http.request(http::method::GET, call); + return _http.request(http_method::GET, call); } diff --git a/src/api/get_stream.cpp b/src/api/get_stream.cpp index a709af6..73f2a63 100644 --- a/src/api/get_stream.cpp +++ b/src/api/get_stream.cpp @@ -68,5 +68,5 @@ return_call API::get_stream(const Mastodon::API::v1 &call, return_call API::get_stream(const std::string &call, std::unique_ptr &ptr) { ptr = std::make_unique(*this, _instance, _access_token); - return ptr->request(http::method::GET_STREAM, call); + return ptr->request(http_method::GET_STREAM, call); } diff --git a/src/api/patch.cpp b/src/api/patch.cpp index 12050d9..260d9d3 100644 --- a/src/api/patch.cpp +++ b/src/api/patch.cpp @@ -36,6 +36,6 @@ return_call API::patch(const Mastodon::API::v1 &call, break; } - return _http.request(API::http::method::PATCH, + return _http.request(http_method::PATCH, strcall, maptoformdata(parameters)); } diff --git a/src/api/post.cpp b/src/api/post.cpp index e2c37cb..1f75ec3 100644 --- a/src/api/post.cpp +++ b/src/api/post.cpp @@ -143,5 +143,5 @@ return_call API::post(const Mastodon::API::v1 &call) return_call API::post(const string &call, const parametermap ¶meters) { - return _http.request(http::method::POST, call, maptoformdata(parameters)); + return _http.request(http_method::POST, call, maptoformdata(parameters)); } diff --git a/src/api/put.cpp b/src/api/put.cpp index 6ecedc0..a74a90f 100644 --- a/src/api/put.cpp +++ b/src/api/put.cpp @@ -56,5 +56,5 @@ return_call API::put(const Mastodon::API::v1 &call, return_call API::put(const string &call, const parametermap ¶meters) { - return _http.request(http::method::PUT, call, maptoformdata(parameters)); + return _http.request(http_method::PUT, call, maptoformdata(parameters)); } diff --git a/src/http.cpp b/src/http.cpp index 0c69d42..c207943 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -44,14 +44,14 @@ API::http::~http() curlpp::terminate(); } -return_call API::http::request(const method &meth, const string &path) +return_call API::http::request(const http_method &meth, const string &path) { return request(meth, path, curlpp::Forms()); } -return_call API::http::request(const method &meth, - const string &path, - const curlpp::Forms &formdata) +return_call API::http::request(const http_method &meth, + const string &path, + const curlpp::Forms &formdata) { using namespace std::placeholders; // _1, _2, _3 @@ -85,7 +85,7 @@ return_call API::http::request(const method &meth, { headers.push_back("Authorization: Bearer " + _access_token); } - if (meth != http::method::GET_STREAM) + if (meth != http_method::GET_STREAM) { headers.push_back("Connection: close"); // Get headers from server @@ -106,18 +106,18 @@ return_call API::http::request(const method &meth, switch (meth) { - case http::method::GET: + case http_method::GET: break; - case http::method::PATCH: + case http_method::PATCH: request.setOpt("PATCH"); break; - case http::method::POST: + case http_method::POST: request.setOpt("POST"); break; - case http::method::PUT: + case http_method::PUT: request.setOpt("PUT"); break; - case http::method::DELETE: + case http_method::DELETE: request.setOpt("DELETE"); break; default: diff --git a/src/mastodon-cpp.hpp b/src/mastodon-cpp.hpp index 3c63921..59600ec 100644 --- a/src/mastodon-cpp.hpp +++ b/src/mastodon-cpp.hpp @@ -76,37 +76,32 @@ namespace Mastodon { public: /*! - * @brief HTTP methods + * @brief Constructs new http object. + * + * @param API Parent object. + * @param instance Instance domain name + * @param access_token Access token + * + * @since before 0.11.0 */ - enum class method - { - GET, - PATCH, - POST, - PUT, - DELETE, - GET_STREAM - }; - explicit http(const API &api, const string &instance, const string &access_token); ~http(); - return_call request(const method &meth, const string &path); + return_call request(const http_method &meth, const string &path); /*! * @brief HTTP Request. * - * @param meth The method defined in http::method + * @param meth A method defined in http::method * @param path The api call as string * @param formdata The form data for PATCH and POST requests. - * @param answer The answer from the server * * @return @ref error "Error code". If the URL has permanently - * changed, 13 is returned and answer is set to the new URL. + * changed, 13 is returned and the answer is set to the new URL. * * @since before 0.11.0 */ - return_call request(const method &meth, + return_call request(const http_method &meth, const string &path, const curlpp::Forms &formdata); diff --git a/src/types.hpp b/src/types.hpp index d71156b..ccde819 100644 --- a/src/types.hpp +++ b/src/types.hpp @@ -40,6 +40,21 @@ namespace Mastodon * @since before 0.11.0 */ typedef std::map> parametermap; + + /*! + * @brief HTTP methods. + * + * @since before 0.100.0 + */ + enum class http_method + { + GET, + PATCH, + POST, + PUT, + DELETE, + GET_STREAM + }; } #endif // MASTODON_CPP_TYPES_HPP