summaryrefslogtreecommitdiff
path: root/discord/httpclient.hpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-01-23 21:07:03 +0000
committerGitHub <noreply@github.com>2021-01-23 21:07:03 +0000
commitb28bfd6f208bc04b4157130eabfcf61b1825570d (patch)
tree7c2f770d7cda4d48571c8df69dc7460f1aa7bea0 /discord/httpclient.hpp
parent547124c94f8808d6dca407af7b6eb0d29ac12e45 (diff)
downloadabaddon-portaudio-b28bfd6f208bc04b4157130eabfcf61b1825570d.tar.gz
abaddon-portaudio-b28bfd6f208bc04b4157130eabfcf61b1825570d.zip
remove cpr as a dependency (#21)
abstract away library usage
Diffstat (limited to 'discord/httpclient.hpp')
-rw-r--r--discord/httpclient.hpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/discord/httpclient.hpp b/discord/httpclient.hpp
new file mode 100644
index 0000000..8038334
--- /dev/null
+++ b/discord/httpclient.hpp
@@ -0,0 +1,37 @@
+#pragma once
+#include <functional>
+#include <future>
+#include <string>
+#include <unordered_map>
+#include <memory>
+#include <mutex>
+#include <queue>
+#include <glibmm.h>
+#include "../http.hpp"
+
+class HTTPClient {
+public:
+ HTTPClient(std::string api_base);
+
+ void SetUserAgent(std::string agent);
+ void SetAuth(std::string auth);
+ void MakeDELETE(const std::string &path, std::function<void(http::response_type r)> cb);
+ void MakeGET(const std::string &path, std::function<void(http::response_type r)> cb);
+ void MakePATCH(const std::string &path, const std::string &payload, std::function<void(http::response_type r)> cb);
+ void MakePOST(const std::string &path, const std::string &payload, std::function<void(http::response_type r)> cb);
+ void MakePUT(const std::string &path, const std::string &payload, std::function<void(http::response_type r)> cb);
+
+private:
+ void OnResponse(const http::response_type &r, std::function<void(http::response_type r)> cb);
+ void CleanupFutures();
+
+ mutable std::mutex m_mutex;
+ Glib::Dispatcher m_dispatcher;
+ std::queue<std::function<void()>> m_queue;
+ void RunCallbacks();
+
+ std::vector<std::future<void>> m_futures;
+ std::string m_api_base;
+ std::string m_authorization;
+ std::string m_agent;
+};