Add return type for requests.
This commit is contained in:
parent
b1b03bfa3e
commit
49e910ecd8
|
@ -17,6 +17,7 @@
|
||||||
#ifndef MASTODONPP_HPP
|
#ifndef MASTODONPP_HPP
|
||||||
#define MASTODONPP_HPP
|
#define MASTODONPP_HPP
|
||||||
|
|
||||||
|
#include "return_types.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace mastodonpp
|
namespace mastodonpp
|
||||||
|
|
46
include/return_types.hpp
Normal file
46
include/return_types.hpp
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/* This file is part of mastodonpp.
|
||||||
|
* Copyright © 2020 tastytea <tastytea@tastytea.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MASTODONPP_RETURN_TYPES_HPP
|
||||||
|
#define MASTODONPP_RETURN_TYPES_HPP
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
namespace mastodonpp
|
||||||
|
{
|
||||||
|
|
||||||
|
using std::uint8_t;
|
||||||
|
using std::uint16_t;
|
||||||
|
using std::string;
|
||||||
|
using std::string_view;
|
||||||
|
|
||||||
|
struct answer
|
||||||
|
{
|
||||||
|
uint8_t error_code;
|
||||||
|
string error_message;
|
||||||
|
uint16_t http_status;
|
||||||
|
string body;
|
||||||
|
|
||||||
|
explicit operator bool() const;
|
||||||
|
explicit operator string_view() const;
|
||||||
|
friend std::ostream &operator <<(std::ostream &out, const answer &answer);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace mastodonpp
|
||||||
|
|
||||||
|
#endif // MASTODONPP_RETURN_TYPES_HPP
|
38
src/return_types.cpp
Normal file
38
src/return_types.cpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/* This file is part of mastodonpp.
|
||||||
|
* Copyright © 2020 tastytea <tastytea@tastytea.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "return_types.hpp"
|
||||||
|
|
||||||
|
namespace mastodonpp
|
||||||
|
{
|
||||||
|
|
||||||
|
answer::operator bool() const
|
||||||
|
{
|
||||||
|
return (error_code == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
answer::operator string_view() const
|
||||||
|
{
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &operator <<(std::ostream &out, const answer &answer)
|
||||||
|
{
|
||||||
|
out << answer.body;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace mastodonpp
|
Loading…
Reference in New Issue
Block a user