mirror of
https://github.com/tribufu/sdk-cpp
synced 2025-06-17 02:34:18 +00:00
Update main branch (#3)
* New api from upstream * Create .clang-format * Update .clang-format * Remove mintaka submodule * Add premake-core submodule * Update premake-core * Fix includes
This commit is contained in:
51
src/api.cpp
Normal file
51
src/api.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#include <tribufu/api.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
TribufuApi::TribufuApi()
|
||||
{
|
||||
}
|
||||
|
||||
TribufuApi::TribufuApi(std::string api_key)
|
||||
{
|
||||
this->options.api_key = api_key;
|
||||
}
|
||||
|
||||
TribufuApi::TribufuApi(TribufuApiOptions options)
|
||||
{
|
||||
this->options = options;
|
||||
}
|
||||
|
||||
TribufuApi::~TribufuApi()
|
||||
{
|
||||
}
|
||||
|
||||
TribufuApi TribufuApi::from_env()
|
||||
{
|
||||
return TribufuApi::from_env("");
|
||||
}
|
||||
|
||||
TribufuApi TribufuApi::from_env(std::string prefix)
|
||||
{
|
||||
std::string env_prefix = "";
|
||||
|
||||
if (prefix != "")
|
||||
{
|
||||
env_prefix = prefix + "_";
|
||||
}
|
||||
|
||||
size_t required_size;
|
||||
char api_key[64];
|
||||
|
||||
auto response = getenv_s(&required_size, api_key, sizeof(api_key), (env_prefix + "API_KEY").c_str());
|
||||
|
||||
if (response == 0 && required_size > 0)
|
||||
{
|
||||
return TribufuApi(api_key);
|
||||
}
|
||||
|
||||
return TribufuApi();
|
||||
}
|
||||
}
|
@ -4,17 +4,22 @@
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
TribufuClient::TribufuClient(uint64_t id, const std::string &secret)
|
||||
TribufuClient::TribufuClient(uint64_t client_id, const std::string &client_secret) : TribufuApi()
|
||||
{
|
||||
this->id = id;
|
||||
this->secret = secret;
|
||||
this->http = HttpClient();
|
||||
this->client_id = client_id;
|
||||
this->client_secret = client_secret;
|
||||
}
|
||||
|
||||
TribufuClient::~TribufuClient()
|
||||
{
|
||||
}
|
||||
|
||||
uint64_t &TribufuClient::get_client_id()
|
||||
{
|
||||
return this->client_id;
|
||||
}
|
||||
|
||||
/*
|
||||
void TribufuClient::get_token()
|
||||
{
|
||||
try
|
||||
@ -37,4 +42,5 @@ namespace tribufu
|
||||
std::cout << "exception: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -8,7 +8,9 @@ namespace tribufu
|
||||
{
|
||||
}
|
||||
|
||||
OAuth2AuthorizeRequest::OAuth2AuthorizeRequest(OAuth2ResponseType response_type, uint64_t client_id, const std::string &client_secret, const std::string &redirect_uri, const std::string &scope, const std::string &state)
|
||||
OAuth2AuthorizeRequest::OAuth2AuthorizeRequest(OAuth2ResponseType response_type, uint64_t client_id,
|
||||
const std::string &client_secret, const std::string &redirect_uri,
|
||||
const std::string &scope, const std::string &state)
|
||||
{
|
||||
this->response_type = response_type;
|
||||
this->client_id = client_id;
|
||||
@ -40,7 +42,8 @@ namespace tribufu
|
||||
{
|
||||
}
|
||||
|
||||
OAuth2ErrorResponse::OAuth2ErrorResponse(OAuth2AuthorizeError error, const std::string &error_description, const std::string &error_uri, const std::string &state)
|
||||
OAuth2ErrorResponse::OAuth2ErrorResponse(OAuth2AuthorizeError error, const std::string &error_description,
|
||||
const std::string &error_uri, const std::string &state)
|
||||
{
|
||||
this->error = error;
|
||||
this->error_description = error_description;
|
||||
@ -56,7 +59,10 @@ namespace tribufu
|
||||
{
|
||||
}
|
||||
|
||||
OAuth2TokenRequest::OAuth2TokenRequest(OAuth2GrantType grant_type, uint64_t client_id, const std::string &client_secret, const std::string &redirect_uri, const std::string &code, const std::string &refresh_token, const std::string &username, const std::string &password)
|
||||
OAuth2TokenRequest::OAuth2TokenRequest(OAuth2GrantType grant_type, uint64_t client_id,
|
||||
const std::string &client_secret, const std::string &redirect_uri,
|
||||
const std::string &code, const std::string &refresh_token,
|
||||
const std::string &username, const std::string &password)
|
||||
{
|
||||
this->grant_type = grant_type;
|
||||
this->client_id = client_id;
|
||||
@ -76,7 +82,9 @@ namespace tribufu
|
||||
{
|
||||
}
|
||||
|
||||
OAuth2TokenResponse::OAuth2TokenResponse(OAuth2TokenType token_type, const std::string &access_token, const std::string &refresh_token, const std::string &scope, const std::string &state, uint64_t expires_in)
|
||||
OAuth2TokenResponse::OAuth2TokenResponse(OAuth2TokenType token_type, const std::string &access_token,
|
||||
const std::string &refresh_token, const std::string &scope,
|
||||
const std::string &state, uint64_t expires_in)
|
||||
{
|
||||
this->token_type = token_type;
|
||||
this->access_token = access_token;
|
||||
|
32
src/options.cpp
Normal file
32
src/options.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#include <tribufu/options.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
TribufuApiOptions::TribufuApiOptions() : TribufuApiOptions(nullptr, nullptr, nullptr, 0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
TribufuApiOptions::TribufuApiOptions(std::string api_key) : TribufuApiOptions(api_key, nullptr, nullptr, 0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
TribufuApiOptions::TribufuApiOptions(std::string access_token, std::string refresh_token, float expires_in)
|
||||
: TribufuApiOptions(nullptr, access_token, refresh_token, expires_in)
|
||||
{
|
||||
}
|
||||
|
||||
TribufuApiOptions::TribufuApiOptions(std::string api_key, std::string access_token, std::string refresh_token,
|
||||
float expires_in)
|
||||
{
|
||||
this->api_key = api_key;
|
||||
this->access_token = access_token;
|
||||
this->refresh_token = refresh_token;
|
||||
this->expires_in = expires_in;
|
||||
}
|
||||
|
||||
TribufuApiOptions::~TribufuApiOptions()
|
||||
{
|
||||
}
|
||||
}
|
21
src/server.cpp
Normal file
21
src/server.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
#include <tribufu/server.h>
|
||||
|
||||
namespace tribufu
|
||||
{
|
||||
TribufuServer::TribufuServer(uint64_t server_id, uint64_t client_id, const std::string &client_secret)
|
||||
: TribufuClient(client_id, client_secret)
|
||||
{
|
||||
this->server_id = server_id;
|
||||
}
|
||||
|
||||
TribufuServer::~TribufuServer()
|
||||
{
|
||||
}
|
||||
|
||||
uint64_t &TribufuServer::get_server_id()
|
||||
{
|
||||
return this->server_id;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user