From 3e575ac920e87c47805eb2f0a603dfbbfcbc3e9e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 24 Nov 2020 19:38:07 +0100 Subject: Start on mastodon/pleroma --- src/Json.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/Json.cpp (limited to 'src/Json.cpp') diff --git a/src/Json.cpp b/src/Json.cpp new file mode 100644 index 0000000..86703b2 --- /dev/null +++ b/src/Json.cpp @@ -0,0 +1,21 @@ +#include "../include/Json.hpp" + +namespace QuickMedia { + static rapidjson::Value nullValue(rapidjson::kNullType); + const rapidjson::Value& GetMember(const rapidjson::Value &obj, const char *key) { + auto it = obj.FindMember(key); + if(it != obj.MemberEnd()) + return it->value; + return nullValue; + } + + DownloadResult download_json(rapidjson::Document &result, const std::string &url, std::vector additional_args, bool use_tor, bool use_browser_useragent, std::string *err_msg) { + if(download_to_json(url, result, std::move(additional_args), use_tor, use_browser_useragent, err_msg == nullptr) != DownloadResult::OK) { + // Cant get error since we parse directly to json. TODO: Make this work somehow? + if(err_msg) + *err_msg = "Failed to download/parse json"; + return DownloadResult::NET_ERR; + } + return DownloadResult::OK; + } +} \ No newline at end of file -- cgit v1.2.3