55 lines
1.2 KiB
C++
55 lines
1.2 KiB
C++
#pragma once
|
|
#include <SiaCommon.h>
|
|
#include <unordered_map>
|
|
|
|
NS_BEGIN(Sia)
|
|
NS_BEGIN(Api)
|
|
|
|
class AFX_EXT_CLASS CSiaCurl
|
|
{
|
|
public:
|
|
enum class _SiaCurlError
|
|
{
|
|
Success,
|
|
ServerVersionMismatch,
|
|
InvalidRequiredVersion,
|
|
NoResponse,
|
|
HttpError,
|
|
UnknownFailure
|
|
};
|
|
|
|
typedef std::unordered_map<String, String> _PostParameters;
|
|
|
|
public:
|
|
CSiaCurl();
|
|
|
|
CSiaCurl(const SiaHostConfig& hostConfig);
|
|
|
|
public:
|
|
~CSiaCurl();
|
|
|
|
private:
|
|
Property(SiaHostConfig, HostConfig, public, public)
|
|
|
|
private:
|
|
static _SiaCurlError CheckApiError(const json& result);
|
|
|
|
private:
|
|
static _SiaCurlError CheckHttpError(const std::string& result);
|
|
std::string ConstructPath(const String& relativePath) const;
|
|
_SiaCurlError _Get(const String& path, json& response) const;
|
|
bool CheckVersion(_SiaCurlError& error) const;
|
|
_SiaCurlError ProcessResponse(const int& res, const int& httpCode, const std::string& result, json& response) const;
|
|
|
|
public:
|
|
String GetServerVersion() const;
|
|
_SiaCurlError Get(const String& path, json& result) const;
|
|
_SiaCurlError Post(const String& path, const _PostParameters& parameters, json& response) const;
|
|
};
|
|
|
|
typedef CSiaCurl::_SiaCurlError SiaCurlError;
|
|
typedef CSiaCurl::_PostParameters PostParameters;
|
|
|
|
NS_END(2)
|
|
|