Crates.io | pokemontcgio |
lib.rs | pokemontcgio |
version | 0.2.1 |
source | src |
created_at | 2024-08-27 15:27:59.976536 |
updated_at | 2024-11-15 13:17:51.241272 |
description | An interface for interacting with the pokemontcg.io REST API |
homepage | |
repository | https://github.com/austinmh12/pokemon-tcg-io-rs |
max_upload_size | |
id | 1353506 |
size | 49,969 |
This is a wrapper for the REST API of pokemontcg.io that uses builder patterns inspired by reqwest.
Run cargo add pokemontcgio
or add the following to the Cargo.toml
file:
[dependencies]
pokemontcgio = "0.2.1"
let client = Client::with_api_key("API_KEY");
let client = Client::with_api_key("API_KEY");
let card = client.get_card("swsh4-183").await?;
match card {
Some(c) => println!("{:?}", c),
None => println!("No card found!")
}
let client = Client::with_api_key("API_KEY");
// Fetch cards with no filters
let cards = client.search_cards().await?;
match cards {
Some(c) => println!("{:?}", c),
None => println!("No cards found!")
}
// search_cards returns a builder with a number of methods to add filters
let cards = client
.search_cards()
.query("name:charizard")
.page(2)
.page_size(5)
.order_by("rarity")
.select("hp,flavor_text")
.await?;
match cards {
Some(c) => println!("{:?}", c),
None => println!("No cards found!")
}
All the same functions for cards exist for sets as well
let client = Client::with_api_key("API_KEY");
let set = client.get_set("swsh4").send().await?;
match set {
Some(c) => println!("{:?}", c),
None => println!("No set found!")
}
// Fetch sets with no filters
let sets = client.search_sets().await?;
match sets {
Some(c) => println!("{:?}", c),
None => println!("No sets found!")
}
// search_sets returns a builder with a number of methods to add filters
let sets = client
.search_sets()
.query("series:\"Sword & Shield\"")
.page(4)
.page_size(1)
.order_by("total")
.select("printed_total,total")
.await?;
match sets {
Some(c) => println!("{:?}", c),
None => println!("No sets found!")
}
These types only provide methods for fetching them all
let client = Client::with_api_key("API_KEY");
// All are Vec<String>
let types = client.get_types().await?;
let subtypes = client.get_subtypes().await?;
let supertypes = client.get_supertypes().await?;
let rarities = client.get_rarities().await?;
0.2.0
made a change that removed the public send()
method from each of the builders. To migrate to 0.2 from 0.1, simply remove any .send().await?;
and use .await?;
instead.
Ability.ability_type
to Ability.type
.first_edition_holofoil
and first_edition_normal
to TCGPlayerPrints
.direct_low
to TCGPlayerPrices
.