aboutsummaryrefslogtreecommitdiff
path: root/src/Json.cpp
blob: 683c4daf9a74b88748f5bcd77a4c6d5bff960641 (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_browser_useragent, std::string *err_msg) {
        if(download_to_json(url, result, std::move(additional_args), 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;
    }
}