summaryrefslogtreecommitdiff
path: root/discord/httpclient.hpp
diff options
context:
space:
mode:
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;
+};