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/tag.cpp

96 lines
2.2 KiB
C++
Raw Normal View History

2018-03-31 04:07:21 +02:00
/* This file is part of mastodon-cpp.
2019-03-20 06:15:43 +01:00
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
2019-03-29 14:44:39 +01:00
*
2018-03-31 04:07:21 +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/>.
*/
2018-06-11 01:39:19 +02:00
#include <sstream>
#include <iomanip>
2019-03-30 23:59:27 +01:00
#include <algorithm>
2018-03-31 04:07:21 +02:00
#include "tag.hpp"
2019-02-22 11:35:06 +01:00
#include "debug.hpp"
2018-03-31 04:07:21 +02:00
using namespace Mastodon;
using Tag = Easy::Tag;
2018-12-04 11:26:28 +01:00
bool Tag::valid() const
{
return Entity::check_valid(
{
"name",
"url"
});
}
2018-03-31 04:07:21 +02:00
const string Tag::name() const
{
2018-03-31 04:29:55 +02:00
return get_string("name");
2018-03-31 04:07:21 +02:00
}
const string Tag::url() const
{
2018-03-31 04:29:55 +02:00
return get_string("url");
2018-03-31 04:07:21 +02:00
}
2018-06-11 01:39:19 +02:00
const std::vector<Tag::History> Tag::history() const
{
const Json::Value node = get("history");
if (node.isArray())
{
std::vector<Easy::Tag::History> vec;
2019-03-30 23:59:27 +01:00
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{ return Easy::Tag::History(value); });
2018-06-11 01:39:19 +02:00
return vec;
}
ttdebug << "Could not get data: history\n";
return {};
}
2018-12-04 11:26:28 +01:00
bool Tag::History::valid() const
{
const std::vector<string> attributes =
{{
"day",
"uses",
"accounts"
}};
return Entity::check_valid(attributes);
}
uint64_t Tag::History::accounts() const
2018-06-11 01:39:19 +02:00
{
return get_uint64("accounts");
2018-06-11 01:39:19 +02:00
}
const Easy::time_type Tag::History::day() const
2018-06-11 01:39:19 +02:00
{
const Json::Value node = get("day");
if (node.isString())
{
std::chrono::seconds seconds(stouint64(node.asString()));
2019-03-29 14:44:39 +01:00
return {system_clock::time_point(seconds)};
2018-06-11 01:39:19 +02:00
}
ttdebug << "Could not get data: day\n";
2019-05-13 21:26:55 +02:00
return Easy::time_type();
2018-06-11 01:39:19 +02:00
}
uint64_t Tag::History::uses() const
2018-06-11 01:39:19 +02:00
{
return get_uint64("uses");
2018-06-11 01:39:19 +02:00
}