summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libtmdb/Jamfile.jam2
-rw-r--r--libtmdb/httpClient.cpp34
2 files changed, 8 insertions, 28 deletions
diff --git a/libtmdb/Jamfile.jam b/libtmdb/Jamfile.jam
index 3c719b6..668af7d 100644
--- a/libtmdb/Jamfile.jam
+++ b/libtmdb/Jamfile.jam
@@ -14,6 +14,7 @@ lib boost_system ;
lib boost_filesystem ;
lib curl ;
lib boost_utf : : <name>boost_unit_test_framework ;
+lib adhocutil : : : : <include>/usr/include/adhocutil ;
lib tmdb :
[ glob *.cpp *.ice : test*.cpp ] :
@@ -26,6 +27,7 @@ lib tmdb :
<library>boost_system
<library>glibmm
<library>curl
+ <library>adhocutil
<slicer>yes
<cflags>-fvisibility=hidden
: :
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);
}
}