mastodon-cpp  0.104.0
Public Member Functions | List of all members
Mastodon::API::http Class Reference

http class. Do not use this directly. More...

#include <mastodon-cpp.hpp>

Public Member Functions

 http (const API &api, const string &instance, const string &access_token)
 Constructs new http object. More...
 
return_call request (const http_method &meth, const string &path)
 
return_call request (const http_method &meth, const string &path, const curlpp::Forms &formdata)
 HTTP Request. More...
 
void request_stream (const string &path, string &stream)
 HTTP Request for streams. More...
 
void get_headers (string &headers) const
 Get all headers in a string.
 
void cancel_stream ()
 Cancels the stream. Use only with streams. More...
 
std::mutex & get_mutex ()
 Gets the mutex guarding the string that is written to. More...
 

Detailed Description

http class. Do not use this directly.

Since
before 0.11.0

Constructor & Destructor Documentation

◆ http()

API::http::http ( const API api,
const string &  instance,
const string &  access_token 
)
explicit

Constructs new http object.

Parameters
APIParent object.
instanceInstance domain name
access_tokenAccess token
Since
before 0.11.0
35 : parent(api)
36 , _instance(instance)
37 , _access_token(access_token)
38 , _cancel_stream(false)
39 {
40  curlpp::initialize();
41 }

Member Function Documentation

◆ cancel_stream()

void API::http::cancel_stream ( )

Cancels the stream. Use only with streams.

Cancels the stream next time data comes in. Can take a few seconds. This works only with streams, because only streams have an own http object.

Since
0.12.2
253 {
254  _cancel_stream = true;
255  _streamthread.join();
256 }

◆ get_mutex()

std::mutex & API::http::get_mutex ( )

Gets the mutex guarding the string that is written to.

The mutex guards the function that writes to the string you specified in get_stream().

Returns
A reference of the mutex.
Since
0.12.3
259 {
260  return _mutex;
261 }

◆ request()

return_call API::http::request ( const http_method meth,
const string &  path,
const curlpp::Forms &  formdata 
)

HTTP Request.

Parameters
methA method defined in http::method.
pathThe API call as string.
formdataThe form data for PATCH and POST requests.
Since
0.100.0
55 {
56  string answer;
57  return request_common(meth, path, formdata, answer);
58 }

◆ request_stream()

void API::http::request_stream ( const string &  path,
string &  stream 
)

HTTP Request for streams.

Parameters
pathThe API call as string.
streamThe stream of data that is returned.
Since
0.100.0
61 {
62  static return_call ret;
63  _streamthread = std::thread(
64  [&, path] // path is captured by value because it may be
65  { // deleted before we access it.
66  ret = request_common(http_method::GET_STREAM, path,
67  curlpp::Forms(), stream);
68  ttdebug << "Remaining content of the stream: " << stream << '\n';
69  if (!ret)
70  {
71  // Embed the HTTP status code in stream on error.
72  stream += "event: ERROR\ndata: {\"error_code\":"
73  + std::to_string(ret.error_code) + ",\"http_error\":"
74  + std::to_string(ret.http_error_code) + "}\n";
75  }
76  });
77 }
Return type for API calls.
Definition: return_types.hpp:92
uint8_t error_code
Error code.
Definition: return_types.hpp:41
uint16_t http_error_code
HTTP error code.
Definition: return_types.hpp:55

The documentation for this class was generated from the following files: