summaryrefslogtreecommitdiff
path: root/battleNetApi
diff options
context:
space:
mode:
Diffstat (limited to 'battleNetApi')
-rw-r--r--battleNetApi/CMakeLists.txt3
-rw-r--r--battleNetApi/include/hearthstoneTokenBuilder.hpp42
2 files changed, 27 insertions, 18 deletions
diff --git a/battleNetApi/CMakeLists.txt b/battleNetApi/CMakeLists.txt
index 6999d57..a89bb11 100644
--- a/battleNetApi/CMakeLists.txt
+++ b/battleNetApi/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.15)
+cmake_minimum_required(VERSION 3.12)
get_filename_component(FNAME ${CMAKE_SOURCE_DIR} NAME)
set(ProjectName ${FNAME})
@@ -17,7 +17,6 @@ set(INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
set(SRC
${PROJECT_SOURCE_DIR}/src/hearthstoneApi.cpp
${PROJECT_SOURCE_DIR}/src/token.cpp
- ${PROJECT_SOURCE_DIR}/src/tokenBuilder.cpp
${PROJECT_SOURCE_DIR}/src/hearthstoneTokenBuilder.cpp
${PROJECT_SOURCE_DIR}/src/apiUrl.cpp
${PROJECT_SOURCE_DIR}/src/main.cpp
diff --git a/battleNetApi/include/hearthstoneTokenBuilder.hpp b/battleNetApi/include/hearthstoneTokenBuilder.hpp
index 571554f..880d64d 100644
--- a/battleNetApi/include/hearthstoneTokenBuilder.hpp
+++ b/battleNetApi/include/hearthstoneTokenBuilder.hpp
@@ -6,12 +6,14 @@
#include <tokenBuilder.hpp>
#include <vector>
-namespace bnet {
+namespace bnet
+{
using nlohmann::json;
static constexpr std::uint64_t kTOKEN_CONTENT_MIN_LENGTH{10};
-class HearthstoneTokenBuilder : TokenBuilder {
+class HearthstoneTokenBuilder : TokenBuilder
+{
private:
std::shared_ptr<Token> _currentToken;
bool _allowBattleNetApiCall{false};
@@ -21,38 +23,46 @@ class HearthstoneTokenBuilder : TokenBuilder {
[[nodiscard]]
bool isUpdateSourceFileAllowed() const;
[[nodiscard]]
- bool isTokenValid(const json &iTokenJson) const;
- static size_t curlCallbackStringOutput(void *iPtr, size_t iSize, size_t iNmemb,
- std::string *iUserData);
+ bool isTokenValid(const json& iTokenJson) const;
+ static size_t curlCallbackStringOutput(void* iPtr,
+ size_t iSize,
+ size_t iNmemb,
+ std::string* iUserData);
[[nodiscard]]
std::chrono::seconds getCurrentTime() const;
[[nodiscard]]
- Token getTokenWithApi(const std::string &iCredentialsJsonFilePath) const;
+ Token getTokenWithApi(const std::string& iCredentialsJsonFilePath) const;
[[nodiscard]]
- Token getTokenWithApi(const json &iCredentials) const;
- void writeTokenToLocalFile(std::shared_ptr<Token> &iToken,
- const std::string &iTokenFileOutputPath) const;
+ Token getTokenWithApi(const json& iCredentials) const;
+ void writeTokenToLocalFile(std::shared_ptr<Token>& iToken,
+ const std::string& iTokenFileOutputPath) const;
public:
- HearthstoneTokenBuilder(const std::span<std::string> &iJsonPaths);
+ HearthstoneTokenBuilder(const std::span<std::string>& iJsonPaths);
+
template <typename... CredentialJsonPaths>
- HearthstoneTokenBuilder(CredentialJsonPaths... iCredentialJsonPaths) {
+ HearthstoneTokenBuilder(CredentialJsonPaths... iCredentialJsonPaths)
+ {
(_credentialJsonPaths.push_back(iCredentialJsonPaths), ...);
}
+
template <typename... CredentialJsonPaths>
- HearthstoneTokenBuilder &addCredentialJsonFiles(CredentialJsonPaths... iCredentialJsonPaths) {
+ HearthstoneTokenBuilder& addCredentialJsonFiles(CredentialJsonPaths... iCredentialJsonPaths)
+ {
(_credentialJsonPaths.push_back(iCredentialJsonPaths), ...);
+ return *this;
}
- HearthstoneTokenBuilder &allowBattleNetApiCall();
- HearthstoneTokenBuilder &allowUpdateSourceFile();
- HearthstoneTokenBuilder &allowExpiredToken();
+
+ HearthstoneTokenBuilder& allowBattleNetApiCall();
+ HearthstoneTokenBuilder& allowUpdateSourceFile();
+ HearthstoneTokenBuilder& allowExpiredToken();
/**
* @return Create an access token to perform API requests.
* First, the cache files are checked. (Which ones?)
* A new token is computed if the token lifetimes expired,
* or if there is no token at all.
*/
- HearthstoneTokenBuilder &buildToken() override;
+ HearthstoneTokenBuilder& buildToken() override;
[[nodiscard]]
std::shared_ptr<Token> getToken() override;
};