summaryrefslogtreecommitdiff
path: root/subprojects/battleNetApi/include
diff options
context:
space:
mode:
authorAotrix <[email protected]>2025-11-01 19:04:16 +0100
committerAotrix <[email protected]>2025-11-01 19:04:16 +0100
commit3baa8fa322dbc8f2a2183e8ac027387c75eb9180 (patch)
treee70c83e40d762d34451353efedd6413af8e3bc5c /subprojects/battleNetApi/include
parentdb533729ce52c9c7a5d1de5393426c0f76de3693 (diff)
added Token class
Diffstat (limited to 'subprojects/battleNetApi/include')
-rw-r--r--subprojects/battleNetApi/include/hearthstoneApi.hpp42
-rw-r--r--subprojects/battleNetApi/include/token.hpp21
2 files changed, 48 insertions, 15 deletions
diff --git a/subprojects/battleNetApi/include/hearthstoneApi.hpp b/subprojects/battleNetApi/include/hearthstoneApi.hpp
index f677080..fcd84c0 100644
--- a/subprojects/battleNetApi/include/hearthstoneApi.hpp
+++ b/subprojects/battleNetApi/include/hearthstoneApi.hpp
@@ -1,25 +1,37 @@
#pragma once
+#include "token.hpp"
#include <chrono>
#include <string>
-class HearthstoneAPI {
+class HearthstoneApi {
public:
- HearthstoneAPI();
- std::string get_cards(const std::string &t_card_parameters);
+ HearthstoneApi();
+ std::string getCards(const std::string &t_card_parameters);
+
+ friend class HearthstoneApiTests;
private:
- static size_t curl_callback_string_output(void *t_contents, size_t t_size, size_t t_nmemb, std::string *t_s);
- std::chrono::seconds get_current_time();
- std::string extract_string_with_regex(const std::string &t_str, const std::string t_regex);
- void write_new_token_info_to_file(const std::string &t_file_path);
- void refresh_token_if_needed();
- std::string get_valid_token();
- std::string generate_request_header();
- const std::string get_url(const std::string &t_parameters);
- const std::string get_set_of_cards_url(const std::string &t_card_parameters);
- std::string make_api_request(const char *t_url, const char *t_header);
- std::string make_api_request(const std::string &t_url, const std::string &t_header);
+ /**
+ * @brief Get a valid token to call Battle.net API
+ * @return A valid token
+ */
+ std::string getValidTokenWithApi() const;
+ static size_t curlCallbackStringOutput(void *t_contents, size_t t_size, size_t t_nmemb, std::string *t_s);
+ std::chrono::seconds getCurrentTime() const;
+ std::string extractStringWithRegex(const std::string &t_str, const std::string t_regex) const;
+ void writeTokenToFile(const std::string &iToken) const;
+ void writeNewTokenToFile() const;
+ void refreshToken();
+ std::string getValidToken();
+ std::string generateRequestHeader();
+ const std::string getUrl(const std::string &t_parameters);
+ const std::string getSetOfCardsUrl(const std::string &t_card_parameters);
+ std::string makeApiRequest(const char *t_url, const char *t_header);
+ std::string makeApiRequest(const std::string &t_url, const std::string &t_header);
- std::string m_access_token;
+ // TODO: add Token object
+ // Token mToken;
+ std::string mTokenFilePath;
+ std::string mToken;
std::string m_header;
};
diff --git a/subprojects/battleNetApi/include/token.hpp b/subprojects/battleNetApi/include/token.hpp
new file mode 100644
index 0000000..9c1eb18
--- /dev/null
+++ b/subprojects/battleNetApi/include/token.hpp
@@ -0,0 +1,21 @@
+#include <chrono>
+#include <string>
+
+class Token {
+ public:
+ Token(const std::string &iTokenFilePath);
+ std::string getValidToken() const;
+
+ private:
+ std::string mFilePath; //!< Path to the token file
+
+ void refreshToken() const;
+ void writeNewTokenToFile() const;
+ void writeTokenToFile(const std::string &iToken) const;
+ std::string getValidTokenWithApi() const;
+ std::chrono::seconds getCurrentTime() const;
+ std::string extractFirstMatchRegex(const std::string &t_str, const std::string &t_regex) const;
+ static size_t curlCallbackStringOutput(void *t_contents, size_t t_size, size_t t_nmemb, std::string *t_s);
+
+ friend class TokenTests;
+};