2021-07-16 16:06:33 +00:00
|
|
|
module Card exposing (..)
|
|
|
|
|
|
|
|
import Json.Decode
|
|
|
|
import Json.Decode.Pipeline as JDP
|
|
|
|
|
|
|
|
|
2021-07-17 07:18:49 +00:00
|
|
|
type alias Prices =
|
2023-01-12 04:56:20 +00:00
|
|
|
{ usd : Maybe Float
|
|
|
|
, usd_foil : Maybe Float
|
|
|
|
, eur : Maybe Float
|
|
|
|
, eur_foil : Maybe Float
|
|
|
|
, tix : Maybe Float
|
2021-07-17 07:18:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-10 17:31:31 +00:00
|
|
|
type alias Oracle =
|
|
|
|
{ oracleId : String
|
|
|
|
, name : String
|
2023-01-11 22:10:48 +00:00
|
|
|
, manaCost : String
|
2023-01-12 02:37:52 +00:00
|
|
|
, cmc : Float
|
2023-01-11 04:12:33 +00:00
|
|
|
, typeLine : String
|
2023-01-10 17:31:31 +00:00
|
|
|
, oracleText : String
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-16 16:06:33 +00:00
|
|
|
type alias Card =
|
|
|
|
{ scryfallId : String
|
|
|
|
, name : String
|
|
|
|
, setCode : String
|
|
|
|
, rarity : String
|
2023-01-11 22:10:48 +00:00
|
|
|
, manaCost : String
|
2023-01-12 02:37:52 +00:00
|
|
|
, cmc : Float
|
2023-01-11 04:12:33 +00:00
|
|
|
, typeLine : String
|
2021-07-17 03:18:06 +00:00
|
|
|
, oracleText : String
|
2021-07-17 07:18:49 +00:00
|
|
|
, prices : Prices
|
2023-01-11 02:21:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type alias Copy =
|
|
|
|
{ card : Card
|
2022-08-03 04:30:58 +00:00
|
|
|
, collection : String
|
|
|
|
, foil : Bool
|
2021-07-16 16:06:33 +00:00
|
|
|
}
|
|
|
|
|
2022-08-03 04:30:58 +00:00
|
|
|
|
2023-01-10 17:31:31 +00:00
|
|
|
decodeOracle : Json.Decode.Decoder Oracle
|
|
|
|
decodeOracle =
|
|
|
|
Json.Decode.succeed Oracle
|
|
|
|
|> JDP.required "oracle_id" Json.Decode.string
|
|
|
|
|> JDP.required "name" Json.Decode.string
|
2023-01-11 22:10:48 +00:00
|
|
|
|> JDP.required "mana_cost"
|
|
|
|
(Json.Decode.nullable Json.Decode.string
|
|
|
|
|> Json.Decode.map (Maybe.withDefault "")
|
|
|
|
)
|
2023-01-12 02:37:52 +00:00
|
|
|
|> JDP.required "cmc" Json.Decode.float
|
2023-01-11 04:12:33 +00:00
|
|
|
|> JDP.required "type_line" Json.Decode.string
|
2023-01-10 17:31:31 +00:00
|
|
|
|> JDP.required "oracle_text"
|
|
|
|
(Json.Decode.nullable Json.Decode.string
|
|
|
|
|> Json.Decode.map (Maybe.withDefault "")
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-07-16 16:06:33 +00:00
|
|
|
decode : Json.Decode.Decoder Card
|
|
|
|
decode =
|
|
|
|
Json.Decode.succeed Card
|
|
|
|
|> JDP.required "scryfall_id" Json.Decode.string
|
|
|
|
|> JDP.required "name" Json.Decode.string
|
|
|
|
|> JDP.required "set_code" Json.Decode.string
|
|
|
|
|> JDP.required "rarity" Json.Decode.string
|
2023-01-11 22:10:48 +00:00
|
|
|
|> JDP.required "mana_cost"
|
|
|
|
(Json.Decode.nullable Json.Decode.string
|
|
|
|
|> Json.Decode.map (Maybe.withDefault "")
|
|
|
|
)
|
2023-01-12 02:37:52 +00:00
|
|
|
|> JDP.required "cmc" Json.Decode.float
|
2023-01-11 04:12:33 +00:00
|
|
|
|> JDP.required "type_line" Json.Decode.string
|
2021-07-17 03:18:06 +00:00
|
|
|
|> JDP.required "oracle_text"
|
|
|
|
(Json.Decode.nullable Json.Decode.string
|
|
|
|
|> Json.Decode.map (Maybe.withDefault "")
|
|
|
|
)
|
2021-07-17 07:18:49 +00:00
|
|
|
|> JDP.required "prices" decodePrices
|
2023-01-11 02:21:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
decodeCopy : Json.Decode.Decoder Copy
|
|
|
|
decodeCopy =
|
|
|
|
Json.Decode.succeed Copy
|
|
|
|
|> JDP.required "card" decode
|
2022-08-03 04:30:58 +00:00
|
|
|
|> JDP.required "collection" Json.Decode.string
|
|
|
|
|> JDP.required "foil" Json.Decode.bool
|
2021-07-17 07:18:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
decodePrices : Json.Decode.Decoder Prices
|
|
|
|
decodePrices =
|
|
|
|
Json.Decode.succeed Prices
|
2023-01-12 04:56:20 +00:00
|
|
|
|> JDP.required "usd" (Json.Decode.nullable Json.Decode.float)
|
|
|
|
|> JDP.required "usd_foil" (Json.Decode.nullable Json.Decode.float)
|
|
|
|
|> JDP.required "eur" (Json.Decode.nullable Json.Decode.float)
|
|
|
|
|> JDP.required "eur_foil" (Json.Decode.nullable Json.Decode.float)
|
|
|
|
|> JDP.required "tix" (Json.Decode.nullable Json.Decode.float)
|