2#define WIN32_LEAN_AND_MEAN
6#include "../IBaseApi.h"
30 void WriteRequest(std::function<
void(
bool, std::string)>
callback,
bool success, std::string result);
33 const std::vector<std::string>& headers,
const std::string& request_type);
41 std::function<void(
bool, std::string)>
callback;
51 : pimpl{
std::make_unique<
impl>() }
64 game_api->GetCommands()->RemoveOnTickCallback(
"RequestsUpdate");
80 const std::vector<std::string>& headers,
const std::string& request_type)
95 for (
const auto& header : headers)
97 const std::string&
key = header.substr(0, header.find(
":"));
98 const std::string& data = header.substr(header.find(
":") + 1);
109 std::string result =
"";
115 std::ostringstream oss;
130 std::vector<std::string> headers)
132 std::thread([
this, url,
callback, headers]
134 std::string Result =
"";
143 Result =
pimpl->GetResponse(session, response);
150 const bool success = (int)response.
getStatus() >= 200
163 const std::string& post_data, std::vector<std::string> headers)
165 std::thread([
this, url,
callback, post_data, headers]
167 std::string Result =
"";
178 std::ostream& OutputStream = session->
sendRequest(request);
179 OutputStream << post_data;
181 Result =
pimpl->GetResponse(session, response);
188 const bool success = (int)response.
getStatus() >= 200
201 const std::string& post_data,
const std::string& content_type, std::vector<std::string> headers)
203 std::thread([
this, url,
callback, post_data, content_type, headers]
205 std::string Result =
"";
216 std::ostream& OutputStream = session->
sendRequest(request);
217 OutputStream << post_data;
219 Result =
pimpl->GetResponse(session, response);
226 const bool success = (int)response.
getStatus() >= 200
239 const std::vector<std::string>& post_ids,
240 const std::vector<std::string>& post_data, std::vector<std::string> headers)
242 if (post_ids.size() != post_data.size())
245 std::thread([
this, url,
callback, post_ids, post_data, headers]
247 std::string Result =
"";
257 for (
size_t i = 0; i < post_ids.size(); ++i)
259 const std::string&
id = post_ids[i];
260 const std::string& data = post_data[i];
270 std::ostream& OutputStream = session->
sendRequest(request);
271 OutputStream << body;
273 Result =
pimpl->GetResponse(session, response);
280 const bool success = (int)response.
getStatus() >= 200
293 std::vector<std::string> headers)
295 std::thread([
this, url,
callback, headers]
297 std::string Result =
"";
306 Result =
pimpl->GetResponse(session, response);
313 const bool success = (int)response.
getStatus() >= 200
327 if (RequestsVec_.empty())
330 RequestMutex_.lock();
331 std::vector<RequestData> requests_temp =
std::move(RequestsVec_);
332 RequestMutex_.unlock();
334 for (
const auto& request : requests_temp) { request.callback(request.success, request.result); }
int void(* callback)(int, int, void *)
void WriteRequest(std::function< void(bool, std::string)> callback, bool success, std::string result)
std::function< void(bool, std::string)> callback
std::string GetResponse(Poco::Net::HTTPClientSession *session, Poco::Net::HTTPResponse &response)
Poco::Net::HTTPRequest ConstructRequest(const std::string &url, Poco::Net::HTTPClientSession *&session, const std::vector< std::string > &headers, const std::string &request_type)
std::vector< RequestData > RequestsVec_
ARK_API bool CreateGetRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, std::vector< std::string > headers={})
Creates an async GET Request that runs in another thread but calls the callback from the main thread.
ARK_API bool CreateDeleteRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, std::vector< std::string > headers={})
Creates an async DELETE Request that runs in another thread but calls the callback from the main thre...
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::string &post_data, std::vector< std::string > headers={})
Creates an async POST Request with application/x-www-form-urlencoded content type that runs in anothe...
static ARK_API Requests & Get()
std::unique_ptr< impl > pimpl
static std::shared_ptr< spdlog::logger > & GetLog()
std::string displayText() const
Returns the exception code if defined.
virtual std::istream & receiveResponse(HTTPResponse &response)
virtual std::ostream & sendRequest(HTTPRequest &request)
Returns the connection timeout for HTTP connections.
void setContentType(const std::string &mediaType)
static const std::string HTTP_1_1
void setContentLength(std::streamsize length)
Returns the HTTP version for this message.
static const std::string HTTP_GET
static const std::string HTTP_DELETE
static const std::string HTTP_POST
const std::string & getReason() const
Sets the HTTP reason phrase.
HTTPStatus getStatus() const
void add(const std::string &name, const std::string &value)
Sets the value of the (first) name-value pair with the given name.
void initializeClient(PrivateKeyPassphraseHandlerPtr ptrPassphraseHandler, InvalidCertificateHandlerPtr ptrHandler, Context::Ptr ptrContext)
static SSLManager & instance()
This stream discards all characters written to it.
static std::streamsize copyStream(std::istream &istr, std::ostream &ostr, std::size_t bufferSize=8192)
const std::string & getHost() const
Sets the user-info part of the URI.
const std::string & getScheme() const
unsigned short getPort() const
Sets the host part of the URI.
std::string getPathAndQuery() const
Returns the encoded path, query and fragment parts of the URI.
std::unique_ptr< IBaseApi > game_api
void NetSSL_API initializeSSL()
void NetSSL_API uninitializeSSL()
std::string format(CStringRef format_str, ArgList args)
fmt::BufferedFile & move(fmt::BufferedFile &f)
static std::string escape(const std::string &s, bool strictJSON=false)