diff --git a/docs/classmastodonpp_1_1CURLWrapper-members.html b/docs/classmastodonpp_1_1CURLWrapper-members.html
index 4f37947..b0bbfcd 100644
--- a/docs/classmastodonpp_1_1CURLWrapper-members.html
+++ b/docs/classmastodonpp_1_1CURLWrapper-members.html
@@ -77,7 +77,7 @@ $(function() {
CURLWrapper(const CURLWrapper &other)=default | mastodonpp::CURLWrapper | |
CURLWrapper(CURLWrapper &&other) noexcept=default | mastodonpp::CURLWrapper | |
get_curl_easy_handle() | mastodonpp::CURLWrapper | inline |
- make_request(const http_method &method, const string_view &uri) | mastodonpp::CURLWrapper | protected |
+ make_request(const http_method &method, string uri, const parametermap ¶meters) | mastodonpp::CURLWrapper | protected |
operator=(const CURLWrapper &other)=default | mastodonpp::CURLWrapper | |
operator=(CURLWrapper &&other) noexcept=default | mastodonpp::CURLWrapper | |
~CURLWrapper() noexcept | mastodonpp::CURLWrapper | virtual |
diff --git a/docs/classmastodonpp_1_1CURLWrapper.html b/docs/classmastodonpp_1_1CURLWrapper.html
index 1f5bfc6..ccc6fa7 100644
--- a/docs/classmastodonpp_1_1CURLWrapper.html
+++ b/docs/classmastodonpp_1_1CURLWrapper.html
@@ -116,9 +116,9 @@ Public Member Functions
Handles the details of network connections.
@@ -143,18 +143,18 @@ Protected Member Functions
Initializes curl and sets up connection.
The first time an instance of CURLWrapper is created, it calls curl_global_init
, which is not thread-safe. For more information consult curl_global_init(3).
- Since
- 0.1.0
-
36 : _curl_buffer_error{}
-
-
38 if (curlwrapper_instances == 0)
-
-
40 curl_global_init(CURL_GLOBAL_ALL);
-
-
42 ++curlwrapper_instances;
-
43 debuglog <<
"CURLWrapper instances: " << curlwrapper_instances <<
" (+1)\n";
-
-
45 _connection = curl_easy_init();
-
-
+
42 : _curl_buffer_error{}
+
+
44 if (curlwrapper_instances == 0)
+
+
46 curl_global_init(CURL_GLOBAL_ALL);
+
+
48 ++curlwrapper_instances;
+
49 debuglog <<
"CURLWrapper instances: " << curlwrapper_instances <<
" (+1)\n";
+
+
51 _connection = curl_easy_init();
+
+
@@ -240,16 +240,16 @@ Protected Member Functions
Cleans up curl and connection.
Calls curl_global_cleanup
, which is not thread-safe. For more information consult curl_global_cleanup(3).
- Since
- 0.1.0
-
-
50 curl_easy_cleanup(_connection);
-
-
52 --curlwrapper_instances;
-
53 debuglog <<
"CURLWrapper instances: " << curlwrapper_instances <<
" (-1)\n";
-
54 if (curlwrapper_instances == 0)
-
-
56 curl_global_cleanup();
-
-
+
+
56 curl_easy_cleanup(_connection);
+
+
58 --curlwrapper_instances;
+
59 debuglog <<
"CURLWrapper instances: " << curlwrapper_instances <<
" (-1)\n";
+
60 if (curlwrapper_instances == 0)
+
+
62 curl_global_cleanup();
+
+
@@ -286,8 +286,8 @@ Protected Member Functions
-
-◆ make_request()
+
+◆ make_request()
@@ -304,8 +304,14 @@ Protected Member Functions
|
|
- const string_view & |
- uri |
+ string |
+ uri, |
+
+
+ |
+ |
+ const parametermap & |
+ parameters |
|
@@ -320,88 +326,134 @@ Protected Member Functions
-
Make a request.
+
Make a HTTP request.
- Parameters
-
method | The HTTP method. |
- uri | The full URI. |
+ uri | The full URI. |
+ parameters | A map of parameters. |
- Since
- 0.1.0
-
-
63 debuglog <<
"Making request to: " << uri <<
'\n';
-
-
-
-
-
68 case http_method::GET:
-
-
-
71 code = curl_easy_setopt(_connection, CURLOPT_HTTPGET, 1L);
-
-
-
74 case http_method::POST:
-
-
-
77 code = curl_easy_setopt(_connection, CURLOPT_POST, 1L);
-
-
-
80 case http_method::PATCH:
-
-
-
83 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"PATCH");
-
-
-
86 case http_method::PUT:
-
-
-
89 code = curl_easy_setopt(_connection, CURLOPT_UPLOAD, 1L);
-
-
-
92 case http_method::DELETE:
-
-
-
95 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"DELETE");
-
-
-
-
-
-
101 throw CURLException{code,
"Failed to set HTTP method",
-
-
-
-
-
106 code = curl_easy_setopt(_connection, CURLOPT_URL, uri.data());
-
107 if (code != CURLE_OK)
-
-
109 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
-
-
-
-
113 code = curl_easy_perform(_connection);
-
114 if (code == CURLE_OK)
-
-
-
-
118 curl_easy_getinfo(_connection, CURLINFO_RESPONSE_CODE, &http_status);
-
119 answer.http_status = static_cast<uint16_t>(http_status);
-
120 debuglog <<
"HTTP status code: " << http_status <<
'\n';
+
+
+
+
+
72 case http_method::GET:
+
+
+
75 code = curl_easy_setopt(_connection, CURLOPT_HTTPGET, 1L);
+
+
77 for (
const auto ¶m : parameters)
+
+
79 static constexpr array replace_in_uri
+
+
81 "id",
"nickname",
"nickname_or_id",
+
82 "hashtag",
"permission_group"
+
+
84 if (any_of(replace_in_uri.begin(), replace_in_uri.end(),
+
85 [¶m](
const auto &s) {
return s == param.first; }))
+
+
87 const auto pos{uri.find(
'<')};
+
88 if (pos != string::npos)
+
+
90 uri.replace(pos, param.first.size() + 2,
+
91 get<string>(param.second));
+
+
+
+
95 static bool first{
true};
+
+
+
+
+
+
+
+
+
+
105 if (holds_alternative<string>(param.second))
+
+
107 uri.append(param.first +
'=' + get<string>(param.second));
+
+
+
+
111 for (
const auto &arg : get<vector<string>>(param.second))
+
+
113 uri.append(param.first +
"[]=" + arg);
+
114 if (arg != *get<vector<string>>(param.second).rbegin())
+
+
+
+
+
+
-
122 answer.headers = _curl_buffer_headers;
-
123 answer.body = _curl_buffer_body;
-
-
-
-
127 answer.curl_error_code = static_cast<uint8_t>(code);
-
128 answer.error_message = _curl_buffer_error;
-
129 debuglog <<
"libcurl error: " << code <<
'\n';
-
130 debuglog << _curl_buffer_error <<
'\n';
-
-
-
-
+
+
+
124 case http_method::POST:
+
+
+
127 code = curl_easy_setopt(_connection, CURLOPT_POST, 1L);
+
+
+
130 case http_method::PATCH:
+
+
+
133 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"PATCH");
+
+
+
136 case http_method::PUT:
+
+
+
139 code = curl_easy_setopt(_connection, CURLOPT_UPLOAD, 1L);
+
+
+
142 case http_method::DELETE:
+
+
+
145 code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST,
"DELETE");
+
+
+
+
149 if (code != CURLE_OK)
+
+
151 throw CURLException{code,
"Failed to set HTTP method",
+
+
+
154 debuglog <<
"Making request to: " << uri <<
'\n';
+
+
+
157 code = curl_easy_setopt(_connection, CURLOPT_URL, uri.data());
+
158 if (code != CURLE_OK)
+
+
160 throw CURLException{code,
"Failed to set URI", _curl_buffer_error};
+
+
+
+
164 code = curl_easy_perform(_connection);
+
165 if (code == CURLE_OK)
+
+
+
+
169 curl_easy_getinfo(_connection, CURLINFO_RESPONSE_CODE, &http_status);
+
170 answer.http_status = static_cast<uint16_t>(http_status);
+
171 debuglog <<
"HTTP status code: " << http_status <<
'\n';
+
+
173 answer.headers = _curl_buffer_headers;
+
174 answer.body = _curl_buffer_body;
+
+
+
+
178 answer.curl_error_code = static_cast<uint8_t>(code);
+
179 answer.error_message = _curl_buffer_error;
+
180 debuglog <<
"libcurl error: " << code <<
'\n';
+
181 debuglog << _curl_buffer_error <<
'\n';
+
+
+
+
diff --git a/docs/classmastodonpp_1_1Connection-members.html b/docs/classmastodonpp_1_1Connection-members.html
index 04cae95..febe376 100644
--- a/docs/classmastodonpp_1_1Connection-members.html
+++ b/docs/classmastodonpp_1_1Connection-members.html
@@ -77,10 +77,10 @@ $(function() {
CURLWrapper() | mastodonpp::CURLWrapper | |
CURLWrapper(const CURLWrapper &other)=default | mastodonpp::CURLWrapper | |
CURLWrapper(CURLWrapper &&other) noexcept=default | mastodonpp::CURLWrapper | |
-
get(const API::endpoint_type &endpoint) | mastodonpp::Connection | |
-
get(const string_view &endpoint) | mastodonpp::Connection | |
+
get(const endpoint_variant &endpoint, const parametermap ¶meters) | mastodonpp::Connection | |
+
get(const endpoint_variant &endpoint) | mastodonpp::Connection | inline |
get_curl_easy_handle() | mastodonpp::CURLWrapper | inline |
-
make_request(const http_method &method, const string_view &uri) | mastodonpp::CURLWrapper | protected |
+
make_request(const http_method &method, string uri, const parametermap ¶meters) | mastodonpp::CURLWrapper | protected |
operator=(const CURLWrapper &other)=default | mastodonpp::CURLWrapper | |
operator=(CURLWrapper &&other) noexcept=default | mastodonpp::CURLWrapper | |
~CURLWrapper() noexcept | mastodonpp::CURLWrapper | virtual |
diff --git a/docs/classmastodonpp_1_1Connection.html b/docs/classmastodonpp_1_1Connection.html
index a3116ec..63db500 100644
--- a/docs/classmastodonpp_1_1Connection.html
+++ b/docs/classmastodonpp_1_1Connection.html
@@ -93,12 +93,12 @@ Public Member Functions
| Connection (Instance &instance) |
| Construct a new Connection object. More...
|
|
-
answer_type | get (const API::endpoint_type &endpoint) |
-
| Make a HTTP GET call. More...
|
-
|
-
answer_type | get (const string_view &endpoint) |
-
| Make a HTTP GET call. More...
|
-
|
+
answer_type | get (const endpoint_variant &endpoint, const parametermap ¶meters) |
+
| Make a HTTP GET call with parameters. More...
|
+
|
+
answer_type | get (const endpoint_variant &endpoint) |
+
| Make a HTTP GET call. Example: More...
|
+
|
| CURLWrapper () |
| Initializes curl and sets up connection. More...
|
@@ -125,9 +125,9 @@ Public Member Functions
|
-
answer_type | make_request (const http_method &method, const string_view &uri) |
-
| Make a request. More...
|
-
|
+
answer_type | make_request (const http_method &method, string uri, const parametermap ¶meters) |
+
| Make a HTTP request. More...
|
+
|
Represents a connection to an instance. Used for requests.
@@ -165,47 +165,54 @@ Additional Inherited Members
- Since
- 0.1.0
-
-
24 , _baseuri{instance.get_baseuri()}
-
+
+
26 , _baseuri{instance.get_baseuri()}
+
-
-
◆ get() [1/2]
+
+
◆ get() [1/2]
-
Make a HTTP GET call.
-
- Parameters
-
+
Make a HTTP GET call. Example:
+auto answer{connection.get("/api/v1/instance")};
+
- Parameters
-
- Since
- 0.1.0
-
-
-
-
31 string(_baseuri).append(API{endpoint}.to_string_view()));
-
+
+
93 return get(endpoint, {});
+
-
-
◆ get() [2/2]
+
+
◆ get() [2/2]
@@ -213,24 +220,50 @@ Additional Inherited Members
answer_type mastodonpp::Connection::get |
( |
- const string_view & |
- endpoint | ) |
+ const endpoint_variant & |
+ endpoint, |
+
+
+ |
|
+ const parametermap & |
+ parameters |
+
+
+ |
+ ) |
+ | |
-
Make a HTTP GET call.
-
- Parameters
-
+
Make a HTTP GET call with parameters.
+Example:
auto answer{connection.get(mastodonpp::API::v1::accounts_id_followers,
+
{
+
{"id", "12"},
+
{"limit", "10"}
+
})};
+
- Parameters
-
- endpoint | Endpoint as string, for example: "/api/v1/instance". |
+ endpoint | Endpoint as API::endpoint_type or std::string . |
+ parameters | A map of parameters. |
- Since
- 0.1.0
-
-
36 return make_request(http_method::GET,
string(_baseuri).append(endpoint));
-
+
+
+
+
34 if (holds_alternative<API::endpoint_type>(endpoint))
+
+
36 return string(_baseuri).append(
+
37 API{std::get<API::endpoint_type>(endpoint)}.to_string_view());
+
+
+
40 return std::get<string>(endpoint);
+
+
+
@@ -239,7 +272,8 @@ Additional Inherited Members
src/connection.cpp
-
answer_type make_request(const http_method &method, const string_view &uri)
Make a request.
Definition: curl_wrapper.cpp:60
+
answer_type get(const endpoint_variant &endpoint, const parametermap ¶meters)
Make a HTTP GET call with parameters.
Definition: connection.cpp:29
+
answer_type make_request(const http_method &method, string uri, const parametermap ¶meters)
Make a HTTP request.
Definition: curl_wrapper.cpp:66
-Connection(Instance &instance)
Construct a new Connection object.
Definition: connection.cpp:22
+answer_type get(const endpoint_variant &endpoint, const parametermap ¶meters)
Make a HTTP GET call with parameters.
Definition: connection.cpp:29
+Connection(Instance &instance)
Construct a new Connection object.
Definition: connection.cpp:24
+answer_type get(const endpoint_variant &endpoint)
Make a HTTP GET call. Example:
Definition: connection.hpp:91
C++ wrapper for the Mastodon API.
Definition: answer.cpp:19
-answer_type get(const API::endpoint_type &endpoint)
Make a HTTP GET call.
Definition: connection.cpp:27
Return type for Requests.
Definition: answer.hpp:40
+map< string, variant< string, vector< string > >> parametermap
std::map of parameters for API calls.
Definition: curl_wrapper.hpp:67
Holds the access data of an instance.
Definition: instance.hpp:40
-variant< v1, v2, oauth, other, pleroma > endpoint_type
Type for endpoints. Can be API::v1, API::v2, API::oauth, API::other or API::pleroma.
Definition: api.hpp:295
-Represents a connection to an instance. Used for requests.
Definition: connection.hpp:41
+Represents a connection to an instance. Used for requests.
Definition: connection.hpp:45
Handles the details of network connections.
Definition: curl_wrapper.hpp:78