Added Easy::Instance
This commit is contained in:
parent
1a0a02d619
commit
18aabc454f
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required (VERSION 3.7)
|
||||
project (mastodon-cpp
|
||||
VERSION 0.7.6
|
||||
VERSION 0.7.7
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
|
|
|
@ -24,10 +24,12 @@
|
|||
#include "easy/card.hpp"
|
||||
//#include "easy/context.hpp"
|
||||
#include "easy/emoji.hpp"
|
||||
#include "easy/instance.hpp"
|
||||
#else
|
||||
#include <mastodon-cpp/easy.hpp>
|
||||
#include <mastodon-cpp/easy/account.hpp>
|
||||
#include <mastodon-cpp/easy/attachment.hpp>
|
||||
#include <mastodon-cpp/easy/instance.hpp>
|
||||
#include <mastodon-cpp/easy/card.hpp>
|
||||
//#include <mastodon-cpp/easy/context.hpp>
|
||||
#include <mastodon-cpp/easy/emoji.hpp>
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <ctime>
|
||||
#include <iomanip> // get_time
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <jsoncpp/json/json.h>
|
||||
#include "easy.hpp"
|
||||
#include "macros.hpp"
|
||||
|
@ -174,3 +175,20 @@ const system_clock::time_point
|
|||
// Return clocks epoch
|
||||
return system_clock::time_point();
|
||||
}
|
||||
|
||||
const std::vector<string> Easy::Entity::get_vector(const string &key) const
|
||||
{
|
||||
const Json::Value node = get(key);
|
||||
|
||||
if (node.isArray())
|
||||
{
|
||||
std::vector<string> vec;
|
||||
for (const Json::Value &value : node)
|
||||
{
|
||||
vec.push_back(value.asString());
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
#include <jsoncpp/json/json.h>
|
||||
|
||||
// If we are compiling mastodon-cpp, use another include path
|
||||
|
@ -106,7 +107,7 @@ public:
|
|||
/*!
|
||||
* @brief Constructs an empty Entity object.
|
||||
*/
|
||||
explicit Entity();
|
||||
Entity();
|
||||
|
||||
/*!
|
||||
* @brief Returns true if the Entity holds valid data
|
||||
|
@ -161,6 +162,13 @@ public:
|
|||
*/
|
||||
const system_clock::time_point get_time_point(const string &key) const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the value of node as vector
|
||||
*
|
||||
* Returns false on error.
|
||||
*/
|
||||
const std::vector<string> get_vector(const string &key) const;
|
||||
|
||||
protected:
|
||||
Json::Value _tree;
|
||||
bool _valid;
|
||||
|
|
83
src/easy/instance.cpp
Normal file
83
src/easy/instance.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
/* 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 <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <jsoncpp/json/json.h>
|
||||
#include "instance.hpp"
|
||||
#include "account.hpp"
|
||||
#include "macros.hpp"
|
||||
|
||||
using namespace Mastodon;
|
||||
using Instance = Easy::Instance;
|
||||
using std::string;
|
||||
using std::uint64_t;
|
||||
|
||||
Instance::Instance(const string &json)
|
||||
: Entity(json)
|
||||
{}
|
||||
|
||||
Instance::Instance()
|
||||
: Entity()
|
||||
{}
|
||||
|
||||
const Easy::Account Instance::contact_account() const
|
||||
{
|
||||
const Json::Value node = _tree["contact_account"];
|
||||
if (node.isObject())
|
||||
{
|
||||
return Easy::Account(node.toStyledString());
|
||||
}
|
||||
|
||||
ttdebug << "Could not get data: contact_account\n";
|
||||
return Easy::Account("");
|
||||
}
|
||||
|
||||
const string Instance::description() const
|
||||
{
|
||||
return get_string("description");
|
||||
}
|
||||
|
||||
const string Instance::email() const
|
||||
{
|
||||
return get_string("email");
|
||||
}
|
||||
|
||||
const std::vector<string> Instance::languages() const
|
||||
{
|
||||
return get_vector("languages");
|
||||
}
|
||||
|
||||
const string Instance::title() const
|
||||
{
|
||||
return get_string("title");
|
||||
}
|
||||
|
||||
const string Instance::uri() const
|
||||
{
|
||||
return get_string("uri");
|
||||
}
|
||||
|
||||
const string Instance::version() const
|
||||
{
|
||||
return get_string("version");
|
||||
}
|
||||
|
||||
const std::vector<string> Instance::urls() const
|
||||
{
|
||||
return get_vector("urls");
|
||||
}
|
101
src/easy/instance.hpp
Normal file
101
src/easy/instance.hpp
Normal file
|
@ -0,0 +1,101 @@
|
|||
/* 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_INSTANCE_HPP
|
||||
#define MASTODON_CPP_EASY_INSTANCE_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/easy/account.hpp>
|
||||
#endif
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace Mastodon
|
||||
{
|
||||
/*!
|
||||
* @brief Class to hold cards
|
||||
*/
|
||||
class Easy::Instance : public Easy::Entity
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* @brief Constructs an Instance object from a JSON string.
|
||||
*
|
||||
* @param json JSON string
|
||||
*/
|
||||
explicit Instance(const string &json);
|
||||
|
||||
/*!
|
||||
* @brief Constructs an empty Instance object.
|
||||
*/
|
||||
Instance();
|
||||
|
||||
/*!
|
||||
* @brief Returns the Account of the admin or another contact person
|
||||
*/
|
||||
const Account contact_account() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the description of the instance
|
||||
*/
|
||||
const string description() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the email address which can be used to contact the
|
||||
* instance administrator
|
||||
*/
|
||||
const string email() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns a vector of ISO 6391 language codes the instance has
|
||||
* chosen to advertise
|
||||
*/
|
||||
const std::vector<string> languages() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the title of the instance
|
||||
*/
|
||||
const string title() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the URI of the instance
|
||||
*/
|
||||
const string uri() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the version used by the instance
|
||||
*/
|
||||
const string version() const;
|
||||
|
||||
// TODO: Find out what Instance.urls is about
|
||||
/*!
|
||||
* @brief Returns the a vector of URLs for the streaming API (?)
|
||||
*/
|
||||
const std::vector<string> urls() const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // MASTODON_CPP_EASY_INSTANCE_HPP
|
Reference in New Issue
Block a user