diff options
Diffstat (limited to 'external/restclient/restclient.cpp')
-rw-r--r-- | external/restclient/restclient.cpp | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/external/restclient/restclient.cpp b/external/restclient/restclient.cpp new file mode 100644 index 0000000..0138c79 --- /dev/null +++ b/external/restclient/restclient.cpp @@ -0,0 +1,118 @@ +/** + * @file restclient.cpp + * @brief implementation of the restclient class + * + * This just provides static wrappers around the Connection class REST + * methods. However since I didn't want to have to pull in a whole URI parsing + * library just now, the Connection constructor is passed an empty string and + * the full URL is passed to the REST methods. All those methods to is + * concatenate them anyways. So this should do for now. + * + * @author Daniel Schauenberg <d@unwiredcouch.com> + */ + +#include "restclient/restclient.h" + +#include "../../src/client/cl_curl.h" +#ifdef USE_LOCAL_HEADERS + #include "../libcurl-7.35.0/curl/curl.h" +#else + #include <curl/curl.h> +#endif + +#include "restclient/version.h" +#include "restclient/connection.h" + +/** + * @brief global init function. Call this before you start any threads. + */ +int RestClient::init() { +#ifdef USE_CURL_DLOPEN + CL_cURL_Init(); +#endif + CURLcode res = qcurl_global_init(CURL_GLOBAL_ALL); + if (res == CURLE_OK) { + return 0; + } else { + return 1; + } +} + +/** + * @brief global disable function. Call this before you terminate your + * program. + */ +void RestClient::disable() { + qcurl_global_cleanup(); +} + +/** + * @brief HTTP GET method + * + * @param url to query + * + * @return response struct + */ +RestClient::Response RestClient::get(const std::string& url) { + RestClient::Response ret; + RestClient::Connection *conn = new RestClient::Connection(""); + ret = conn->get(url); + delete conn; + return ret; +} + +/** + * @brief HTTP POST method + * + * @param url to query + * @param ctype content type as string + * @param data HTTP POST body + * + * @return response struct + */ +RestClient::Response RestClient::post(const std::string& url, + const std::string& ctype, + const std::string& data) { + RestClient::Response ret; + RestClient::Connection *conn = new RestClient::Connection(""); + conn->AppendHeader("Content-Type", ctype); + ret = conn->post(url, data); + delete conn; + return ret; +} + +/** + * @brief HTTP PUT method + * + * @param url to query + * @param ctype content type as string + * @param data HTTP PUT body + * + * @return response struct + */ +RestClient::Response RestClient::put(const std::string& url, + const std::string& ctype, + const std::string& data) { + RestClient::Response ret; + RestClient::Connection *conn = new RestClient::Connection(""); + conn->AppendHeader("Content-Type", ctype); + ret = conn->put(url, data); + delete conn; + return ret; +} + +/** + * @brief HTTP DELETE method + * + * @param url to query + * + * @return response struct + */ +RestClient::Response RestClient::del(const std::string& url) { + RestClient::Response ret; + RestClient::Connection *conn = new RestClient::Connection(""); + ret = conn->del(url); + delete conn; + return ret; +} + |