mtgio-sdk

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.

Integration

There is no way to retrieve this library using crates.io yet, will follow soon. ```

Cargo.toml

[dependencies] mtgapi-client = { git = "https://github.com/MagicTheGathering/mtg-sdk-rust" } ```

```

main.rs / lib.rs

extern crate mtgapi_client; ```

Documentation

~ Docs will follow after the crate has been published, you can build them locally by cloning and using 'cargo doc'

Usage

// Create a client with the specified (per request) timeout use mtgapi_client::MtgClient; let api = MtgClient::new(100);

Example: Get all Cards on pages 20 - 25

The Page size for cards requests is 100 cards by default.

``` // Create a unfiltered cards request let mut getcardsrequest = api.cards().all();

//Start at Page 20 getcardsrequest.set_page(20);

let mut cards: Vec = Vec::new(); //collect all cards from pages 20 to 25 for _ in 0..5 { let cards = getcardsrequest.nextpage()?.content; if cards.isempty() { break; } unfilteredcards.extend(cards); } println!("Unfiltered Cards: {:?}", unfilteredcards); ```

Example: Get all cards matching a filter

``` // Create a filtered cards request let mut getcardsrequest = api.cards().allfiltered( CardFilter::builder() .gameformat(GameFormat::Standard) .cardtypesor(&[CardType::Instant, CardType::Sorcery]) .convertedmana_cost(2) .rarities(&[CardRarity::Rare, CardRarity::MythicRare]) .build(), );

let mut cards: Vec = Vec::new(); //collect all cards matching the filter loop { let cards = getcardsrequest.nextpage()?.content; if cards.isempty() { break; } filteredcards.extend(cards); } println!("Filtered Cards: {:?}", filteredcards); ```

Some example API-calls

``` // Get all sets let sets = api.sets().all()?.content; println!("All Sets: {:?}", sets);

// Get an example booster pack from the specified set let boostercards = api.sets().booster("ktk")?.content; println!("Random Cards from Booster: {:?}", boostercards);

// Get all card types let types = api.types().all()?.content; println!("Types: {:?}", types);

// Get all card subtypes let subtypes = api.subtypes().all()?.content; println!("Subtypes: {:?}", subtypes);

// Get all card supertypes let supertypes = api.supertypes().all()?.content; println!("Supertypes: {:?}", supertypes);

// Get all game formats let formats = api.formats().all()?.content; println!("Formats: {:?}", formats); ```