Represents a connection to an instance. Used for requests.
More...
#include <mastodonpp/connection.hpp>
Represents a connection to an instance. Used for requests.
- Since
- 0.1.0
◆ Connection()
mastodonpp::Connection::Connection |
( |
Instance & |
instance | ) |
|
|
explicit |
Construct a new Connection object.
- Parameters
-
instance | An Instance with the access data. |
- Since
- 0.1.0
26 , _baseuri{instance.get_baseuri()}
◆ cancel_stream()
void mastodonpp::Connection::cancel_stream |
( |
| ) |
|
|
inline |
Cancel the stream.
The stream will be cancelled, usually whithin a second. The curl_error_code of the answer will be set to 42 (CURLE_ABORTED_BY_CALLBACK
).
- Since
- 0.1.0
◆ del() [1/2]
Make a HTTP DELETE call.
- Parameters
-
- Since
- 0.2.0
239 return del(endpoint, {});
◆ del() [2/2]
Make a HTTP DELETE call with parameters.
- Parameters
-
endpoint | Endpoint as API::endpoint_type or std::string_view . |
parameters | A map of parameters. |
- Since
- 0.2.0
82 endpoint_to_uri(endpoint), parameters);
◆ get() [1/2]
Make a HTTP GET call.
Example:
auto answer{connection.get("/api/v1/instance")};
- Parameters
-
- Since
- 0.1.0
124 return get(endpoint, {});
◆ get() [2/2]
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 API::endpoint_type or std::string_view . |
parameters | A map of parameters. |
- Since
- 0.1.0
54 endpoint_to_uri(endpoint), parameters);
◆ get_new_events()
vector< event_type > mastodonpp::Connection::get_new_events |
( |
| ) |
|
Get new stream events.
- Since
- 0.1.0
99 vector<event_type> events;
102 while ((pos = buffer.find(
"event: ")) != string::npos)
104 const auto endpos{buffer.find(
"\n\n", pos)};
105 if (endpos == string::npos)
112 event.type = buffer.substr(pos, buffer.find(
'\n', pos) - pos);
113 pos = buffer.find(
"data: ") + 6;
114 event.data = buffer.substr(pos, endpos - pos);
115 events.push_back(event);
117 buffer.erase(0, endpos);
◆ get_new_stream_contents()
string mastodonpp::Connection::get_new_stream_contents |
( |
| ) |
|
Copy new stream contents and delete the “original”.
Note that the last event is not necessarily complete, it could happen that you are calling this function mid-transfer. You have to check the data integrity yourself.
Using get_new_events() instead is recommended.
- Since
- 0.1.0
89 auto buffer_copy{buffer};
◆ patch() [1/2]
Make a HTTP PATCH call.
- Parameters
-
- Since
- 0.2.0
187 return patch(endpoint, {});
◆ patch() [2/2]
Make a HTTP PATCH call with parameters.
- Parameters
-
endpoint | Endpoint as API::endpoint_type or std::string_view . |
parameters | A map of parameters. |
- Since
- 0.2.0
68 endpoint_to_uri(endpoint), parameters);
◆ post() [1/2]
Make a HTTP POST call.
- Parameters
-
- Since
- 0.1.0
161 return post(endpoint, {});
◆ post() [2/2]
Make a HTTP POST call with parameters.
Example:
auto answer{connection.post(
mastodonpp::API::v1::statuses,
{
{"status", "How is the wheather?"},
{"poll[options]", vector<string_view>{"Nice", "not nice"}},
{"poll[expires_in]", to_string(poll_seconds)}
})};
- Parameters
-
endpoint | Endpoint as API::endpoint_type or std::string_view . |
parameters | A map of parameters. |
- Since
- 0.1.0
61 endpoint_to_uri(endpoint), parameters);
◆ put() [1/2]
Make a HTTP PUT call.
- Parameters
-
- Since
- 0.2.0
213 return put(endpoint, {});
◆ put() [2/2]
Make a HTTP PUT call with parameters.
- Parameters
-
endpoint | Endpoint as API::endpoint_type or std::string_view . |
parameters | A map of parameters. |
- Since
- 0.2.0
75 endpoint_to_uri(endpoint), parameters);
The documentation for this class was generated from the following files:
answer_type get(const endpoint_variant &endpoint, const parametermap ¶meters)
Make a HTTP GET call with parameters.
Definition: connection.cpp:50
string_view get_proxy() const
Returns the proxy string that was previously set.
Definition: instance.hpp:133
void set_access_token(const string_view access_token)
Set OAuth 2.0 Bearer Access Token.
Definition: curl_wrapper.cpp:200
string_view get_access_token() const
Returns the access token.
Definition: instance.hpp:85
answer_type put(const endpoint_variant &endpoint, const parametermap ¶meters)
Make a HTTP PUT call with parameters.
Definition: connection.cpp:71
mutex buffer_mutex
Mutex for get_buffer a.k.a. _curl_buffer_body.
Definition: curl_wrapper.hpp:169
string & get_buffer()
Returns a reference to the buffer libcurl writes into.
Definition: curl_wrapper.hpp:190
answer_type del(const endpoint_variant &endpoint, const parametermap ¶meters)
Make a HTTP DELETE call with parameters.
Definition: connection.cpp:78
void set_proxy(string_view proxy)
Set the proxy to use.
Definition: curl_wrapper.cpp:67
answer_type patch(const endpoint_variant &endpoint, const parametermap ¶meters)
Make a HTTP PATCH call with parameters.
Definition: connection.cpp:64
answer_type post(const endpoint_variant &endpoint, const parametermap ¶meters)
Make a HTTP POST call with parameters.
Definition: connection.cpp:57
answer_type make_request(const http_method &method, string uri, const parametermap ¶meters)
Make a HTTP request.
Definition: curl_wrapper.cpp:77
void cancel_stream()
Cancel the stream.
Definition: curl_wrapper.hpp:204