Added some more fields
Got most of them done. Added a couple of cards too
This commit is contained in:
@@ -24,9 +24,71 @@ struct ScryfallCard {
|
||||
pub uri: String, //URI
|
||||
|
||||
// Gameplay Fields
|
||||
// https://scryfall.com/docs/api/cards#gameplay-fields
|
||||
pub all_parts: Option<Vec<ScryfallRelatedCardObject>>,
|
||||
pub card_faces: Option<Vec<ScryfallCardFaceObject>>,
|
||||
|
||||
// NOTE: Much of the next is a repeat of what's in the ScryfallCardFaceObject if you change something here, change something there
|
||||
// NOTE: Probably a bad idea to rename color -> colour just for the sake
|
||||
pub cmc: Option<f64>, // TODO: Make this a proper Decimal - see "Little Girl" card for example of cmc of 0.5
|
||||
#[serde(rename = "color_identity")]
|
||||
pub colour_identity: Vec<Colour>,
|
||||
#[serde(rename = "color_indicator")]
|
||||
pub colour_indicator: Option<Vec<Colour>>,
|
||||
#[serde(rename = "colors")]
|
||||
pub colours: Option<Vec<Colour>>,
|
||||
pub edhrec_rank: Option<u64>,
|
||||
pub defence: Option<String>,
|
||||
pub hand_modifier: Option<String>,
|
||||
pub keywords: Vec<String>, // Words like "Flying"
|
||||
pub legalities: FormatLegalities,
|
||||
pub life_modifier: Option<String>,
|
||||
pub loyalty: Option<String>,
|
||||
pub mana_cost: Option<String>,
|
||||
pub name: String,
|
||||
pub oracle_text: Option<String>,
|
||||
pub penny_rank: Option<u64>,
|
||||
pub power: Option<String>,
|
||||
pub produced_mana: Option<Vec<Colour>>,
|
||||
pub reserved: bool,
|
||||
pub toughness: Option<String>,
|
||||
pub type_line: String,
|
||||
|
||||
// Print Fields
|
||||
// https://scryfall.com/docs/api/cards#print-fields
|
||||
pub artist: Option<String>,
|
||||
pub artist_ids: Option<Vec<String>>,
|
||||
pub attraction_lights: Option<Vec<String>>, // TODO: I'm not actually sure what these look like - I should test
|
||||
pub booster: bool,
|
||||
#[serde(rename = "border_color")]
|
||||
pub border_colour: BorderColour,
|
||||
pub card_back_id: String, // UUID
|
||||
pub collector_number: String,
|
||||
pub content_warning: Option<bool>,
|
||||
pub digital: bool,
|
||||
pub finishes: Vec<Finish>,
|
||||
#[serde(rename = "flavor_name")]
|
||||
pub flavour_name: Option<String>,
|
||||
#[serde(rename = "flavor_text")]
|
||||
pub flavour_text: Option<String>,
|
||||
pub frame_effects: Option<Vec<FrameEffect>>,
|
||||
pub frame: Frame,
|
||||
pub full_art: bool,
|
||||
pub games: Vec<Game>,
|
||||
pub highres_image: bool,
|
||||
pub illustration_id: Option<String>, // UUID
|
||||
pub image_status: ImageStatus,
|
||||
pub image_uris: ImageURIs,
|
||||
pub oversized: bool,
|
||||
pub prices: Prices,
|
||||
pub printed_name: Option<String>,
|
||||
pub printed_text: Option<String>,
|
||||
pub printed_type_line: Option<String>,
|
||||
pub promo: bool,
|
||||
pub promo_types: Vec<String>, // TODO: Check what types exist - could be a enumeratable selection
|
||||
pub purchase_uris: Option<Vec<bool>>, // FIXME
|
||||
pub rarity: Rarity,
|
||||
// TODO - the rest (and the purachase URIs above)
|
||||
}
|
||||
|
||||
// https://scryfall.com/docs/api/cards#card-face-objects
|
||||
@@ -36,11 +98,14 @@ struct ScryfallCardFaceObject {
|
||||
pub artist: Option<String>,
|
||||
pub artist_id: Option<String>, // UUID
|
||||
pub cmc: Option<f64>, // TODO: Make this a proper Decimal - see "Little Girl" card for example of cmc of 0.5
|
||||
#[serde(rename = "color_identity")]
|
||||
pub colour_identity: Vec<Colour>,
|
||||
#[serde(rename = "color_indicator")]
|
||||
pub colour_indicator: Option<Vec<Colour>>,
|
||||
#[serde(rename = "colors")]
|
||||
pub colours: Option<Vec<Colour>>,
|
||||
pub defence: Option<String>,
|
||||
pub edhrec_rank: Option<u64>,
|
||||
// TODO: Complete
|
||||
}
|
||||
|
||||
// https://scryfall.com/docs/api/cards#related-card-objects
|
||||
@@ -67,10 +132,207 @@ enum Colour {
|
||||
Red,
|
||||
#[serde(rename = "G")]
|
||||
Green,
|
||||
//#[serde(rename = "C")]
|
||||
// Colourless
|
||||
// Just realised that colourless is just an empty vector... probably need a custom deserialiser,
|
||||
// or just handle it at a higher level... probably just that - the caller/user can figure it out
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
enum Legality {
|
||||
#[serde(rename = "legal")]
|
||||
Legal,
|
||||
#[serde(rename = "not_legal")]
|
||||
NotLegal,
|
||||
#[serde(rename = "banned")]
|
||||
Banned,
|
||||
#[serde(rename = "restricted")]
|
||||
Restricted,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct FormatLegalities {
|
||||
standard: Legality,
|
||||
future: Legality,
|
||||
historic: Legality,
|
||||
timeless: Legality,
|
||||
gladiator: Legality,
|
||||
pioneer: Legality,
|
||||
explorer: Legality,
|
||||
modern: Legality,
|
||||
legacy: Legality,
|
||||
pauper: Legality,
|
||||
vintage: Legality,
|
||||
penny: Legality,
|
||||
commander: Legality,
|
||||
oathbreaker: Legality,
|
||||
standardbrawl: Legality,
|
||||
brawl: Legality,
|
||||
alchemy: Legality,
|
||||
paupercommander: Legality,
|
||||
duel: Legality,
|
||||
oldschool: Legality,
|
||||
premodern: Legality,
|
||||
predh: Legality
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
enum BorderColour {
|
||||
#[serde(rename = "black")]
|
||||
Black,
|
||||
#[serde(rename = "white")]
|
||||
White,
|
||||
#[serde(rename = "borderless")]
|
||||
Borderless,
|
||||
#[serde(rename = "yellow")]
|
||||
Yellow,
|
||||
#[serde(rename = "silver")]
|
||||
Silver,
|
||||
#[serde(rename = "gold")]
|
||||
Gold
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
enum Finish {
|
||||
#[serde(rename = "foil")]
|
||||
Foil,
|
||||
#[serde(rename = "nonfoil")]
|
||||
NonFoil,
|
||||
#[serde(rename = "etched")]
|
||||
Etched
|
||||
}
|
||||
|
||||
// https://scryfall.com/docs/api/frames#frames
|
||||
// This is probably dumb...
|
||||
#[allow(dead_code)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
enum Frame {
|
||||
#[serde(rename = "1993")]
|
||||
NinetyThree,
|
||||
#[serde(rename = "1997")]
|
||||
NinetySeven,
|
||||
#[serde(rename = "2003")]
|
||||
OhThree,
|
||||
#[serde(rename = "2015")]
|
||||
OhFifteen,
|
||||
#[serde(rename = "future")]
|
||||
Future
|
||||
}
|
||||
|
||||
// https://scryfall.com/docs/api/frames#frame-effects
|
||||
#[allow(dead_code)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
enum FrameEffect {
|
||||
#[serde(rename = "legendary")]
|
||||
Legendary,
|
||||
#[serde(rename = "miracle")]
|
||||
Miracle,
|
||||
#[serde(rename = "enchantment")]
|
||||
Enchantment,
|
||||
#[serde(rename = "draft")]
|
||||
Draft,
|
||||
#[serde(rename = "devoid")]
|
||||
Devoid,
|
||||
#[serde(rename = "tombstone")]
|
||||
Tombstone,
|
||||
#[serde(rename = "colorshifted")]
|
||||
Colourshifted,
|
||||
#[serde(rename = "inverted")]
|
||||
Inverted,
|
||||
#[serde(rename = "sunmoondfc")]
|
||||
SunMoonDFC,
|
||||
#[serde(rename = "compasslanddfc")]
|
||||
CompassLandDFC,
|
||||
#[serde(rename = "originpwdfc")]
|
||||
OriginPwDFC,
|
||||
#[serde(rename = "mooneldrazidfc")]
|
||||
MoonEldraziDFC,
|
||||
#[serde(rename = "waxingandwaningmoondfc")]
|
||||
WaxingAndWaningMoonDFC,
|
||||
#[serde(rename = "showcase")]
|
||||
Showcase,
|
||||
#[serde(rename = "extendedart")]
|
||||
ExtendedArt,
|
||||
#[serde(rename = "companion")]
|
||||
Companion,
|
||||
#[serde(rename = "etched")]
|
||||
Etched,
|
||||
#[serde(rename = "snow")]
|
||||
Snow,
|
||||
#[serde(rename = "lesson")]
|
||||
Lesson,
|
||||
#[serde(rename = "shatteredglass")]
|
||||
ShatteredGlass,
|
||||
#[serde(rename = "convertdfc")]
|
||||
ConvertDFC,
|
||||
#[serde(rename = "fandfc")]
|
||||
FanDFC,
|
||||
#[serde(rename = "upsidedowndfc")]
|
||||
UpsideDownDFC,
|
||||
#[serde(rename = "spree")]
|
||||
Spree
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
enum Game {
|
||||
#[serde(rename = "paper")]
|
||||
Paper,
|
||||
#[serde(rename = "mtgo")]
|
||||
MTGO,
|
||||
#[serde(rename = "arena")]
|
||||
Arena
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
enum ImageStatus {
|
||||
#[serde(rename = "missing")]
|
||||
Missing,
|
||||
#[serde(rename = "placeholder")]
|
||||
Placeholder,
|
||||
#[serde(rename = "lowres")]
|
||||
LowResolution,
|
||||
#[serde(rename = "highres_scan")]
|
||||
HighResolutionScan
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct ImageURIs {
|
||||
png: Option<String>,
|
||||
border_crop: Option<String>,
|
||||
art_crop: Option<String>,
|
||||
large: Option<String>,
|
||||
normal: Option<String>,
|
||||
small: Option<String>
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Prices {
|
||||
usd: Option<String>, // TODO Convert to f64?
|
||||
usd_foil: Option<String>,
|
||||
usd_etched: Option<String>,
|
||||
eur: Option<String>,
|
||||
eur_foil: Option<String>,
|
||||
tix: Option<String>
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
enum Rarity {
|
||||
#[serde(rename = "common")]
|
||||
Common,
|
||||
#[serde(rename = "uncommon")]
|
||||
Uncommon,
|
||||
#[serde(rename = "rare")]
|
||||
Rare,
|
||||
#[serde(rename = "special")]
|
||||
Special,
|
||||
#[serde(rename = "mythic")]
|
||||
Mythic,
|
||||
#[serde(rename = "bonus")]
|
||||
Bonus
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -88,4 +350,24 @@ mod tests {
|
||||
let nissa: ScryfallCard = serde_json::from_str(&fc).unwrap();
|
||||
println!("{:#?}", nissa);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialise_black_lotus() {
|
||||
let mut f = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
f.push("test_files/black_lotus.json");
|
||||
assert!(f.exists());
|
||||
let fc = fs::read_to_string(f).unwrap();
|
||||
let bl: ScryfallCard = serde_json::from_str(&fc).unwrap();
|
||||
println!("{:#?}", bl);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialise_little_girl() {
|
||||
let mut f = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
f.push("test_files/little_girl.json");
|
||||
assert!(f.exists());
|
||||
let fc = fs::read_to_string(f).unwrap();
|
||||
let lg: ScryfallCard = serde_json::from_str(&fc).unwrap();
|
||||
println!("{:#?}", lg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user