aboutsummaryrefslogtreecommitdiff
path: root/src/Json.cpp
blob: 86703b23b36f5ccca4bdc4aee7625d14a2f79e63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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<CommandArg> 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;
    }
}