Add Easy::Report and Easy::Results (incomplete)

This commit is contained in:
tastytea 2018-03-31 03:28:18 +02:00
parent d4708e538f
commit 06ab515f17
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
9 changed files with 244 additions and 2 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project (mastodon-cpp
VERSION 0.7.10
VERSION 0.7.11
LANGUAGES CXX
)

View File

@ -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 <mastodon-cpp/easy.hpp>
#include <mastodon-cpp/easy/account.hpp>
@ -42,6 +44,8 @@
#include <mastodon-cpp/easy/mention.hpp>
//#include <mastodon-cpp/easy/notification.hpp>
#include <mastodon-cpp/easy/relationship.hpp>
#include <mastodon-cpp/easy/report.hpp>
//#include <mastodon-cpp/easy/results.hpp>
#endif
#endif // MASTODON_CPP_EASY_ALL_HPP

View File

@ -196,6 +196,8 @@ public:
class Mention;
class Notification;
class Relationship;
class Report;
class Results;
};
}

View File

@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <jsoncpp/json/json.h>
#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());

View File

@ -17,6 +17,7 @@
#ifndef MASTODON_CPP_EASY_RELATIONSHIP_HPP
#define MASTODON_CPP_EASY_RELATIONSHIP_HPP
#include <string>
#include <cstdint>
// If we are compiling mastodon-cpp, use another include path
@ -28,6 +29,7 @@
#include <mastodon-cpp/easy.hpp>
#endif
using std::string;
using std::uint64_t;
namespace Mastodon

39
src/easy/report.cpp Normal file
View File

@ -0,0 +1,39 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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");
}

68
src/easy/report.hpp Normal file
View File

@ -0,0 +1,68 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_REPORT_HPP
#define MASTODON_CPP_EASY_REPORT_HPP
#include <string>
#include <cstdint>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy.hpp>
#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

52
src/easy/results.cpp Normal file
View File

@ -0,0 +1,52 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <jsoncpp/json/json.h>
#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<Easy::Account> Results::accounts() const
{
const Json::Value node = get("accounts");
if (node.isArray())
{
std::vector<Easy::Account> 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<string> Results::hashtags() const
{
return get_vector("hashtags");
}

74
src/easy/results.hpp Normal file
View File

@ -0,0 +1,74 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_RESULTS_HPP
#define MASTODON_CPP_EASY_RESULTS_HPP
#include <string>
#include <vector>
// 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 <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy.hpp>
#include <mastodon-cpp/account.hpp>
#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<Account> accounts() const;
/*!
* @brief Returns an array of matched Statuses
*/
// const std::vector<Status> statuses() const;
/*!
* @brief Returns an array of matched hashtags
*/
const std::vector<string> hashtags() const;
};
}
#endif // MASTODON_CPP_EASY_RESULTS_HPP