mastodonpp  0.5.7
C++ wrapper for the Mastodon and Pleroma APIs.
Public Member Functions | Public Attributes | Friends | List of all members
mastodonpp::answer_type Struct Reference

Return type for Requests. More...

#include <types.hpp>

Collaboration diagram for mastodonpp::answer_type:
Collaboration graph
[legend]

Public Member Functions

 operator bool () const
 Returns true if curl_error_code is 0 and http_status is 200, false otherwise. More...
 
 operator string_view () const
 Returns body as std::string_view. More...
 
string_view get_header (string_view field) const
 Returns the value of a header field. More...
 
parametermap next () const
 Returns the parameters needed for the next entries. More...
 
parametermap prev () const
 Returns the parameters needed for the previous entries. More...
 

Public Attributes

uint8_t curl_error_code {0}
 The error code returned by libcurl. More...
 
string error_message
 The error message. More...
 
uint16_t http_status {0}
 HTTP status code. More...
 
string headers
 The headers of the response from the server. More...
 
string body
 The response from the server, usually JSON. More...
 

Friends

ostream & operator<< (ostream &out, const answer_type &answer)
 Returns body as std::ostream. More...
 

Detailed Description

Return type for Requests.

Since
0.1.0

Member Function Documentation

◆ get_header()

string_view mastodonpp::answer_type::get_header ( string_view  field) const

Returns the value of a header field.

Is only valid for as long as the answer_type is in scope.

Parameters
fieldCase insensitive, only ASCII.
Since
0.1.0
47 {
48  const string_view searchstring{string(field) += ':'};
49  // clang-format off
50  auto it{search(headers.begin(), headers.end(), searchstring.begin(),
51  searchstring.end(), [](unsigned char a, unsigned char b)
52  { return tolower(a) == tolower(b); })};
53  // clang-format on
54 
55  if (it != headers.end())
56  {
57  auto pos{static_cast<size_t>(it - headers.begin())};
58  pos = headers.find(':', pos) + 2;
59  const auto endpos{headers.find('\n', pos)};
60  return string_view(&headers[pos], endpos - pos);
61  }
62 
63  return {};
64 }
string headers
The headers of the response from the server.
Definition: types.hpp:112

◆ next()

parametermap mastodonpp::answer_type::next ( ) const
inline

Returns the parameters needed for the next entries.

Parses the Link header.

Since
0.3.0
162  {
163  return parse_pagination(true);
164  }

◆ operator bool()

mastodonpp::answer_type::operator bool ( ) const
explicit

Returns true if curl_error_code is 0 and http_status is 200, false otherwise.

Since
0.1.0
31 {
32  return (curl_error_code == 0 && http_status == 200);
33 }
uint16_t http_status
HTTP status code.
Definition: types.hpp:105
uint8_t curl_error_code
The error code returned by libcurl.
Definition: types.hpp:91

◆ operator string_view()

mastodonpp::answer_type::operator string_view ( ) const
explicit

Returns body as std::string_view.

Since
0.1.0
36 {
37  return body;
38 }
string body
The response from the server, usually JSON.
Definition: types.hpp:119

◆ prev()

parametermap mastodonpp::answer_type::prev ( ) const
inline

Returns the parameters needed for the previous entries.

Parses the Link header.

Since
0.3.0
175  {
176  return parse_pagination(false);
177  }

Friends And Related Function Documentation

◆ operator<<

ostream& operator<< ( std::ostream &  out,
const answer_type answer 
)
friend

Returns body as std::ostream.

Since
0.1.0
41 {
42  out << answer.body;
43  return out;
44 }

Member Data Documentation

◆ body

string mastodonpp::answer_type::body

The response from the server, usually JSON.

Since
0.1.0

◆ curl_error_code

uint8_t mastodonpp::answer_type::curl_error_code {0}

The error code returned by libcurl.

For more information consult libcurl-errors(3).

Since
0.1.0

◆ error_message

string mastodonpp::answer_type::error_message

The error message.

Since
0.1.0

◆ headers

string mastodonpp::answer_type::headers

The headers of the response from the server.

Since
0.1.0

◆ http_status

uint16_t mastodonpp::answer_type::http_status {0}

HTTP status code.

Since
0.1.0

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