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

114 lines
2.3 KiB
C++
Raw Normal View History

2018-03-25 19:43:48 +02:00
/* 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 "card.hpp"
#include "macros.hpp"
using namespace Mastodon;
using Card = Easy::Card;
Card::Card(const string &json)
: Entity(json)
2018-03-30 20:16:31 +02:00
{}
Card::Card()
: Entity()
{}
2018-03-25 19:43:48 +02:00
2018-12-04 11:26:28 +01:00
bool Card::valid() const
{
const std::vector<string> attributes =
{{
"url",
"title",
"description",
"type"
}};
return Entity::check_valid(attributes);
}
2018-03-25 19:43:48 +02:00
const string Card::author_name() const
{
2018-03-25 22:46:38 +02:00
return get_string("author_name");
2018-03-25 19:43:48 +02:00
}
const string Card::author_url() const
{
2018-03-25 22:46:38 +02:00
return get_string("author_url");
2018-03-25 19:43:48 +02:00
}
const string Card::description() const
{
2018-03-25 22:46:38 +02:00
return get_string("description");
2018-03-25 19:43:48 +02:00
}
2018-12-04 11:26:28 +01:00
uint_fast64_t Card::height() const
2018-03-25 19:43:48 +02:00
{
2018-03-25 22:46:38 +02:00
return get_uint64("height");
2018-03-25 19:43:48 +02:00
}
const string Card::html() const
{
2018-03-25 22:46:38 +02:00
return get_string("html");
2018-03-25 19:43:48 +02:00
}
const string Card::image() const
{
2018-03-25 22:46:38 +02:00
return get_string("image");
2018-03-25 19:43:48 +02:00
}
const string Card::provider_name() const
{
2018-03-25 22:46:38 +02:00
return get_string("provider_name");
2018-03-25 19:43:48 +02:00
}
const string Card::provider_url() const
{
2018-03-25 22:46:38 +02:00
return get_string("provider_url");
2018-03-25 19:43:48 +02:00
}
const string Card::title() const
{
2018-03-25 22:46:38 +02:00
return get_string("title");
2018-03-25 19:43:48 +02:00
}
2018-12-04 11:26:28 +01:00
Easy::card_type Card::type() const
2018-03-25 19:43:48 +02:00
{
2018-03-25 22:46:38 +02:00
const string strtype = get_string("type");
if (strtype.compare("link") == 0)
2018-04-01 05:14:02 +02:00
return card_type::Link;
2018-03-25 22:46:38 +02:00
else if (strtype.compare("photo") == 0)
2018-04-01 05:14:02 +02:00
return card_type::Photo;
2018-03-25 22:46:38 +02:00
else if (strtype.compare("video") == 0)
2018-04-01 05:14:02 +02:00
return card_type::Video;
2018-03-25 22:46:38 +02:00
else if (strtype.compare("rich") == 0)
2018-04-01 05:14:02 +02:00
return card_type::Rich;
2018-03-25 22:46:38 +02:00
2018-03-31 00:12:34 +02:00
ttdebug << "Could not get data: type\n";
2018-04-01 05:14:02 +02:00
return card_type::Undefined;
2018-03-25 19:43:48 +02:00
}
const string Card::url() const
{
2018-03-25 22:46:38 +02:00
return get_string("url");
2018-03-25 19:43:48 +02:00
}
2018-12-04 11:26:28 +01:00
uint_fast64_t Card::width() const
2018-03-25 19:43:48 +02:00
{
2018-03-25 22:46:38 +02:00
return get_uint64("width");
2018-03-25 19:43:48 +02:00
}