Gatherer is the canonical source for Magic: The Gathering card details. While useful, it lacks an interface for retrieving this data programmatically. The lack of an API makes creating Magic-related applications unnecessarily difficult.
Tutor is a simple JavaScript interface for Gatherer.
API
tutor.card
tutor.card(id, callback(err, card))
tutor.card(name, callback(err, card))
tutor.card(details, callback(err, card))
The first and second forms are shorthand for tutor.card({id: id}, ...)
and
tutor.card({name: name}, ...)
respectively. The callback is passed an object
representing the specified card. Version-specific metadata such as flavor text
and rarity are included for cards specified by id. Attributes not applicable
to the card type (e.g. lands have no mana cost) or not present (e.g. certain
creatures have no rules text) are omitted.
tutorcard 'Demonic Tutor' consolelog cardname # => "Demonic Tutor" consolelog cardmana_cost # => "{1}{B}" consolelog cardtext # => "Search your library for a card and put that card into your hand. Then shuffle your library."
Split cards
Because the two sides of a split card share a Gatherer id, it's necessary to provide the name of the desired side:
tutorcard id: 27165name: 'Fire' consolelog cardname # => "Fire" tutorcard id: 27165name: 'Ice' consolelog cardname # => "Ice"
Retrieving either side of a split card by name is straightforward:
tutorcard 'Fire' consolelog cardname # => "Fire" tutorcard 'Ice' consolelog cardname # => "Ice"
Flip cards
Retrieving the top half of a flip card by id is straightforward:
tutorcard 247175 consolelog cardname # => "Nezumi Graverobber"
Either half of a flip card can be retrieved explicitly by setting which
to
"a"
(for the upper half) or "b"
(for the lower half):
tutorcard id: 247175which: 'b' consolelog cardname # => "Nighteyes the Desecrator"
When retrieving a flip card by name rather than id, one may simply provide the name of the desired half:
tutorcard 'Nighteyes the Desecrator' consolelog cardname # => "Nighteyes the Desecrator"
Double-faced cards
Either face of a double-faced card can be retrieved by id:
tutorcard 262675 consolelog cardname # => "Afflicted Deserter" tutorcard 262698 consolelog cardname # => "Werewolf Ransacker"
Or by name:
tutorcard 'Afflicted Deserter' consolelog cardname # => "Afflicted Deserter" tutorcard 'Werewolf Ransacker' consolelog cardname # => "Werewolf Ransacker"
tutor.set
tutor.set(name, callback(err, set))
Scrape cards from the set specified by name
. For example:
tutorset 'Homelands' consolelog cardslength # => 115 consolelog Objectkeyscards0sort # => [ # "converted_mana_cost", # "expansion", # "gatherer_url", # "image_url", # "mana_cost", # "name", # "power", # "rarity", # "subtypes", # "supertypes", # "text", # "toughness", # "types", # "versions" # ]
tutor.formats
tutor.formats(callback(err, formatNames))
Provides the names of all the game's formats:
tutorformats consolelog formatNames # => [ # "Classic", # "Commander", # ... # "Vintage", # "Zendikar Block" # ]
tutor.sets
tutor.sets(callback(err, setNames))
Provides the names of all the game's sets:
tutorsets consolelog setNames # => [ # "Alara Reborn", # "Alliances", # ... # "Worldwake", # "Zendikar" # ]
tutor.types
tutor.types(callback(err, types))
Provides the names of all the game's types:
tutortypes consolelog types # => [ # "Artifact", # "Basic", # ... # "Vanguard", # "World" # ]
CLI
npm install tutor --global
will make the tutor
command available globally.
$ tutor card 'Demonic Tutor'
Demonic Tutor {1}{B} Search your library for a card and put that card into your hand. Then shuffle your library.
$ tutor card 'Demonic Tutor' --format json | python -mjson.tool | head -n 10
{
"community_rating": {
"rating": 4.714,
"votes": 229
},
"converted_mana_cost": 2,
"languages": {},
"legality": {
"Commander": "Legal",
"Legacy": "Banned",
$ tutor card 60 --format json | python -mjson.tool | head -n 10
{
"artist": "Douglas Schuler",
"community_rating": {
"rating": 4.917,
"votes": 109
},
"converted_mana_cost": 2,
"expansion": "Limited Edition Alpha",
"languages": {},
"legality": {
$ tutor set Alliances | head -n 2
Aesthir Glider {3} 2/1 Flying Aesthir Glider can't block.
Agent of Stromgald {R} 1/1 {R}: Add {B} to your mana pool.
Example of using the CLI from other applications:
Running the tests
make fixtures
make test
make testcli