From f01072eb4166fc68f59519ebf84de46e7386abf5 Mon Sep 17 00:00:00 2001 From: Aotrix <9aotrix@protonmail.com> Date: Fri, 27 Mar 2026 18:48:55 +0100 Subject: Generate json card lists with static methods Instead of creating a useless instance of HearthstoneApi class, calls static methods. --- battleNetApi/include/hearthstoneApi.hpp | 11 ++++------- battleNetApi/include/tokenPool.hpp | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 battleNetApi/include/tokenPool.hpp (limited to 'battleNetApi/include') diff --git a/battleNetApi/include/hearthstoneApi.hpp b/battleNetApi/include/hearthstoneApi.hpp index c3fbfac..ecf785a 100644 --- a/battleNetApi/include/hearthstoneApi.hpp +++ b/battleNetApi/include/hearthstoneApi.hpp @@ -8,17 +8,14 @@ using json = nlohmann::json; class HearthstoneApi { public: - HearthstoneApi(const Token &iToken); - HearthstoneApi(Token &&iToken); - json makeApiRequest(const std::string &iUrl) const; - std::vector makeApiRequest(const std::vector &iUrls) const; - void downloadAllCards(ApiUrl &iApiUrl, const std::string &iOutputJsonPath) const; + static json makeApiRequest(const std::string &iUrl, const std::string &iTokenText); + static std::vector makeApiRequest(const std::vector &iUrls, const std::string &iTokenText); + static json downloadCards(ApiUrl &iApiUrl, Token &iToken); private: - std::string authorizationHeader() const; + static std::string authorizationHeader(const std::string &iTokenText); static size_t curlCallbackStringOutput(void *iContent, size_t iSize, size_t iNmemb, std::string *iS); - Token mToken; std::string mAuthorizationHeader; // +#include + +class TokenPool { + private: + TokenPool() = default; + TokenPool(const TokenPool &) = delete; + TokenPool(TokenPool &&) = delete; + TokenPool &operator=(const TokenPool &) = delete; + TokenPool &operator=(TokenPool &&) = delete; + static std::queue mTokenContainer; + + public: + static void fillTokenSource(const std::string &iJsonPath); + static std::optional unusedToken(); +}; -- cgit v1.2.3