From cc436cb44c60ef2485321e1e22b3ea0a59ee22af Mon Sep 17 00:00:00 2001 From: Aotrix <9aotrix@protonmail.com> Date: Sun, 19 Apr 2026 18:16:14 +0200 Subject: TokenPool now works --- battleNetApi/include/apiUrl.hpp | 18 +++++++++++++++++- battleNetApi/include/hearthstoneApi.hpp | 2 +- battleNetApi/include/token.hpp | 2 +- battleNetApi/include/tokenPool.hpp | 7 ++++--- 4 files changed, 23 insertions(+), 6 deletions(-) (limited to 'battleNetApi/include') diff --git a/battleNetApi/include/apiUrl.hpp b/battleNetApi/include/apiUrl.hpp index 881e593..e936b6c 100644 --- a/battleNetApi/include/apiUrl.hpp +++ b/battleNetApi/include/apiUrl.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include #include @@ -10,12 +11,27 @@ class ApiUrl { void setLocale(const std::string &iLocale); void setGameMode(const std::string &iGameMode); void setPage(const std::string &iPage); + void setPage(uint64_t iPage); void setPageSize(const std::string &iPageSize); - void setValue(const std::string &iKey, const std::string &iValue); + void setPageSize(uint64_t iPageSize); + + bool hasRegion() const; + bool hasLocale() const; + bool hasGameMode() const; + bool hasPage() const; + bool hasPageSize() const; + std::string text() const; private: + static constexpr std::string kLOCALE_KEY{"locale"}; + static constexpr std::string kGAME_MODE_KEY{"gameMode"}; + static constexpr std::string kPAGE_KEY{"page"}; + static constexpr std::string kPAGE_SIZE_KEY{"pageSize"}; std::string mContentType; std::string mRegion; std::unordered_map aParameters; + + void setValue(const std::string &iKey, const std::string &iValue); + bool hasValue(const std::string &iKey) const; }; diff --git a/battleNetApi/include/hearthstoneApi.hpp b/battleNetApi/include/hearthstoneApi.hpp index f2bdf04..59cd336 100644 --- a/battleNetApi/include/hearthstoneApi.hpp +++ b/battleNetApi/include/hearthstoneApi.hpp @@ -11,7 +11,7 @@ class HearthstoneApi { static json makeApiRequest(const ApiUrl &iApiUrl, const std::string &iTokenText); static std::vector makeApiRequest(const std::vector &iApiUrls, const std::string &iTokenText); static std::vector makeApiRequest(const std::vector &iUrls, const std::string &iTokenText); - static json downloadCards(ApiUrl &iApiUrl, Token &iToken); + static json downloadCards(ApiUrl iApiUrl, const Token &iToken); private: static std::string authorizationHeader(const std::string &iTokenText); diff --git a/battleNetApi/include/token.hpp b/battleNetApi/include/token.hpp index 23d1f49..bcb4926 100644 --- a/battleNetApi/include/token.hpp +++ b/battleNetApi/include/token.hpp @@ -5,7 +5,7 @@ class Token { public: - Token(const std::string &iTokenFilePath); + explicit Token(const std::string &iTokenFilePath); std::string text() const; const bool hasExpired() const; void updateToken(); diff --git a/battleNetApi/include/tokenPool.hpp b/battleNetApi/include/tokenPool.hpp index 6f5dffc..0b1e4cc 100644 --- a/battleNetApi/include/tokenPool.hpp +++ b/battleNetApi/include/tokenPool.hpp @@ -3,7 +3,7 @@ #include #include -static std::queue mTokenContainer; +static std::queue aTokenContainer; class TokenPool { private: @@ -14,6 +14,7 @@ class TokenPool { TokenPool &operator=(TokenPool &&) = delete; public: - static void fillTokenSource(const std::string &iJsonPath); - static std::optional unusedToken(); + static void feedTokenSource(const std::span &iJsonPaths); + static void feedTokenSource(const std::string &iJsonPath); + static std::optional availableToken(); }; -- cgit v1.2.3