summaryrefslogtreecommitdiff
path: root/external/restclient/restclient.cpp
diff options
context:
space:
mode:
authorIronClawTrem <louie.nutman@gmail.com>2020-02-16 03:40:06 +0000
committerIronClawTrem <louie.nutman@gmail.com>2020-02-16 03:40:06 +0000
commit425decdf7e9284d15aa726e3ae96b9942fb0e3ea (patch)
tree6c0dd7edfefff1be7b9e75fe0b3a0a85fe1595f3 /external/restclient/restclient.cpp
parentccb0b2e4d6674a7a00c9bf491f08fc73b6898c54 (diff)
create tremded branch
Diffstat (limited to 'external/restclient/restclient.cpp')
-rw-r--r--external/restclient/restclient.cpp118
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;
+}
+