added Attachment class
This commit is contained in:
parent
a1c1257c2d
commit
d2398008e8
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.7)
|
cmake_minimum_required (VERSION 3.7)
|
||||||
project (mastodon-cpp
|
project (mastodon-cpp
|
||||||
VERSION 0.7.1
|
VERSION 0.7.2
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* This file is part of mastodon-cpp.
|
/* This file is part of mastodon-cpp.
|
||||||
* Copyright © 2018 tastytea <tastytea@tastytea.de>
|
* Copyright © 2018 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
|
@ -177,6 +177,28 @@ const bool Account::locked() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool Account::has_moved() const
|
||||||
|
{
|
||||||
|
if (_tree["moved"].isObject())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Account Account::moved() const
|
||||||
|
{
|
||||||
|
if (has_moved())
|
||||||
|
{
|
||||||
|
// TODO: Find an account with this node and test
|
||||||
|
return Account(_tree["moved"].toStyledString());
|
||||||
|
}
|
||||||
|
|
||||||
|
ttdebug << "Could not get account data: moved\n";
|
||||||
|
return Account("");
|
||||||
|
}
|
||||||
|
|
||||||
const string Account::note() const
|
const string Account::note() const
|
||||||
{
|
{
|
||||||
if (_tree["note"].isString())
|
if (_tree["note"].isString())
|
||||||
|
|
128
src/easy/attachment.cpp
Normal file
128
src/easy/attachment.cpp
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
/* 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 <jsoncpp/json/json.h>
|
||||||
|
#include "easy.hpp"
|
||||||
|
#include "macros.hpp"
|
||||||
|
|
||||||
|
using namespace Mastodon;
|
||||||
|
using Attachment = Easy::Attachment;
|
||||||
|
using std::string;
|
||||||
|
|
||||||
|
Attachment::Attachment(const string &json)
|
||||||
|
{
|
||||||
|
std::stringstream ss(json);
|
||||||
|
ss >> _tree;
|
||||||
|
|
||||||
|
if (_tree.isNull())
|
||||||
|
{
|
||||||
|
std::cerr << "ERROR: Could not build Attachment from JSON string\n";
|
||||||
|
ttdebug << "String was: " << json << '\n';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_valid = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool Attachment::valid() const
|
||||||
|
{
|
||||||
|
return _valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
const string Attachment::description() const
|
||||||
|
{
|
||||||
|
if (_tree["description"].isString())
|
||||||
|
{
|
||||||
|
return _tree["description"].asString();
|
||||||
|
}
|
||||||
|
|
||||||
|
ttdebug << "Could not get attachment data: description\n";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::uint64_t Attachment::id() const
|
||||||
|
{
|
||||||
|
if (_tree["id"].isUInt64())
|
||||||
|
{
|
||||||
|
return _tree["id"].asUInt64();
|
||||||
|
}
|
||||||
|
|
||||||
|
ttdebug << "Could not get attachment data: id\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const string Attachment::preview_url() const
|
||||||
|
{
|
||||||
|
if (_tree["preview_url"].isString())
|
||||||
|
{
|
||||||
|
return _tree["preview_url"].asString();
|
||||||
|
}
|
||||||
|
|
||||||
|
ttdebug << "Could not get attachment data: preview_url\n";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
const string Attachment::remote_url() const
|
||||||
|
{
|
||||||
|
if (_tree["remote_url"].isString())
|
||||||
|
{
|
||||||
|
return _tree["remote_url"].asString();
|
||||||
|
}
|
||||||
|
|
||||||
|
ttdebug << "Could not get attachment data: remote_url\n";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
const string Attachment::text_url() const
|
||||||
|
{
|
||||||
|
if (_tree["text_url"].isString())
|
||||||
|
{
|
||||||
|
return _tree["text_url"].asString();
|
||||||
|
}
|
||||||
|
|
||||||
|
ttdebug << "Could not get attachment data: text_url\n";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
const Easy::attachment_type Attachment::type() const
|
||||||
|
{
|
||||||
|
const string strtype = _tree["type"].asString();
|
||||||
|
if (strtype.compare("image"))
|
||||||
|
return attachment_type::image;
|
||||||
|
else if (strtype.compare("video"))
|
||||||
|
return attachment_type::video;
|
||||||
|
else if (strtype.compare("gifv"))
|
||||||
|
return attachment_type::gifv;
|
||||||
|
else if (strtype.compare("unknown"))
|
||||||
|
return attachment_type::unknown;
|
||||||
|
|
||||||
|
ttdebug << "Could not get account data: type\n";
|
||||||
|
return attachment_type::unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
const string Attachment::url() const
|
||||||
|
{
|
||||||
|
if (_tree["url"].isString())
|
||||||
|
{
|
||||||
|
return _tree["url"].asString();
|
||||||
|
}
|
||||||
|
|
||||||
|
ttdebug << "Could not get attachment data: url\n";
|
||||||
|
return "";
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/* This file is part of mastodon-cpp.
|
/* This file is part of mastodon-cpp.
|
||||||
* Copyright © 2018 tastytea <tastytea@tastytea.de>
|
* Copyright © 2018 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
|
|
|
@ -180,7 +180,7 @@ public:
|
||||||
const visibility privacy() const;
|
const visibility privacy() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns if media is amrked as sensitive by default
|
* @brief Returns if media is marked as sensitive by default
|
||||||
*/
|
*/
|
||||||
const bool sensitive() const;
|
const bool sensitive() const;
|
||||||
|
|
||||||
|
@ -222,14 +222,41 @@ public:
|
||||||
*/
|
*/
|
||||||
const bool valid() const;
|
const bool valid() const;
|
||||||
|
|
||||||
const uint64_t id() const;
|
/*!
|
||||||
const attachment_type type() const;
|
* @brief Returns the image description
|
||||||
const string url() const;
|
*/
|
||||||
const string remote_url() const;
|
|
||||||
const string preview_url() const;
|
|
||||||
const string text_url() const;
|
|
||||||
const string description() const;
|
const string description() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns the ID of the attachment
|
||||||
|
*/
|
||||||
|
const uint64_t id() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns the URL of the preview image
|
||||||
|
*/
|
||||||
|
const string preview_url() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns the remote URL of the original image
|
||||||
|
*/
|
||||||
|
const string remote_url() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns shorter URL for the image
|
||||||
|
*/
|
||||||
|
const string text_url() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns attachment type
|
||||||
|
*/
|
||||||
|
const attachment_type type() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns URL of the locally hosted version of the image
|
||||||
|
*/
|
||||||
|
const string url() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Json::Value _tree;
|
Json::Value _tree;
|
||||||
bool _valid;
|
bool _valid;
|
||||||
|
|
Reference in New Issue
Block a user