diff options
Diffstat (limited to 'battleNetApi/include/hearthstoneTokenBuilder.hpp')
| -rw-r--r-- | battleNetApi/include/hearthstoneTokenBuilder.hpp | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/battleNetApi/include/hearthstoneTokenBuilder.hpp b/battleNetApi/include/hearthstoneTokenBuilder.hpp index 488aff4..e946fe8 100644 --- a/battleNetApi/include/hearthstoneTokenBuilder.hpp +++ b/battleNetApi/include/hearthstoneTokenBuilder.hpp @@ -14,30 +14,40 @@ class HearthstoneTokenBuilder : TokenBuilder { private: std::shared_ptr<Token> mCurrentToken; bool mUpdateSourceFile{false}; - std::vector<std::string> mJsonPaths; + std::vector<std::string> _credentialJsonPaths; + [[nodiscard]] bool isUpdateSourceFileAllowed() const; - const bool hasExpired(json iToken) const; - static size_t curlCallbackStringOutput(void *iPtr, size_t iSize, - size_t iNmemb, + [[nodiscard]] + const bool hasExpired(json iTokenJson) const; + static size_t curlCallbackStringOutput(void *iPtr, size_t iSize, size_t iNmemb, std::string *iUserData); + [[nodiscard]] std::chrono::seconds getCurrentTime() const; - std::pair<std::string, std::uint64_t> getTokenWithApi() const; + [[nodiscard]] + std::pair<std::string, std::uint64_t> + getTokenWithApi(const std::string &iAgentJsonFilePath) const; + [[nodiscard]] std::string getTokenFromLocalFile() const; - void writeTokenToLocalFile( - const std::pair<std::string, std::uint64_t> &iToken) const; + void writeTokenToLocalFile(const std::pair<std::string, std::uint64_t> &iToken) const; public: HearthstoneTokenBuilder(const std::span<std::string> &iJsonPaths); - HearthstoneTokenBuilder(const std::string &iJsonPath); - HearthstoneTokenBuilder &addJsonPath(const std::string &iJsonPath); - HearthstoneTokenBuilder &addJsonPaths(const std::string &iJsonPath); + template <typename... CredentialJsonPaths> + HearthstoneTokenBuilder(CredentialJsonPaths... iCredentialJsonPaths) { + (_credentialJsonPaths.push_back(iCredentialJsonPaths), ...); + } + template <typename... CredentialJsonPaths> + HearthstoneTokenBuilder &addCredentialJsonFiles(CredentialJsonPaths... iCredentialJsonPaths) { + (_credentialJsonPaths.push_back(iCredentialJsonPaths), ...); + } HearthstoneTokenBuilder &allowUpdateSourceFile(); /** * @return Create an access token to perform API requests. - * First, the cache files are checked. + * 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; + [[nodiscard]] std::shared_ptr<Token> getToken() override; }; |
