Made Easy::Status writable (#1)
the build was successful Details

This commit is contained in:
tastytea 2018-06-13 23:55:19 +02:00
parent bb697639ef
commit a56f6f0340
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
4 changed files with 115 additions and 5 deletions

View File

@ -342,6 +342,11 @@ public:
*/ */
const std::vector<string> get_vector(const string &key) const; const std::vector<string> get_vector(const string &key) const;
/*!
* @brief Sets the value of key
*/
const void set(const string &key, const Json::Value &value);
const std::uint_fast64_t stouint64(const string &str) const; const std::uint_fast64_t stouint64(const string &str) const;
private: private:

View File

@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <iostream>
#include <jsoncpp/json/json.h> #include <jsoncpp/json/json.h>
#include "status.hpp" #include "status.hpp"
#include "macros.hpp" #include "macros.hpp"
@ -63,6 +64,12 @@ const string Status::content() const
return get_string("content"); return get_string("content");
} }
Status Status::content(const string &content)
{
set("content", Json::Value(content));
return *this;
}
const std::vector<Easy::Emoji> Status::emojis() const const std::vector<Easy::Emoji> Status::emojis() const
{ {
const Json::Value node = get("emojis"); const Json::Value node = get("emojis");
@ -100,6 +107,12 @@ const uint_fast64_t Status::in_reply_to_id() const
return stouint64(get_string("in_reply_to_id")); return stouint64(get_string("in_reply_to_id"));
} }
Status Status::in_reply_to_id(const uint_fast64_t &in_reply_to_id)
{
set("in_reply_to_id", Json::Value(std::to_string(in_reply_to_id)));
return *this;
}
const uint_fast64_t Status::in_reply_to_account_id() const const uint_fast64_t Status::in_reply_to_account_id() const
{ {
return stouint64(get_string("in_reply_to_account_id")); return stouint64(get_string("in_reply_to_account_id"));
@ -110,6 +123,12 @@ const string Status::language() const
return get_string("language"); return get_string("language");
} }
Status Status::language(const string &language)
{
set("language", Json::Value(language));
return *this;
}
const std::vector<Easy::Attachment> Status::media_attachments() const const std::vector<Easy::Attachment> Status::media_attachments() const
{ {
const Json::Value node = get("media_attachments"); const Json::Value node = get("media_attachments");
@ -127,6 +146,20 @@ const std::vector<Easy::Attachment> Status::media_attachments() const
return {}; return {};
} }
Status Status::media_attachments
(const std::vector<Attachment> &media_attachments)
{
// FIXME: Needs writable Easy::Attachment()
Json::Value jsonarray(Json::arrayValue);
for (const Attachment &att : media_attachments)
{
jsonarray.append(att.to_object());
}
set("media_attachments", jsonarray);
return *this;
}
const std::vector<Easy::Mention> Status::mentions() const const std::vector<Easy::Mention> Status::mentions() const
{ {
const Json::Value node = get("mentions"); const Json::Value node = get("mentions");
@ -154,7 +187,7 @@ const bool Status::pinned() const
return get_bool("pinned"); return get_bool("pinned");
} }
const Easy::Status Status::reblog() const const Status Status::reblog() const
{ {
const Json::Value node = get("reblog"); const Json::Value node = get("reblog");
if (node.isObject()) if (node.isObject())
@ -181,11 +214,23 @@ const bool Status::sensitive() const
return get_bool("sensitive"); return get_bool("sensitive");
} }
Status Status::sensitive(const bool &sensitive)
{
set("sensitive", Json::Value(sensitive));
return *this;
}
const string Status::spoiler_text() const const string Status::spoiler_text() const
{ {
return get_string("spoiler_text"); return get_string("spoiler_text");
} }
Status Status::spoiler_text(const string &spoiler_text)
{
set("spoiler_text", Json::Value(spoiler_text));
return *this;
}
const std::vector<Easy::Tag> Status::tags() const const std::vector<Easy::Tag> Status::tags() const
{ {
const Json::Value node = get("tags"); const Json::Value node = get("tags");
@ -228,3 +273,27 @@ const Easy::visibility_type Status::visibility() const
ttdebug << "Could not get data: visibility\n"; ttdebug << "Could not get data: visibility\n";
return visibility_type::Undefined; return visibility_type::Undefined;
} }
Status Status::visibility(const visibility_type &visibility)
{
switch (visibility)
{
case visibility_type::Direct:
set("visibility", "direct");
break;
case visibility_type::Private:
set("visibility", "private");
break;
case visibility_type::Unlisted:
set("visibility", "unlisted");
break;
case visibility_type::Public:
set("visibility", "public");
break;
default:
std::cerr << "WARNING: setting visibility to Undefined "
"has no effect.\n";
break;
};
return *this;
}

View File

@ -68,12 +68,12 @@ namespace Mastodon
Status(); Status();
/*! /*!
* @brief Returns an array of matched accounts * @brief Returns an array of matched accounts.
*/ */
const Account account() const; const Account account() const;
/*! /*!
* @brief Returns application from which the status was posted * @brief Returns application from which the status was posted.
*/ */
const Application application() const; const Application application() const;
@ -87,6 +87,11 @@ namespace Mastodon
*/ */
const string content() const; const string content() const;
/*!
* @brief Sets content of status
*/
Status content(const string &content);
/*! /*!
* @brief Returns an array of emojis * @brief Returns an array of emojis
*/ */
@ -112,6 +117,11 @@ namespace Mastodon
*/ */
const uint_fast64_t in_reply_to_id() const; const uint_fast64_t in_reply_to_id() const;
/*!
* @brief Sets the ID of the status it replies to
*/
Status in_reply_to_id(const uint_fast64_t &in_reply_to_id);
/*! /*!
* @brief Returns the ID of the account it replies to * @brief Returns the ID of the account it replies to
*/ */
@ -122,11 +132,22 @@ namespace Mastodon
*/ */
const string language() const; const string language() const;
/*!
* @brief Sets the language of the status
*/
Status language(const string &language);
/*! /*!
* @brief Returns the attachments * @brief Returns the attachments
*/ */
const std::vector<Attachment> media_attachments() const; const std::vector<Attachment> media_attachments() const;
/*!
* @brief Sets the attachments
*/
Status media_attachments
(const std::vector<Attachment> &media_attachments);
/*! /*!
* @brief Returns the mentions * @brief Returns the mentions
*/ */
@ -162,11 +183,21 @@ namespace Mastodon
*/ */
const bool sensitive() const; const bool sensitive() const;
/*!
* @brief Sets sensitive flag for attachments
*/
Status sensitive(const bool &sensitive);
/*! /*!
* @brief Returns the spoiler text * @brief Returns the spoiler text
*/ */
const string spoiler_text() const; const string spoiler_text() const;
/*!
* @brief Sets the spoiler text
*/
Status spoiler_text(const string &spoiler_text);
/*! /*!
* @brief Returns the tags * @brief Returns the tags
*/ */
@ -188,9 +219,9 @@ namespace Mastodon
const visibility_type visibility() const; const visibility_type visibility() const;
/*! /*!
* @brief Returns the * @brief Sets the visibility of the status
*/ */
Status visibility(const visibility_type &visibility);
}; };
} }

View File

@ -223,6 +223,11 @@ const std::vector<string> Easy::Entity::get_vector(const string &key) const
return {}; return {};
} }
const void Easy::Entity::set(const string &key, const Json::Value &value)
{
_tree[key] = value;
}
const std::uint_fast64_t Easy::Entity::stouint64(const string &str) const const std::uint_fast64_t Easy::Entity::stouint64(const string &str) const
{ {
if (str == "") if (str == "")