#include #include #include #include #include #include #include using nlohmann::json; static constexpr std::uint64_t kTOKEN_CONTENT_MIN_LENGTH{10}; class HearthstoneTokenBuilder : TokenBuilder { private: std::shared_ptr mCurrentToken; bool mUpdateSourceFile{false}; std::vector _credentialJsonPaths; [[nodiscard]] bool isUpdateSourceFileAllowed() const; [[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; [[nodiscard]] std::pair getTokenWithApi(const std::string &iAgentJsonFilePath) const; [[nodiscard]] std::string getTokenFromLocalFile() const; void writeTokenToLocalFile(const std::pair &iToken) const; public: HearthstoneTokenBuilder(const std::span &iJsonPaths); template HearthstoneTokenBuilder(CredentialJsonPaths... iCredentialJsonPaths) { (_credentialJsonPaths.push_back(iCredentialJsonPaths), ...); } template 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. (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 getToken() override; };