/* 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 "pushsubscription.hpp" using namespace Mastodon; using PushSubscription = Easy::PushSubscription; PushSubscription::PushSubscription(const string &json) : Entity(json) {} const uint_fast64_t PushSubscription::id() const { return stouint64(get_string("id")); } PushSubscription::PushSubscription() : Entity() {} const bool PushSubscription::valid() const { const std::vector attributes = {{ "id", "endpoint", "server_key" }}; return Entity::check_valid(attributes); } const string PushSubscription::endpoint() const { return get_string("endpoint"); } const string PushSubscription::server_key() const { return get_string("server_key"); } const Easy::alertmap PushSubscription::alerts() const { alertmap alerts; const Json::Value node = get("alerts"); for (auto it = node.begin(); it != node.end(); ++it) { const string &str = it.name(); Easy::notification_type type; if (str.compare("mention") == 0) { type = notification_type::Mention; } else if (str.compare("reblog") == 0) { type = notification_type::Reblog; } else if (str.compare("favourite") == 0) { type = notification_type::Favourite; } else if (str.compare("follow") == 0) { type = notification_type::Follow; } else { type = notification_type::Undefined; } alerts.insert({{ type, s_to_b(it->asString()) }}); } return alerts; } const bool PushSubscription::s_to_b(const string &str) const { if (str.compare("true") == 0) { return true; } else { return false; } }