summaryrefslogtreecommitdiff
path: root/libtmdb/httpClient.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-09-02 19:58:41 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2015-09-02 20:21:30 +0100
commita3f47bdeb630361502a743259dcaa0bb1377f3bd (patch)
treedc570fa0058c4569dba6075988fac27eb02cdec7 /libtmdb/httpClient.cpp
parentVisibility hidden (diff)
downloadp2pvr-a3f47bdeb630361502a743259dcaa0bb1377f3bd.tar.bz2
p2pvr-a3f47bdeb630361502a743259dcaa0bb1377f3bd.tar.xz
p2pvr-a3f47bdeb630361502a743259dcaa0bb1377f3bd.zip
Use libadhocutil
Diffstat (limited to 'libtmdb/httpClient.cpp')
-rw-r--r--libtmdb/httpClient.cpp34
1 files changed, 6 insertions, 28 deletions
diff --git a/libtmdb/httpClient.cpp b/libtmdb/httpClient.cpp
index a4b4eb7..4331c07 100644
--- a/libtmdb/httpClient.cpp
+++ b/libtmdb/httpClient.cpp
@@ -2,6 +2,7 @@
#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) :
@@ -38,38 +39,15 @@ namespace TMDb {
}
}
- static size_t
- appendString(void * contents, size_t size, size_t nmemb, void * userp)
- {
- auto data = static_cast<std::stringstream *>(userp);
- data->write(static_cast<const char *>(contents), size * nmemb);
- return size * nmemb;
- }
-
json::Value
HttpClient::FetchJson(const std::string & path) const
{
- std::stringstream jsonData;
-
- struct curl_slist *headers = NULL;
- curl_slist_append(headers, "Accept: application/json");
-
- CURL * curl_handle = curl_easy_init();
- curl_easy_setopt(curl_handle, CURLOPT_URL, path.c_str());
- curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, appendString);
- curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&jsonData);
- curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
- curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
- CURLcode res = curl_easy_perform(curl_handle);
-
- long http_code = 0;
- curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &http_code);
- curl_easy_cleanup(curl_handle);
- if (res != CURLE_OK) {
- throw TMDb::HttpException(http_code);
- }
+ AdHoc::Net::CurlStreamSource css(path);
+ css.appendHeader("Accept: application/json");
+ css.setopt(CURLOPT_USERAGENT, "libtmdb/1.0");
- return json::parseValue(jsonData);
+ AdHoc::Net::CurlStream curlstrm(css);
+ return json::parseValue(curlstrm);
}
}