summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/mastodonpp.hpp1
-rw-r--r--include/return_types.hpp46
-rw-r--r--src/return_types.cpp38
3 files changed, 85 insertions, 0 deletions
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 <string>
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 <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
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 <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