diff options
Diffstat (limited to 'oop2eindopdr/PokemonTCGAPIClient.cpp')
-rw-r--r-- | oop2eindopdr/PokemonTCGAPIClient.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/oop2eindopdr/PokemonTCGAPIClient.cpp b/oop2eindopdr/PokemonTCGAPIClient.cpp index e69de29..0c950fd 100644 --- a/oop2eindopdr/PokemonTCGAPIClient.cpp +++ b/oop2eindopdr/PokemonTCGAPIClient.cpp @@ -0,0 +1,39 @@ +#include "PokemonTCGAPIClient.h" + +#include <iostream> +#include <cpr/cpr.h> + +PokemonTCGAPIClient::PokemonTCGAPIClient() { + +} + +PokemonTCGAPIClient::~PokemonTCGAPIClient() { + +} + +nlohmann::json PokemonTCGAPIClient::raw_request(const char* endpoint, cpr::Parameters params) { + std::string full_url = API_URL; + full_url.append(endpoint); + cpr::Response res = cpr::Get(cpr::Url{full_url}, params); + return nlohmann::json::parse(res.text); +} + +nlohmann::json PokemonTCGAPIClient::raw_get_cards(const char* query) { + return raw_request("/cards", cpr::Parameters{{"q", query}}); +} + +nlohmann::json PokemonTCGAPIClient::raw_get_sets(const char* query) { + return raw_request("/sets", cpr::Parameters{{"q", query}}); +} + +std::vector<PokemonCard*> PokemonTCGAPIClient::get_set_cards(const char* set_name) { + return {}; +} + +std::vector<std::string> PokemonTCGAPIClient::get_sets() { + nlohmann::json raw_data = raw_get_sets("legalities.standard:legal"); + std::vector<std::string> sets; + for (unsigned s = 0; s < raw_data["count"]; s++) + sets.push_back(raw_data["data"][s]["id"]); + return sets; +} |