Crates.io | mtgapi-client |
lib.rs | mtgapi-client |
version | 0.2.0 |
source | src |
created_at | 2018-08-06 06:31:41.876324 |
updated_at | 2020-03-29 16:50:42.639165 |
description | API bindings for www.magicthegathering.io |
homepage | https://github.com/MagicTheGathering/mtg-sdk-rust |
repository | https://github.com/MagicTheGathering/mtg-sdk-rust |
max_upload_size | |
id | 77714 |
size | 89,435 |
Rust Wrapper around the https://magicthegathering.io/ API
In-depth documentation about the capabilities can be found here: https://docs.magicthegathering.io/
This Wrapper supplies the related methods to call the API and the conversion of the supplied json data into rust objects.
Documentation can be found on docs.rs: https://docs.rs/mtgapi-client
# Cargo.toml
[dependencies]
mtgapi-client = "0.1"
# main.rs / lib.rs
extern crate mtgapi_client;
// Create a client with the specified (per request) timeout
use mtgapi_client::MtgClient;
let api = MtgClient::new(100);
The Page size for cards requests is 100 cards by default.
// Create a unfiltered cards request
let mut get_cards_request = api.cards().all();
//Start at Page 20
get_cards_request.set_page(20);
let mut cards: Vec<CardDetail> = Vec::new();
//collect all cards from pages 20 to 25
for _ in 0..5 {
let response = get_cards_request.next_page().await?
let cards = response.content;
if cards.is_empty() {
break;
}
unfiltered_cards.extend(cards);
}
println!("Unfiltered Cards: {:?}", unfiltered_cards);
// Create a filtered cards request
let mut get_cards_request = api.cards().all_filtered(
CardFilter::builder()
.game_format(GameFormat::Standard)
.cardtypes_or(&[CardType::Instant, CardType::Sorcery])
.converted_mana_cost(2)
.rarities(&[CardRarity::Rare, CardRarity::MythicRare])
.build(),
);
let mut cards: Vec<CardDetail> = Vec::new();
//collect all cards matching the filter
loop {
let response = get_cards_request.next_page().await?
let cards = response.content;
if cards.is_empty() {
break;
}
filtered_cards.extend(cards);
}
println!("Filtered Cards: {:?}", filtered_cards);
// Get all sets
let sets = api.sets().all().await?.content;
println!("All Sets: {:?}", sets);
// Get an example booster pack from the specified set
let booster_cards = api.sets().booster("ktk").await?.content;
println!("Random Cards from Booster: {:?}", booster_cards);
// Get all card types
let types = api.types().all().await?.content;
println!("Types: {:?}", types);
// Get all card subtypes
let subtypes = api.subtypes().all().await?.content;
println!("Subtypes: {:?}", subtypes);
// Get all card supertypes
let supertypes = api.supertypes().all().await?.content;
println!("Supertypes: {:?}", supertypes);
// Get all game formats
let formats = api.formats().all().await?.content;
println!("Formats: {:?}", formats);