blob: 4331c07f5ae7f7e67473f91c88bcfed33495dc74 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#include "httpClient.h"
#include <boost/lexical_cast.hpp>
#include <curl/curl.h>
#include <tmdb-api.h>
#include <curlStream.h>
namespace TMDb {
HttpClient::HttpClient(const std::string & bu, const std::string & k) :
BaseURL(bu),
ApiKey(k)
{
}
void
HttpClient::packParams(boost::format &)
{
}
void
HttpClient::appendQueryParameters(std::string & path, const Parameters::value_type & nvp) const
{
path += nvp.first;
path += "=";
auto ev = curl_easy_escape(NULL, nvp.second.value->c_str(), nvp.second.value->size());
path += ev;
curl_free(ev);
}
void
HttpClient::appendQueryParameters(std::string & path, const Parameters & parameters) const
{
path += "?";
appendQueryParameters(path, { "apikey", ApiKey });
for (const auto & nvp : parameters) {
if (nvp.second.value) {
path += "&";
appendQueryParameters(path, nvp);
}
}
}
json::Value
HttpClient::FetchJson(const std::string & path) const
{
AdHoc::Net::CurlStreamSource css(path);
css.appendHeader("Accept: application/json");
css.setopt(CURLOPT_USERAGENT, "libtmdb/1.0");
AdHoc::Net::CurlStream curlstrm(css);
return json::parseValue(curlstrm);
}
}
|