Moved API::http::method to http_method.
This commit is contained in:
parent
88d69be298
commit
6a01efc6aa
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
20
src/http.cpp
20
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<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:
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user