summaryrefslogtreecommitdiff
path: root/battleNetApi/include
diff options
context:
space:
mode:
Diffstat (limited to 'battleNetApi/include')
-rw-r--r--battleNetApi/include/hearthstoneTokenBuilder.hpp32
-rw-r--r--battleNetApi/include/token.hpp8
2 files changed, 27 insertions, 13 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;
};
diff --git a/battleNetApi/include/token.hpp b/battleNetApi/include/token.hpp
index cc909a8..8b9f95e 100644
--- a/battleNetApi/include/token.hpp
+++ b/battleNetApi/include/token.hpp
@@ -1,13 +1,17 @@
#pragma once
+#include <chrono>
#include <string>
class Token {
public:
- explicit Token(const std::string &iTokenText);
+ explicit Token(const std::string &iTokenText, const std::chrono::seconds &iExpirationTime);
std::string text() const;
void setText(const std::string &iTokenText);
+ void setExpirationTime(const std::chrono::seconds &iExpirationTime);
+ bool isExpired();
private:
- std::string mTokenText; //!< Token value
+ std::string _tokenText;
+ std::chrono::seconds _expirationTime;
};