pokemon-tcg-sdk

Crates.iopokemon-tcg-sdk
lib.rspokemon-tcg-sdk
version0.3.0
sourcesrc
created_at2022-01-11 17:10:58.719884
updated_at2022-01-24 00:54:40.006869
descriptionPokémon TCG SDK is a rust wrapper around the Pokémon TCG API located at pokemontcg.io
homepage
repositoryhttps://github.com/mattoni/pokemon-tcg-sdk-rust
max_upload_size
id512338
size40,011
Alexander Mattoni (mattoni)

documentation

README

Pokémon TCG SDK - Rust

This is the Pokémon TCG SDK Rust implementation. It is a wrapper around the Pokémon TCG API of pokemontcg.io.

Usage

Configuration

[dependencies]
pokemon-tcg-sdk = "0.3.0"

Using an API Key

// This method fails for the same reasons a reqwest::ClientBuilder would fail (TLS, system config)
// or if your API key contains invalid characters for a header.
let client = Client::with_api_key("YOUR_API_KEY")?;

Cards

Get a single card by ID

let client = Client::default();
let card = client.get_card(GetCardRequest::new("base1-1")).await;

match card {
    // Card
    Ok(c) => println!("{:?}", c),
    // Will be a 'ClientError' enum
    Err(e) => println!("{:?}", e),
}

Filter cards via the q parameter

let client = Client::default();
let cards = client.search_cards(SearchCardsRequest::new("name:celebi")).await;

match cards {
    // Vec<Card>
    Ok(c) => println!("{:?}", c),
    // Will be a 'ClientError' enum
    Err(e) => println!("{:?}", e),
}

// You can also construct a SearchCardsRequest with more parameters
let search_request = SearchCardsRequest {
    query: Some(String::from("name:celebi")),
    page: Some(10),
    page_size: None,
    order_by: None,
}

Automatically page through card data

let client = Client::default();
let cards = client.get_all_cards().await;

match cards {
    // Vec<Card>
    Ok(c) => println!("{:?}", c),
    // Will be a 'ClientError' enum
    Err(e) => println!("{:?}", e),
}

Sets

Get a single set by ID

let client = Client::default();
let set = client.get_set(GetSetRequest::new("base1")).await;

match set {
    // Set
    Ok(s) => println!("{:?}", s),
    // Will be a 'ClientError' enum
    Err(e) => println!("{:?}", e),
}

Filter sets via the q parameter

let client = Client::default();
let sets = client.search_sets(SearchSetsRequest::new("series:base")).await;

match sets {
    // Vec<Set>
    Ok(s) => println!("{:?}", s),
    // Will be a 'ClientError' enum
    Err(e) => println!("{:?}", e),
}

// You can also construct a SearchSetsRequest with more parameters
let search_request = SearchSetsRequest {
    query: Some(String::from("series:base")),
    page: Some(2),
    page_size: None,
    order_by: None,
}

Automatically page through set data

let client = Client::default();
let sets = client.get_all_sets().await;

match sets {
    // Vec<Set>
    Ok(s) => println!("{:?}", s),
    // Will be a 'ClientError' enum
    Err(e) => println!("{:?}", e),
}

Supertypes

let client = Client::default();
let types = client.get_supertypes().await;

match types {
    // Vec<String>
    Ok(c) => println!("{:?}", c),
    // Will be a 'ClientError' enum
    Err(e) => println!("{:?}", e),
}

Subtypes

let client = Client::default();
let types = client.get_subtypes().await;

match types {
    // Vec<String>
    Ok(c) => println!("{:?}", c),
    // Will be a 'ClientError' enum
    Err(e) => println!("{:?}", e),
}

Types

let client = Client::default();
let types = client.get_types().await;

match types {
    // Vec<String>
    Ok(c) => println!("{:?}", c),
    // Will be a 'ClientError' enum
    Err(e) => println!("{:?}", e),
}

Rarities

let client = Client::default();
let types = client.get_rarities().await;

match types {
    // Vec<String>
    Ok(c) => println!("{:?}", c),
    // Will be a 'ClientError' enum
    Err(e) => println!("{:?}", e),
}
Commit count: 9

cargo fmt