mastodonpp  0.5.4
Public Member Functions | Public Attributes | Friends | List of all members
mastodonpp::answer_type Struct Reference

Return type for Requests. More...

#include <types.hpp>

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
46 {
47  const string_view searchstring{string(field) += ':'};
48  auto it{search(headers.begin(), headers.end(),
49  searchstring.begin(), searchstring.end(),
50  [](unsigned char a, unsigned char b)
51  { return tolower(a) == tolower(b); })};
52 
53  if (it != headers.end())
54  {
55  auto pos{static_cast<size_t>(it - headers.begin())};
56  pos = headers.find(':', pos) + 2;
57  const auto endpos{headers.find('\n', pos)};
58  return string_view(&headers[pos], endpos - pos);
59  }
60 
61  return {};
62 }

◆ next()

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

Returns the parameters needed for the next entries.

Parses the Link header.

Since
0.3.0
164  {
165  return parse_pagination(true);
166  }

◆ 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
30 {
31  return (curl_error_code == 0 && http_status == 200);
32 }

◆ operator string_view()

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

Returns body as std::string_view.

Since
0.1.0
35 {
36  return body;
37 }

◆ prev()

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

Returns the parameters needed for the previous entries.

Parses the Link header.

Since
0.3.0
178  {
179  return parse_pagination(false);
180  }

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
40 {
41  out << answer.body;
42  return out;
43 }

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:
mastodonpp::answer_type::headers
string headers
The headers of the response from the server.
Definition: types.hpp:112
mastodonpp::answer_type::curl_error_code
uint8_t curl_error_code
The error code returned by libcurl.
Definition: types.hpp:91
mastodonpp::answer_type::body
string body
The response from the server, usually JSON.
Definition: types.hpp:119
mastodonpp::answer_type::http_status
uint16_t http_status
HTTP status code.
Definition: types.hpp:105