From a51a54bc5979a2491f152abc47ad54e6b63f27c8 Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Tue, 23 Nov 2021 05:21:56 +0100 Subject: Restructure source and resource files (#46) importantly, res is now res/res and css is now res/css --- src/discord/httpclient.hpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/discord/httpclient.hpp (limited to 'src/discord/httpclient.hpp') diff --git a/src/discord/httpclient.hpp b/src/discord/httpclient.hpp new file mode 100644 index 0000000..da8be37 --- /dev/null +++ b/src/discord/httpclient.hpp @@ -0,0 +1,39 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include "http.hpp" + +class HTTPClient { +public: + HTTPClient(); + + void SetBase(const std::string &url); + + void SetUserAgent(std::string agent); + void SetAuth(std::string auth); + void MakeDELETE(const std::string &path, std::function cb); + void MakeGET(const std::string &path, std::function cb); + void MakePATCH(const std::string &path, const std::string &payload, std::function cb); + void MakePOST(const std::string &path, const std::string &payload, std::function cb); + void MakePUT(const std::string &path, const std::string &payload, std::function cb); + +private: + void OnResponse(const http::response_type &r, std::function cb); + void CleanupFutures(); + + mutable std::mutex m_mutex; + Glib::Dispatcher m_dispatcher; + std::queue> m_queue; + void RunCallbacks(); + + std::vector> m_futures; + std::string m_api_base; + std::string m_authorization; + std::string m_agent; +}; -- cgit v1.2.3