This repository has been archived on 2020-05-10. You can view files and clone it, but cannot push or open issues or pull requests.
mastodon-cpp/src/easy/entities/instance.cpp

101 lines
2.2 KiB
C++
Raw Normal View History

2018-03-30 20:08:47 +02:00
/* This file is part of mastodon-cpp.
2019-03-20 06:15:43 +01:00
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
2018-03-30 20:08:47 +02:00
*
* 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>
2018-03-30 20:08:47 +02:00
#include "instance.hpp"
#include "account.hpp"
2019-02-22 11:35:06 +01:00
#include "debug.hpp"
2018-03-30 20:08:47 +02:00
using namespace Mastodon;
using Instance = Easy::Instance;
2018-12-04 11:26:28 +01:00
bool Instance::valid() const
{
const std::vector<string> attributes =
{{
"uri",
"title",
"description",
"email",
"version",
"urls",
"languages",
"contact_account"
}};
return Entity::check_valid(attributes);
}
2018-03-30 20:08:47 +02:00
const Easy::Account Instance::contact_account() const
{
const Json::Value node = get("contact_account");
2018-03-30 20:08:47 +02:00
if (node.isObject())
{
return Easy::Account(node.toStyledString());
}
ttdebug << "Could not get data: contact_account\n";
2018-03-30 20:16:31 +02:00
return Easy::Account();
2018-03-30 20:08:47 +02:00
}
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");
}
2018-04-01 01:58:03 +02:00
const string Instance::streaming_api() const
2018-03-30 20:08:47 +02:00
{
2018-04-01 01:58:03 +02:00
return get_string("urls.streaming_api");
2018-03-30 20:08:47 +02:00
}
2018-12-04 09:42:26 +01:00
uint64_t Instance::max_toot_chars() const
2018-12-04 09:42:26 +01:00
{
const uint64_t max_chars = get_uint64("max_toot_chars");
2018-12-04 09:42:26 +01:00
if (was_set())
{
return max_chars;
}
else
{
return 500;
}
}