Moved API::http::method to http_method.

This commit is contained in:
tastytea 2019-04-05 14:40:54 +02:00
parent 88d69be298
commit 6a01efc6aa
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
9 changed files with 42 additions and 32 deletions

View File

@ -62,5 +62,5 @@ return_call API::del(const Mastodon::API::v1 &call,
return_call API::del(const std::string &call, const parametermap &parameters)
{
return _http.request(http::method::DELETE, call, maptoformdata(parameters));
return _http.request(http_method::DELETE, call, maptoformdata(parameters));
}

View File

@ -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);
}

View File

@ -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<http> &ptr)
{
ptr = std::make_unique<http>(*this, _instance, _access_token);
return ptr->request(http::method::GET_STREAM, call);
return ptr->request(http_method::GET_STREAM, call);
}

View File

@ -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));
}

View File

@ -143,5 +143,5 @@ return_call API::post(const Mastodon::API::v1 &call)
return_call API::post(const string &call, const parametermap &parameters)
{
return _http.request(http::method::POST, call, maptoformdata(parameters));
return _http.request(http_method::POST, call, maptoformdata(parameters));
}

View File

@ -56,5 +56,5 @@ return_call API::put(const Mastodon::API::v1 &call,
return_call API::put(const string &call, const parametermap &parameters)
{
return _http.request(http::method::PUT, call, maptoformdata(parameters));
return _http.request(http_method::PUT, call, maptoformdata(parameters));
}

View File

@ -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<curlopts::CustomRequest>("PATCH");
break;
case http::method::POST:
case http_method::POST:
request.setOpt<curlopts::CustomRequest>("POST");
break;
case http::method::PUT:
case http_method::PUT:
request.setOpt<curlopts::CustomRequest>("PUT");
break;
case http::method::DELETE:
case http_method::DELETE:
request.setOpt<curlopts::CustomRequest>("DELETE");
break;
default:

View File

@ -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);

View File

@ -40,6 +40,21 @@ namespace Mastodon
* @since before 0.11.0
*/
typedef std::map<string, std::vector<string>> 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