From b28bfd6f208bc04b4157130eabfcf61b1825570d Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 23 Jan 2021 21:07:03 +0000 Subject: remove cpr as a dependency (#21) abstract away library usage --- discord/httpclient.hpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 discord/httpclient.hpp (limited to 'discord/httpclient.hpp') 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 +#include +#include +#include +#include +#include +#include +#include +#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 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