1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#![deny(missing_docs)]
//! [Scryfall](https://scryfall.com) provides a REST-like API for ingesting our card data
//! programatically. The API exposes information available on the regular site in easy-to-consume
//! formats.
//!
//! ## Cards
//! The main way to fetch cards from this API is the [`Card`] struct.
//!
//! This allows you to get cards from `scryfall` using all of their available
//! REST Apis
//!
//! ```rust,no_run
//! use scryfall::card::Card;
//! match Card::named_fuzzy("Light Bolt") {
//!     Ok(card) => assert_eq!(card.name, "Lightning Bolt"),
//!     Err(e) => panic!(format!("{:?}", e))
//! }
//! ```
//!
//! ## Sets
//! You can also fetch information about a card set.
//!
//! The available routes for this can be seen on [`Set`]
//!
//! ```rust,no_run
//! use scryfall::set::Set;
//! assert_eq!(Set::code("mmq").unwrap().name, "Mercadian Masques")
//! ```
//!
//! ## Catalogs
//! Finally `scryfall` also allows you to fetch *catalogs* witch
//! are collections of Magic the Gathering data points.
//!
//! For example, one could fetch all available card names.
//! ```rust,no_run
//! use scryfall::catalog::Catalog;
//! assert!(Catalog::card_names().unwrap().data.len() > 0)
//! ```
//!
//! ## Advanced Search
//! One of the main features of `scryfall` is it's advanced search.
//! For this the [`card_searcher`] module provides a type safe api
//! to interact and query the search engine.
//!
//! [`Card`]: card/struct.Card.html
//! [`Set`]: set/struct.Set.html
//! [`card_searcher`]: card_searcher/index.html
pub mod bulk;
pub mod card;
pub mod card_searcher;
pub mod catalog;
pub mod error;
pub mod format;
pub mod ruling;
pub mod set;
pub mod util;

pub use error::Result;

#[cfg(test)]
mod tests {
    use crate::{
        card_searcher::{SearchBuilder, StringParam},
        set::{set_code::SetCode, Set},
    };
    use rayon::prelude::*;
    use serde_json::{from_str, to_string};
    use std::convert::TryFrom;

    #[test]
    fn set_code_serde_test() {
        let instance = SetCode::try_from("war").unwrap();
        let new_instance: SetCode = from_str(&to_string(&instance).unwrap()).unwrap();
        assert_eq!(new_instance, instance);

        let instance = SetCode::try_from("wwar").unwrap();
        let new_instance: SetCode = from_str(&to_string(&instance).unwrap()).unwrap();
        assert_eq!(new_instance, instance)
    }

    #[test]
    #[ignore]
    fn all_sets() {
        let mut page = 1;
        for sets in Set::all() {
            if let Err(e) = sets {
                panic!("Couldn't parse sets at page {}. Error: {}", page, e);
            }
            page += 1;
        }
    }

    #[test]
    #[ignore]
    fn lattest_cards() {
        Set::all()
            .map(Result::unwrap)
            .flatten()
            .take(30)
            .par_bridge()
            .for_each(|set| {
                SearchBuilder::new()
                    .param(StringParam::Set(set.code))
                    .search()
                    .enumerate()
                    .for_each(|(i, c)| {
                        if let Err(e) = c {
                            panic!("Card {} in set {} couldn't be parsed: {}", i, set.name, e)
                        }
                    });
            })
    }
}