#card #api-wrapper #pokémon #sdk #tcg #io #set

pokemon-tcg-sdk

Pokémon TCG SDK is a rust wrapper around the Pokémon TCG API located at pokemontcg.io

4 releases (2 breaking)

0.3.0 Jan 24, 2022
0.2.0 Jan 11, 2022
0.1.1 Jan 11, 2022
0.1.0 Jan 11, 2022

#2331 in Web programming

43 downloads per month

MIT license

39KB
727 lines

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),
}

Dependencies

~6–19MB
~287K SLoC