diff --git a/CMakeLists.txt b/CMakeLists.txt index ced92f9..40af053 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (mastodon-cpp - VERSION 0.7.10 + VERSION 0.7.11 LANGUAGES CXX ) diff --git a/src/easy/all.hpp b/src/easy/all.hpp index 339f8cc..36e566f 100644 --- a/src/easy/all.hpp +++ b/src/easy/all.hpp @@ -30,6 +30,8 @@ #include "easy/mention.hpp" //#include "easy/notification.hpp" #include "easy/relationship.hpp" + #include "easy/report.hpp" + //#include "easy/results.hpp" #else #include #include @@ -42,6 +44,8 @@ #include //#include #include + #include + //#include #endif #endif // MASTODON_CPP_EASY_ALL_HPP diff --git a/src/easy/easy.hpp b/src/easy/easy.hpp index 89ae4f7..e0caa88 100644 --- a/src/easy/easy.hpp +++ b/src/easy/easy.hpp @@ -196,6 +196,8 @@ public: class Mention; class Notification; class Relationship; + class Report; + class Results; }; } diff --git a/src/easy/instance.cpp b/src/easy/instance.cpp index 95c6eb8..c36f869 100644 --- a/src/easy/instance.cpp +++ b/src/easy/instance.cpp @@ -14,6 +14,7 @@ * along with this program. If not, see . */ +#include #include "instance.hpp" #include "account.hpp" #include "macros.hpp" @@ -31,7 +32,7 @@ Instance::Instance() const Easy::Account Instance::contact_account() const { - const Json::Value node = _tree["contact_account"]; + const Json::Value node = get("contact_account"); if (node.isObject()) { return Easy::Account(node.toStyledString()); diff --git a/src/easy/relationship.hpp b/src/easy/relationship.hpp index 85d5625..cb68afc 100644 --- a/src/easy/relationship.hpp +++ b/src/easy/relationship.hpp @@ -17,6 +17,7 @@ #ifndef MASTODON_CPP_EASY_RELATIONSHIP_HPP #define MASTODON_CPP_EASY_RELATIONSHIP_HPP +#include #include // If we are compiling mastodon-cpp, use another include path @@ -28,6 +29,7 @@ #include #endif +using std::string; using std::uint64_t; namespace Mastodon diff --git a/src/easy/report.cpp b/src/easy/report.cpp new file mode 100644 index 0000000..17f1551 --- /dev/null +++ b/src/easy/report.cpp @@ -0,0 +1,39 @@ +/* This file is part of mastodon-cpp. + * Copyright © 2018 tastytea + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "report.hpp" + +using namespace Mastodon; +using Report = Easy::Report; + +Report::Report(const string &json) +: Entity(json) +{} + +Report::Report() +: Entity() +{} + +const bool Report::action_taken() const +{ + return get_bool("action_taken"); +} + +const uint64_t Report::id() const +{ + return get_uint64("id"); +} + diff --git a/src/easy/report.hpp b/src/easy/report.hpp new file mode 100644 index 0000000..c18a596 --- /dev/null +++ b/src/easy/report.hpp @@ -0,0 +1,68 @@ +/* This file is part of mastodon-cpp. + * Copyright © 2018 tastytea + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef MASTODON_CPP_EASY_REPORT_HPP +#define MASTODON_CPP_EASY_REPORT_HPP + +#include +#include + +// If we are compiling mastodon-cpp, use another include path +#ifdef MASTODON_CPP + #include "mastodon-cpp.hpp" + #include "easy.hpp" +#else + #include + #include +#endif + +using std::string; +using std::uint64_t; + +namespace Mastodon +{ + /*! + * @brief Class to hold reports + */ + class Easy::Report : public Easy::Entity + { + public: + /*! + * @brief Constructs a Report object from a JSON string. + * + * @param json JSON string + */ + explicit Report(const string &json); + + /*! + * @brief Constructs an empty Report object. + */ + Report(); + + /*! + * @brief Returns true if an action was taken in response to the + * report + */ + const bool action_taken() const; + + /*! + * @brief Returns the ID of the report + */ + const uint64_t id() const; + }; +} + +#endif // MASTODON_CPP_EASY_REPORT_HPP diff --git a/src/easy/results.cpp b/src/easy/results.cpp new file mode 100644 index 0000000..59c5cea --- /dev/null +++ b/src/easy/results.cpp @@ -0,0 +1,52 @@ +/* This file is part of mastodon-cpp. + * Copyright © 2018 tastytea + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include "results.hpp" +#include "macros.hpp" + +using namespace Mastodon; +using Results = Easy::Results; + +Results::Results(const string &json) +: Entity(json) +{} + +Results::Results() +: Entity() +{} + +const std::vector Results::accounts() const +{ + const Json::Value node = get("accounts"); + if (node.isArray()) + { + std::vector vec; + for (const Json::Value &value : node) + { + vec.push_back(Easy::Account(value.toStyledString())); + } + return vec; + } + + ttdebug << "Could not get data: accounts\n"; + return {}; +} + +const std::vector Results::hashtags() const +{ + return get_vector("hashtags"); +} diff --git a/src/easy/results.hpp b/src/easy/results.hpp new file mode 100644 index 0000000..b865a3e --- /dev/null +++ b/src/easy/results.hpp @@ -0,0 +1,74 @@ +/* This file is part of mastodon-cpp. + * Copyright © 2018 tastytea + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef MASTODON_CPP_EASY_RESULTS_HPP +#define MASTODON_CPP_EASY_RESULTS_HPP + +#include +#include + +// If we are compiling mastodon-cpp, use another include path +#ifdef MASTODON_CPP + #include "mastodon-cpp.hpp" + #include "easy.hpp" + #include "account.hpp" +#else + #include + #include + #include +#endif + +using std::string; +using std::uint64_t; + +namespace Mastodon +{ + /*! + * @brief Class to hold results + */ + class Easy::Results : public Easy::Entity + { + public: + /*! + * @brief Constructs a Result object from a JSON string. + * + * @param json JSON string + */ + explicit Results(const string &json); + + /*! + * @brief Constructs an empty Results object. + */ + Results(); + + /*! + * @brief Returns an array of matched Accounts + */ + const std::vector accounts() const; + + /*! + * @brief Returns an array of matched Statuses + */ + // const std::vector statuses() const; + + /*! + * @brief Returns an array of matched hashtags + */ + const std::vector hashtags() const; + }; +} + +#endif // MASTODON_CPP_EASY_RESULTS_HPP