diff --git a/CMakeLists.txt b/CMakeLists.txt index 56fddce..7c09166 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (mastodon-cpp - VERSION 0.16.1 + VERSION 0.17.0 LANGUAGES CXX ) diff --git a/src/easy/entities/attachment.cpp b/src/easy/entities/attachment.cpp index b0cc4b7..582e408 100644 --- a/src/easy/entities/attachment.cpp +++ b/src/easy/entities/attachment.cpp @@ -49,6 +49,12 @@ const string Attachment::description() const return get_string("description"); } +Attachment Attachment::description(const string &description) +{ + set("description", Json::Value(description)); + return *this; +} + const std::chrono::duration Attachment::duration() const { const double sec = get_double("meta.original.duration"); @@ -56,6 +62,18 @@ const std::chrono::duration Attachment::duration() const return std::chrono::duration(sec); } +const string Attachment::file() +{ + return get_string("file"); +} + +Attachment Attachment::file(const string &file) +{ + set("file", Json::Value(file)); + return *this; +} + + const std::array Attachment::focus() const { const Json::Value x = get("meta.focus.x"); @@ -72,6 +90,13 @@ const std::array Attachment::focus() const return {}; } +Attachment Attachment::focus(const std::array &focus) +{ + set("meta.focus.x", Json::Value(focus[0])); + set("meta.focus.y", Json::Value(focus[1])); + return *this; +} + const double Attachment::framerate() const { string strframes = get_string("meta.original.frame_rate"); diff --git a/src/easy/entities/attachment.hpp b/src/easy/entities/attachment.hpp index 299fb96..5ec694a 100644 --- a/src/easy/entities/attachment.hpp +++ b/src/easy/entities/attachment.hpp @@ -68,16 +68,40 @@ namespace Mastodon * @brief Returns the bitrate of a video */ const uint_fast64_t bitrate() const; + /*! * @brief Returns the image description */ const string description() const; + /*! + * @brief Sets the image description + * + * @since 0.17.0 + */ + Attachment description(const string &description); + /*! * @brief Returns the duration of a video in seconds */ const std::chrono::duration duration() const; + /*! + * @brief Gets file to upload + * + * @since 0.17.0 + */ + const string file(); + + /*! + * @brief Sets file to upload + * + * @since 0.17.0 + * + * @param file Filename + */ + Attachment file(const string &file); + /*! * @brief Returns the focus point (x, y) * @@ -85,6 +109,15 @@ namespace Mastodon */ const std::array focus() const; + /*! + * @brief Sets the focus point (x, y) + * + * Values are between -1.0 and 1.0. + * + * @since 0.17.0 + */ + Attachment focus(const std::array &focus); + /*! * @brief Returns the framerate of a video in frames per second */ diff --git a/src/easy/entity.cpp b/src/easy/entity.cpp index 09d358e..6d07eaa 100644 --- a/src/easy/entity.cpp +++ b/src/easy/entity.cpp @@ -225,7 +225,40 @@ const std::vector Easy::Entity::get_vector(const string &key) const const void Easy::Entity::set(const string &key, const Json::Value &value) { - _tree[key] = value; + if (key.find('.') == std::string::npos) + { + _tree[key] = value; + return; + } + else + { + std::size_t pos = 0; + string current_key = key; + Json::Value *node = &_tree; + + while ((pos = current_key.find('.')) != std::string::npos) + { + try + { + node = &(*node)[current_key.substr(0, pos)]; + if (node->isNull()) + { + *node = Json::Value(Json::objectValue); + } + current_key = current_key.substr(pos + 1); + } + catch (const Json::LogicError &e) + { + ttdebug << e.what() << '\n'; + goto error; + } + } + (*node)[current_key] = value; + return; + } + + error: + ttdebug << "Could not set data: " << key << '\n'; } const std::uint_fast64_t Easy::Entity::stouint64(const string &str) const