#include "configuration.h" #include #include #include "codes.h" namespace twitter { configuration::configuration(std::string data) try { auto json_data = nlohmann::json::parse(data); _characters_reserved_per_media = json_data["characters_reserved_per_media"].get(); _dm_text_character_limit = json_data["dm_text_character_limit"].get(); _max_media_per_upload = json_data["max_media_per_upload"].get(); _photo_size_limit = json_data["photo_size_limit"].get(); _short_url_length = json_data["short_url_length"].get(); _short_https_url_length = json_data["short_url_length_https"].get(); for (auto sizedata = std::begin(json_data["photo_sizes"]); sizedata != std::end(json_data["photo_sizes"]); ++sizedata) { photosize size; size.height = sizedata.value()["h"].get(); size.width = sizedata.value()["w"].get(); if (sizedata.value()["resize"].get() == "fit") { size.resize = resizetype::fit; } else { size.resize = resizetype::crop; } _photo_sizes[sizedata.key()] = size; } for (auto path : json_data["non_username_paths"]) { _non_username_paths.insert(path.get()); } } catch (const std::invalid_argument& error) { std::throw_with_nested(malformed_object("configuration", data)); } catch (const std::domain_error& error) { std::throw_with_nested(malformed_object("configuration", data)); } };