diff options
Diffstat (limited to 'oop2eindopdr/PokemonTCGAPIClient.cpp')
-rw-r--r-- | oop2eindopdr/PokemonTCGAPIClient.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/oop2eindopdr/PokemonTCGAPIClient.cpp b/oop2eindopdr/PokemonTCGAPIClient.cpp index 0c950fd..335c15c 100644 --- a/oop2eindopdr/PokemonTCGAPIClient.cpp +++ b/oop2eindopdr/PokemonTCGAPIClient.cpp @@ -19,15 +19,34 @@ nlohmann::json PokemonTCGAPIClient::raw_request(const char* endpoint, cpr::Param } nlohmann::json PokemonTCGAPIClient::raw_get_cards(const char* query) { - return raw_request("/cards", cpr::Parameters{{"q", query}}); + return raw_request("/cards", cpr::Parameters{{"q", query}, {"select", "id,name,hp,attacks,number,images"}}); } nlohmann::json PokemonTCGAPIClient::raw_get_sets(const char* query) { return raw_request("/sets", cpr::Parameters{{"q", query}}); } +nlohmann::json PokemonTCGAPIClient::raw_get_card(const char* id) { + std::string full_query = "id:"; + full_query.append(id); + return raw_request("/cards", cpr::Parameters{{"q", full_query}}); +} + std::vector<PokemonCard*> PokemonTCGAPIClient::get_set_cards(const char* set_name) { - return {}; + std::string query = "set.id:"; + query.append(set_name); + nlohmann::json raw_data = raw_get_cards(query.c_str()); + std::vector<PokemonCard*> out; + for (nlohmann::json card_json : raw_data["data"]) { + out.push_back(new PokemonCard::from_json(card_json)); + } + return out; +} + +PokemonCard* PokemonTCGAPIClient::get_full_card(const char* id) { + nlohmann::json raw_cards = raw_get_card(id); + if (raw_cards["data"].size() == 0) return nullptr; + return new PokemonCard::from_json(raw_cards["data"][0]); } std::vector<std::string> PokemonTCGAPIClient::get_sets() { |