mastodonpp  0.2.0
answer.hpp
1 /* This file is part of mastodonpp.
2  * Copyright © 2020 tastytea <tastytea@tastytea.de>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as published by
6  * the Free Software Foundation, version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Affero General Public License for more details.
12  *
13  * You should have received a copy of the GNU Affero General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef MASTODONPP_ANSWER_HPP
18 #define MASTODONPP_ANSWER_HPP
19 
20 #include <cstdint>
21 #include <ostream>
22 #include <string>
23 #include <string_view>
24 
25 namespace mastodonpp
26 {
27 
28 using std::uint8_t;
29 using std::uint16_t;
30 using std::ostream;
31 using std::string;
32 using std::string_view;
33 
43 {
52  uint8_t curl_error_code{0};
53 
59  string error_message;
60 
66  uint16_t http_status{0};
67 
73  string headers;
74 
80  string body;
81 
88  explicit operator bool() const;
89 
95  explicit operator string_view() const;
96 
102  friend ostream &operator <<(ostream &out, const answer_type &answer);
103 
113  string_view get_header(string_view field) const;
114 };
115 
116 } // namespace mastodonpp
117 
118 #endif // MASTODONPP_ANSWER_HPP
mastodonpp::answer_type::operator<<
friend ostream & operator<<(ostream &out, const answer_type &answer)
Returns body as std::ostream.
Definition: answer.cpp:38
mastodonpp::answer_type::headers
string headers
The headers of the response from the server.
Definition: answer.hpp:73
mastodonpp::answer_type::curl_error_code
uint8_t curl_error_code
The error code returned by libcurl.
Definition: answer.hpp:52
mastodonpp
C++ wrapper for the Mastodon API.
Definition: answer.cpp:22
mastodonpp::answer_type::body
string body
The response from the server, usually JSON.
Definition: answer.hpp:80
mastodonpp::answer_type::error_message
string error_message
The error message.
Definition: answer.hpp:59
mastodonpp::answer_type
Return type for Requests.
Definition: answer.hpp:42
mastodonpp::answer_type::get_header
string_view get_header(string_view field) const
Returns the value of a header field.
Definition: answer.cpp:44
mastodonpp::answer_type::http_status
uint16_t http_status
HTTP status code.
Definition: answer.hpp:66