From aceb3cc33ee78cce1077252aff8a8808a3195ff1 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 31 May 2016 09:55:58 -0400 Subject: Added ability to get configuration --- src/configuration.cpp | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/configuration.cpp (limited to 'src/configuration.cpp') diff --git a/src/configuration.cpp b/src/configuration.cpp new file mode 100644 index 0000000..63464ed --- /dev/null +++ b/src/configuration.cpp @@ -0,0 +1,109 @@ +#include "configuration.h" +#include +#include + +using nlohmann::json; + +namespace twitter { + + configuration::configuration() + { + _valid = false; + } + + configuration::configuration(std::string data) + { + _valid = true; + + auto _data = json::parse(data); + + _characters_reserved_per_media = _data.at("characters_reserved_per_media"); + _dm_text_character_limit = _data.at("dm_text_character_limit"); + _max_media_per_upload = _data.at("max_media_per_upload"); + _photo_size_limit = _data.at("photo_size_limit"); + _short_url_length = _data.at("short_url_length"); + _short_https_url_length = _data.at("short_url_length_https"); + + for (json::iterator sizedata = _data.at("photo_sizes").begin(); sizedata != _data.at("photo_sizes").end(); ++sizedata) + { + photosize size; + size.height = sizedata.value().at("h"); + size.width = sizedata.value().at("w"); + if (sizedata.value().at("resize") == "fit") + { + size.resize = resizetype::fit; + } else { + size.resize = resizetype::crop; + } + + _photo_sizes[sizedata.key()] = size; + } + + for (auto path : _data.at("non_username_paths")) + { + _non_username_paths.insert(path.get()); + } + } + + size_t configuration::getCharactersReservedPerMedia() const + { + assert(_valid); + + return _characters_reserved_per_media; + } + + size_t configuration::getDirectMessageCharacterLimit() const + { + assert(_valid); + + return _dm_text_character_limit; + } + + size_t configuration::getMaxMediaPerUpload() const + { + assert(_valid); + + return _max_media_per_upload; + } + + size_t configuration::getPhotoSizeLimit() const + { + assert(_valid); + + return _photo_size_limit; + } + + std::map configuration::getPhotoSizes() const + { + assert(_valid); + + return _photo_sizes; + } + + size_t configuration::getShortUrlLength() const + { + assert(_valid); + + return _short_url_length; + } + + size_t configuration::getShortHttpsUrlLength() const + { + assert(_valid); + + return _short_https_url_length; + } + + std::set configuration::getNonUsernamePaths() const + { + assert(_valid); + + return _non_username_paths; + } + + configuration::operator bool() const + { + return _valid; + } + +}; -- cgit 1.4.1