Got most of the fields I think

This commit is contained in:
2025-02-04 23:21:23 +00:00
parent f576fe6cc8
commit 993ac46954
2 changed files with 85 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
chrono = { version = "0.4.39", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.138" serde_json = "1.0.138"
uuid = { version = "1.12.1", features = ["v4", "serde"] } uuid = { version = "1.12.1", features = ["v4", "serde"] }

View File

@@ -1,5 +1,7 @@
use serde::Deserialize; use serde::Deserialize;
use serde_json::Value;
use uuid::Uuid; use uuid::Uuid;
use chrono::NaiveDate;
// Info from here: // Info from here:
// https://scryfall.com/docs/api/cards // https://scryfall.com/docs/api/cards
@@ -86,10 +88,32 @@ struct ScryfallCard {
pub printed_text: Option<String>, pub printed_text: Option<String>,
pub printed_type_line: Option<String>, pub printed_type_line: Option<String>,
pub promo: bool, pub promo: bool,
pub promo_types: Option<Vec<String>>, // TODO: Check what types exist - could be a enumeratable selection pub promo_types: Option<Vec<String>>, // TODO enum?
//pub purchase_uris: Option<Vec<bool>>, // FIXME pub purchase_uris: Option<PurchaseUris>,
pub rarity: Rarity, pub rarity: Rarity,
// TODO - the rest (and the purachase URIs above) pub related_uris: Value, // TODO: - list all the URIs? Maybe? Who cares?
pub released_at: NaiveDate,
pub reprint: bool,
pub scryfall_set_uri: String, // URI
pub set_name: String,
pub set_search_uri: String, // URI
pub set_type: String, // TODO: Enum?
pub set_uri: String, // URI
pub set: String,
pub set_id: Uuid,
pub story_spotlight: bool,
pub textless: bool,
pub variation: bool,
pub variation_of: Option<Uuid>,
pub security_stamp: Option<SecurityStamp>,
pub watermark: Option<String>,
#[serde(rename = "preview.previewed_at")]
pub preview_previewed_at: Option<NaiveDate>,
#[serde(rename = "preview.source_uri")]
pub preview_source_uri: Option<String>, // URI
#[serde(rename = "preview.source")]
pub preview_source: Option<String>
} }
// https://scryfall.com/docs/api/cards#card-face-objects // https://scryfall.com/docs/api/cards#card-face-objects
@@ -106,7 +130,23 @@ struct ScryfallCardFaceObject {
#[serde(rename = "colors")] #[serde(rename = "colors")]
pub colours: Option<Vec<Colour>>, pub colours: Option<Vec<Colour>>,
pub defence: Option<String>, pub defence: Option<String>,
// TODO: Complete pub flavour_text: Option<String>,
pub illustration_id: Option<Uuid>,
pub image_uris: ImageURIs,
pub layout: Option<String>,
pub loyalty: Option<String>,
pub mana_cost: Option<String>,
pub name: String,
pub object: String,
pub oracle_id: Option<Uuid>,
pub oracle_text: Option<String>,
pub power: Option<String>,
pub printed_name: Option<String>,
pub printed_text: Option<String>,
pub printed_type_line: Option<String>,
pub toughness: Option<String>,
pub type_line: Option<String>,
pub watermark: Option<String>
} }
// https://scryfall.com/docs/api/cards#related-card-objects // https://scryfall.com/docs/api/cards#related-card-objects
@@ -115,7 +155,7 @@ struct ScryfallCardFaceObject {
struct ScryfallRelatedCardObject { struct ScryfallRelatedCardObject {
pub id: Uuid, pub id: Uuid,
pub object: String, // Always "related_card" pub object: String, // Always "related_card"
pub component: String, // One of token, meld_part, meld_result, combo_piece pub component: Component,
pub name: String, pub name: String,
pub type_line: String, pub type_line: String,
pub uri: String // URI pub uri: String // URI
@@ -214,7 +254,7 @@ enum Frame {
#[serde(rename = "2003")] #[serde(rename = "2003")]
OhThree, OhThree,
#[serde(rename = "2015")] #[serde(rename = "2015")]
OhFifteen, Fifteen,
#[serde(rename = "future")] #[serde(rename = "future")]
Future Future
} }
@@ -336,6 +376,44 @@ enum Rarity {
Bonus Bonus
} }
#[allow(dead_code)]
#[derive(Deserialize, Debug)]
struct PurchaseUris {
tcgplayer: String, // Option?
cardmarket: String,
cardhoarder: String,
}
#[allow(dead_code)]
#[derive(Deserialize, Debug)]
enum SecurityStamp {
#[serde(rename = "oval")]
Oval,
#[serde(rename = "triangle")]
Triangle,
#[serde(rename = "acorn")]
Acorn,
#[serde(rename = "circle")]
Circle,
#[serde(rename = "arena")]
Arena,
#[serde(rename = "heart")]
Heart
}
#[allow(dead_code)]
#[derive(Deserialize, Debug)]
enum Component {
#[serde(rename = "token")]
Token,
#[serde(rename = "meld_part")]
MeldPart,
#[serde(rename = "meld_result")]
MeldResult,
#[serde(rename = "combo_piece")]
ComboPiece,
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;