scruffy/client/cards
Requests and response decoders for Scryfall’s Cards endpoints.
Each endpoint is a pair of plain functions: a *_request that builds
the Request(String) to send, and a *_response that decodes the
Response(String) you got back into a Card (or the handful of
endpoints that return something else) – or a client.ClientError
describing what went wrong. Several endpoints below share a
*_response function since they decode the same shape; the doc comment
on each *_request says which one to pair it with.
See https://scryfall.com/docs/api/cards for the upstream reference.
Types
The response to a get_card_collection_request request: the cards that
were found, plus any identifiers that couldn’t be matched to a card.
pub type CardCollection {
CardCollection(
data: List(card.Card),
not_found: List(CardIdentifier),
)
}
Constructors
-
CardCollection( data: List(card.Card), not_found: List(CardIdentifier), )
A way of identifying a single card within a get_card_collection_request
request.
pub type CardIdentifier {
IdentifierById(String)
IdentifierByMtgoId(Int)
IdentifierByMultiverseId(Int)
IdentifierByOracleId(String)
IdentifierByIllustrationId(String)
IdentifierByName(String)
IdentifierByNameAndSet(name: String, set: String)
IdentifierByCollectorNumber(
set: String,
collector_number: String,
)
}
Constructors
-
IdentifierById(String) -
IdentifierByMtgoId(Int) -
IdentifierByMultiverseId(Int) -
IdentifierByOracleId(String) -
IdentifierByIllustrationId(String) -
IdentifierByName(String) -
IdentifierByNameAndSet(name: String, set: String) -
IdentifierByCollectorNumber( set: String, collector_number: String, )
A way of identifying a card by name, either exactly or through Scryfall’s fuzzy-matching algorithm.
pub type NameQuery {
Exact(String)
Fuzzy(String)
}
Constructors
-
Exact(String) -
Fuzzy(String)
Optional parameters accepted by search_cards_request.
pub type SearchOptions {
SearchOptions(
unique: option.Option(UniqueMode),
order: option.Option(SortOrder),
dir: option.Option(SortDirection),
include_extras: option.Option(Bool),
include_multilingual: option.Option(Bool),
include_variations: option.Option(Bool),
page: option.Option(Int),
)
}
Constructors
-
SearchOptions( unique: option.Option(UniqueMode), order: option.Option(SortOrder), dir: option.Option(SortDirection), include_extras: option.Option(Bool), include_multilingual: option.Option(Bool), include_variations: option.Option(Bool), page: option.Option(Int), )
The direction search_cards results are sorted in.
pub type SortDirection {
Auto
Ascending
Descending
}
Constructors
-
Auto -
Ascending -
Descending
The field search_cards results are sorted by.
pub type SortOrder {
ByName
BySet
ByReleased
ByRarity
ByColor
ByUsd
ByTix
ByEur
ByCmc
ByPower
ByToughness
ByEdhrec
ByPenny
ByArtist
ByReview
}
Constructors
-
ByName -
BySet -
ByReleased -
ByRarity -
ByColor -
ByUsd -
ByTix -
ByEur -
ByCmc -
ByPower -
ByToughness -
ByEdhrec -
ByPenny -
ByArtist -
ByReview
How cards with multiple versions should be collapsed by search_cards.
pub type UniqueMode {
UniqueCards
UniqueArt
UniquePrints
}
Constructors
-
UniqueCards -
UniqueArt -
UniquePrints
Values
pub fn autocomplete_card_name_request(
q: String,
include_extras: option.Option(Bool),
) -> request.Request(String)
Build a request for a Catalog of Magic-related word fragments that can be used as the start of a full card name, for use in a typeahead search bar.
pub fn autocomplete_card_name_response(
resp: response.Response(String),
) -> Result(catalog.Catalog(String), client.ClientError)
Decode a response as a Catalog(String). Pairs with
autocomplete_card_name_request.
pub fn card_collection_response(
resp: response.Response(String),
) -> Result(CardCollection, client.ClientError)
Decode a response as a CardCollection. Pairs with
get_card_collection_request.
pub fn card_list_response(
resp: response.Response(String),
) -> Result(
scryfall_list.ScryfallList(card.Card),
client.ClientError,
)
Decode a response as a ScryfallList(Card). Pairs with
get_cards_manifest_request and search_cards_request.
pub fn card_response(
resp: response.Response(String),
) -> Result(card.Card, client.ClientError)
Decode a response as a single Card. Pairs with every get_card_by_*
and get_card_by_name_request/get_random_card_request below.
pub fn get_card_by_arena_id_request(
id: Int,
) -> request.Request(String)
Build a request for a single card by its MTG Arena ID. Pair the response
with card_response.
pub fn get_card_by_cardmarket_id_request(
id: Int,
) -> request.Request(String)
Build a request for a single card by its Cardmarket product ID. Pair the
response with card_response.
pub fn get_card_by_id_request(
id: String,
) -> request.Request(String)
Build a request for a single card by its Scryfall ID. Pair the response
with card_response.
pub fn get_card_by_mtgo_id_request(
id: Int,
) -> request.Request(String)
Build a request for a single card by its Magic Online ID. Pair the
response with card_response.
pub fn get_card_by_multiverse_id_request(
id: Int,
) -> request.Request(String)
Build a request for a single card by its multiverse ID, as assigned by
Wizards’ Gatherer. Pair the response with card_response.
pub fn get_card_by_name_request(
query: NameQuery,
set: option.Option(String),
) -> request.Request(String)
Build a request for a single card by name, optionally scoped to a
particular set. Pair the response with card_response.
pub fn get_card_by_set_and_number_request(
set: String,
collector_number: String,
lang: option.Option(language.Language),
) -> request.Request(String)
Build a request for a single card by its set code, collector number, and
(optionally) a specific language. Pair the response with
card_response.
pub fn get_card_by_tcgplayer_id_request(
id: Int,
) -> request.Request(String)
Build a request for a single card by its TCGplayer product ID. Pair the
response with card_response.
pub fn get_card_collection_request(
identifiers: List(CardIdentifier),
) -> request.Request(String)
Build a request for up to 75 cards at once, identified in bulk by ID,
name, or set/collector number. Pair the response with
card_collection_response.
pub fn get_cards_manifest_request() -> request.Request(String)
Build a request for a lightweight manifest of every card Scryfall has on
file. Pair the response with card_list_response.
pub fn get_random_card_request(
q: option.Option(String),
) -> request.Request(String)
Build a request for a random card, optionally scoped to cards matching a
search query. Pair the response with card_response.
pub fn search_cards_request(
q: String,
options: SearchOptions,
) -> request.Request(String)
Build a request to search for cards using Scryfall’s full-text search
syntax. Pair the response with card_list_response.