From d4708e538f538386d7fa08e73eaea1f59769f0fd Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 31 Mar 2018 02:54:00 +0200 Subject: [PATCH] Added Easy::Relationship --- CMakeLists.txt | 2 +- src/easy/all.hpp | 2 + src/easy/easy.hpp | 19 ++++---- src/easy/relationship.cpp | 68 ++++++++++++++++++++++++++++ src/easy/relationship.hpp | 95 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 176 insertions(+), 10 deletions(-) create mode 100644 src/easy/relationship.cpp create mode 100644 src/easy/relationship.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9eb853b..ced92f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (mastodon-cpp - VERSION 0.7.9 + VERSION 0.7.10 LANGUAGES CXX ) diff --git a/src/easy/all.hpp b/src/easy/all.hpp index 68a40e4..339f8cc 100644 --- a/src/easy/all.hpp +++ b/src/easy/all.hpp @@ -29,6 +29,7 @@ #include "easy/list.hpp" #include "easy/mention.hpp" //#include "easy/notification.hpp" + #include "easy/relationship.hpp" #else #include #include @@ -40,6 +41,7 @@ #include #include //#include + #include #endif #endif // MASTODON_CPP_EASY_ALL_HPP diff --git a/src/easy/easy.hpp b/src/easy/easy.hpp index 233b0f8..89ae4f7 100644 --- a/src/easy/easy.hpp +++ b/src/easy/easy.hpp @@ -131,29 +131,30 @@ public: */ const string error() const; + protected: /*! - * @brief Returns the value of node as Json::Value - * + * @brief Returns the value of key as Json::Value + * * Returns an empty object on error. */ const Json::Value get(const string &key) const; /*! - * @brief Returns the value of node as std::string + * @brief Returns the value of key as std::string * * returns "" on error. */ const string get_string(const string &key) const; /*! - * @brief Returns the value of node as std::uint64_t + * @brief Returns the value of key as std::uint64_t * * Returns 0 on error. */ const uint64_t get_uint64(const string &key) const; /*! - * @brief Returns the value of node as double + * @brief Returns the value of key as double * * Returns 0.0 on error. */ @@ -161,27 +162,26 @@ public: // TODO: Investigate if uint8_t would be better /*! - * @brief Returns the value of node as bool + * @brief Returns the value of key as bool * * Returns false on error. */ const bool get_bool(const string &key) const; /*! - * @brief Returns the value of node as time_point + * @brief Returns the value of key as time_point * * Returns clocks epoch on error. */ const system_clock::time_point get_time_point(const string &key) const; /*! - * @brief Returns the value of node as vector + * @brief Returns the value of key as vector * * Returns false on error. */ const std::vector get_vector(const string &key) const; - protected: Json::Value _tree; bool _valid; }; @@ -195,6 +195,7 @@ public: class List; class Mention; class Notification; + class Relationship; }; } diff --git a/src/easy/relationship.cpp b/src/easy/relationship.cpp new file mode 100644 index 0000000..77b3a68 --- /dev/null +++ b/src/easy/relationship.cpp @@ -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 . + */ + +#include "relationship.hpp" + +using namespace Mastodon; +using Relationship = Easy::Relationship; + +Relationship::Relationship(const string &json) +: Entity(json) +{} + +Relationship::Relationship() +: Entity() +{} + +const bool Relationship::blocking() const +{ + return get_bool("blocking"); +} + +const bool Relationship::domain_blocking() const +{ + return get_bool("domain_blocking"); +} + +const bool Relationship::followed_by() const +{ + return get_bool("followed_by"); +} + +const bool Relationship::following() const +{ + return get_bool("following"); +} + +const uint64_t Relationship::id() const +{ + return get_uint64("id"); +} + +const bool Relationship::muting() const +{ + return get_bool("muting"); +} + +const bool Relationship::muting_notifications() const +{ + return get_bool("muting_notifications"); +} + +const bool Relationship::requested() const +{ + return get_bool("requested"); +} diff --git a/src/easy/relationship.hpp b/src/easy/relationship.hpp new file mode 100644 index 0000000..85d5625 --- /dev/null +++ b/src/easy/relationship.hpp @@ -0,0 +1,95 @@ +/* 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_RELATIONSHIP_HPP +#define MASTODON_CPP_EASY_RELATIONSHIP_HPP + +#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::uint64_t; + +namespace Mastodon +{ + /*! + * @brief Class to hold relationships + */ + class Easy::Relationship : public Easy::Entity + { + public: + /*! + * @brief Constructs a Relationship object from a JSON string. + * + * @param json JSON string + */ + explicit Relationship(const string &json); + + /*! + * @brief Constructs an empty Relationship object. + */ + Relationship(); + + /*! + * @brief Returns true if the user is blocking the account + */ + const bool blocking() const; + + /*! + * @brief Returns true if the user is blocking the account's domain + */ + const bool domain_blocking() const; + + /*! + * @brief Returns true if the user is being followed by the account + */ + const bool followed_by() const; + + /*! + * @brief Returns true if the user is being following the account + */ + const bool following() const; + + /*! + * @brief Returns the target account ID + */ + const uint64_t id() const; + + /*! + * @brief Returns true if the user is muting the account + */ + const bool muting() const; + + /*! + * @brief Returns true if the user is also muting notifications + */ + const bool muting_notifications() const; + + /*! + * @brief Returns true if the user has requested to follow the account + */ + const bool requested() const; + }; +} + +#endif // MASTODON_CPP_EASY_RELATIONSHIP_HPP