#pragma once #include #include class Token { public: explicit Token(const std::string &iTokenFilePath); std::string text() const; const bool hasExpired() const; private: const std::string mFilePath; //!< Path to the token file const std::string mUsername; //!< Username for Battle.net API const std::string mPassword; //!< Password for Battle.net API std::string mToken; //!< Token value /** * @return An access token that a user can use to perform API requests. * First, the cache file is checked. * A new token is computed if the current token lifetime expired, * or if there is no token at all. */ std::string generateToken(); void writeTokenToLocalFile(const std::pair &iToken) const; std::string getTokenFromLocalFile() const; std::pair getTokenWithApi() const; std::chrono::seconds getCurrentTime() const; static size_t curlCallbackStringOutput(void *iPtr, size_t iSize, size_t iNmemb, std::string *iUserData); static const std::uint16_t kTokenContentMinLength{10}; };