pokemontcgio

Crates.iopokemontcgio
lib.rspokemontcgio
version0.2.1
sourcesrc
created_at2024-08-27 15:27:59.976536
updated_at2024-11-15 13:17:51.241272
descriptionAn interface for interacting with the pokemontcg.io REST API
homepage
repositoryhttps://github.com/austinmh12/pokemon-tcg-io-rs
max_upload_size
id1353506
size49,969
Austin Heil (austinmh12)

documentation

README

Pokémon TCG IO API Wrapper

This is a wrapper for the REST API of pokemontcg.io that uses builder patterns inspired by reqwest.

Usage

Configuration

Run cargo add pokemontcgio or add the following to the Cargo.toml file:

[dependencies]
pokemontcgio = "0.2.1"

Using With an API Key

let client = Client::with_api_key("API_KEY");

Cards

Fetching a single card

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!")
}

Searching for cards

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!")
}

Sets

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!")
}

Types, Subtypes, Supertypes and Rarities

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?;

Migrating from 0.1.0

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.

Changelog

v0.2.1

  • Changed Ability.ability_type to Ability.type.
  • Added first_edition_holofoil and first_edition_normal to TCGPlayerPrints.
  • Added direct_low to TCGPlayerPrices.
  • Updated documentation.
Commit count: 36

cargo fmt