diff --git a/include/mastodonpp.hpp b/include/mastodonpp.hpp index 713712d..606e61a 100644 --- a/include/mastodonpp.hpp +++ b/include/mastodonpp.hpp @@ -17,6 +17,7 @@ #ifndef MASTODONPP_HPP #define MASTODONPP_HPP +#include "return_types.hpp" #include namespace mastodonpp diff --git a/include/return_types.hpp b/include/return_types.hpp new file mode 100644 index 0000000..e9d7db8 --- /dev/null +++ b/include/return_types.hpp @@ -0,0 +1,46 @@ +/* This file is part of mastodonpp. + * Copyright © 2020 tastytea + * + * 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 . + */ + +#ifndef MASTODONPP_RETURN_TYPES_HPP +#define MASTODONPP_RETURN_TYPES_HPP + +#include +#include +#include + +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 diff --git a/src/return_types.cpp b/src/return_types.cpp new file mode 100644 index 0000000..6367f7c --- /dev/null +++ b/src/return_types.cpp @@ -0,0 +1,38 @@ +/* This file is part of mastodonpp. + * Copyright © 2020 tastytea + * + * 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 . + */ + +#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