extern crate serde; extern crate serde_json; #[macro_use] extern crate serde_derive; extern crate reqwest; #[macro_use] extern crate derive_error; use std::collections::HashMap; use std::io::Read; pub struct Scryfall {} impl Scryfall { pub fn new() -> Scryfall { Scryfall {} } pub fn search(&self, query: &str) -> Result { let mut response = reqwest::get(&format!("https://api.scryfall.com/cards/search?q={}", query))?; let mut content = String::new(); response.read_to_string(&mut content); Result::Ok(serde_json::from_str(&content)?) } } #[derive(Serialize, Deserialize, Debug)] pub struct CardList { pub data: Vec, pub has_more: bool, pub next_page: Option, pub total_cards: u32, pub warnings: Option> } #[derive(Serialize, Deserialize, Debug)] pub struct Card { pub id: String, pub multiverse_ids: Vec, pub mtgo_id: Option, pub mtgo_foil_id: Option, pub uri: String, pub scryfall_uri: String, pub rulings_uri: String, pub name: String, pub layout: String, pub cmc: f32, pub type_line: String, pub oracle_text: Option, pub mana_cost: String, pub power: Option, pub toughness: Option, pub loyalty: Option, pub life_modifier: Option, pub hand_modifier: Option, pub colors: Colors, pub color_indicator: Option, pub color_identity: Colors, pub all_parts: Option>, pub card_faces: Option>, pub legalities: HashMap, pub reserved: bool, pub edhrec_rank: Option, pub set: String, pub set_name: String, pub collector_number: String, pub set_search_uri: String, pub scryfall_set_uri: String, pub image_uris: Option>, pub highres_image: bool, pub reprint: bool, pub digital: bool, pub rarity: String, pub flavor_text: Option, pub artist: Option, pub frame: String, pub full_art: bool, pub watermark: Option, pub border_color: String, pub story_spotlight_number: Option, pub story_spotlight_uri: Option, pub timeshifted: bool, pub colorshifted: bool, pub futureshifted: bool } type Colors = Vec; #[derive(Serialize, Deserialize, Debug)] pub struct RelatedCard { pub id: String, pub name: String, pub uri: String } #[derive(Serialize, Deserialize, Debug)] pub struct CardFace { pub name: String, pub type_line: String, pub oracle_text: Option, pub mana_cost: String, pub colors: Colors, pub color_indicator: Option, pub power: Option, pub toughness: Option, pub loyalty: Option, pub flavor_text: Option, pub image_uris: Option> } #[derive(Debug, Error)] pub enum Error { /// HTTP request failed HTTP(reqwest::Error), /// Failed to parse Parse(serde_json::Error) } #[cfg(test)] mod tests { #[test] fn it_works() { assert_eq!(2 + 2, 4); } }