Class: Scryfall::Card

Inherits:
Client
  • Object
show all
Defined in:
lib/scryfall/card.rb

Class Method Summary collapse

Methods inherited from Client

#connection, connection, connection=, #initialize, #method_missing, #to_h

Constructor Details

This class inherits a constructor from Scryfall::Client

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Scryfall::Client

Class Method Details

.autocomplete(q, format: "json", pretty: false) ⇒ Object

Returns a Catalog object container up to 20 full English card names that could be auto-completions of the given string parameter scryfall.com/docs/api/cards/autocomplete

Parameters:

  • q (String)

    The string to autocomplete

  • format (String) (defaults to: "json")

    The data format to return. This method only supports json.

  • pretty (Boolean) (defaults to: false)

    If true, the returned JSON will be prettified. Avoid using for production code.



81
82
83
84
85
86
87
88
# File 'lib/scryfall/card.rb', line 81

def autocomplete(q, format: "json", pretty: false)
  req = Request.new(
                   params = {q: q},
                   headers = nil,
                   body = nil)

  Scryfall::Catalog.new JSON.parse(connection.get("/cards/autocomplete", req).body)
end

.collection(identifiers, pretty: false) ⇒ Object

Accepts a JSON array of card identifiers, and returns a List object with the collection of requested cards. A maximum of 75 card references may be submitted per request. scryfall.com/docs/api/cards/collection

Parameters:

  • identifiers (Array)

    An array of JSON objects, each one a card identifier.

  • pretty (Boolean) (defaults to: false)

    If true, the returend JSON will be prettified. Avoid using for production code.



123
124
125
126
127
128
129
# File 'lib/scryfall/card.rb', line 123

def collection(identifiers, pretty: false)
  req = Request.new(params = nil,
                    headers = {'Content-Type' => 'application/json'},
                    body = identifiers)

  Scryfall::Search.post("/cards/collection", self, req)
end

.id(id) ⇒ Scryfall::Card

Returns a single card with the given Scryfall ID. scryfall.com/docs/api/cards/id

Parameters:

  • id (String)

    ID of the card to retrieve

Returns:



136
137
138
139
140
141
142
# File 'lib/scryfall/card.rb', line 136

def id(id)
  req = Request.new(params = nil,
                    headers = nil,
                    body = nil)

  Scryfall::Card.new JSON.parse(connection.get("/cards/#{id}", req).body)
end

.named(name, mode: "exact", set: nil, format: "json", face: nil, version: "large", pretty: false) ⇒ Object

Returns a Card based on a name search string. scryfall.com/docs/api/cards/named

Parameters:

  • name (String)

    Name of the card to retrieve

  • mode (String) (defaults to: "exact")

    The level of search specificity (‘exact’ or ‘fuzzy’)

  • set (String) (defaults to: nil)

    A set code to limit the search to one set.

  • format (String) (defaults to: "json")

    The data format to return (json, text, or image)

  • face (String) (defaults to: nil)

    If using the image format and this parameter has the value ‘back’, the back of the card will be returned. Will return a 404 if this card has no back face.

  • version (String) (defaults to: "large")

    The image version to return when using the ‘image’ format (small, normal, large, png, art_crop, or border_crop)

  • pretty (Boolean) (defaults to: false)

    If true, the returned JSON will be prettified. Avoid using for production code.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/scryfall/card.rb', line 57

def named(name, mode: "exact", set: nil, format: "json", face: nil, version: "large", pretty: false)
  params = {
      mode => name,
      set: set,
      format: format,
      face: face,
      version: version,
      pretty: pretty
  }

  req = Request.new(params = params,
                    headers = nil,
                    body = nil)

  Scryfall::Card.new JSON.parse(connection.get("/cards/named", req).body)
end

.random(q: nil, format: "json", face: nil, version: "large", pretty: false) ⇒ Object

Returns a single, random Card object. scryfall.com/docs/api/cards/random

Parameters:

  • q (String) (defaults to: nil)

    An optional fulltext search query to filter the pool of random cards. Make sure that your parameter is properly encoded (en.wikipedia.org/wiki/Percent-encoding)

  • format (String) (defaults to: "json")

    The data format to return (json, text, or image)

  • face (String) (defaults to: nil)

    If using the image format and this parameter has the value ‘back’, the back of the card will be returned. Will return a 404 if this card has no back face.

  • version (String) (defaults to: "large")

    The image version to return when using the ‘image’ format (small, normal, large, png, art_crop, or border_crop)

  • pretty (Boolean) (defaults to: false)

    If true, the returned JSON will be prettified. Avoid using for production code. # @param face [String]



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/scryfall/card.rb', line 101

def random(q: nil, format: "json", face: nil, version: "large", pretty: false)
  params = {
      q: q,
      format: format,
      face: face,
      version: version,
      pretty: pretty
  }

  req = Request.new(params = params,
                    headers = nil,
                    body = nil)

  Scryfall::Card.new JSON.parse(connection.get("/cards/random", req).body)
end

.search(q, unique: "cards", order: "name", dir: "auto", include_extras: false, include_multilingual: false, include_variations: false, page: 1, format: "json", pretty: false) ⇒ Object

Returns a List contained Cards found using a fulltext search string. This string supports the same fulltext search system that the main site uses. (scryfall.com/docs/syntax) scryfall.com/docs/api/cards/search

Parameters:

  • q (String)

    A fulltext search query. Make sure that your parameter is properly encoded.

  • unique (String) (defaults to: "cards")

    Specifies if Scryfall should remove “duplicate” results in your query. (cards, art prints)

  • order (String) (defaults to: "name")

    The method to sort returned cards. (name, set, released, rarity, color, usd, tix, eur, cmc, power, toughness, edhrec, artist)

  • dir (String) (defaults to: "auto")

    The direction to sort cards. (auto, asc, desc)

  • include_extras (Boolean) (defaults to: false)

    If true, extra cards (tokens, planes, etc.) will be included. Equivalent to adding include:extras to the fulltext search. Defaults to false.

  • include_multilingual (Boolean) (defaults to: false)

    If true, cards in every language supported by Scryfall will be included.

  • include_variations (Boolean) (defaults to: false)

    If true, rare care variations will be included. (Hairy Runesword, etc)

  • page (Integer) (defaults to: 1)

    The apge number to return

  • format (String) (defaults to: "json")

    The data format to return (json or csv)

  • pretty (Boolean) (defaults to: false)

    If true, the returned JSON will be prettified. Avoid using for production code.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/scryfall/card.rb', line 24

def search(q, unique: "cards", order: "name", dir: "auto", include_extras: false, include_multilingual: false, include_variations: false, page: 1, format: "json", pretty: false)
  params = {
      q: q,
      unique: unique,
      order: order,
      dir: dir,
      include_extras: include_extras,
      include_multilingual: include_multilingual,
      include_variations: include_variations,
      page: page,
      format: format,
      pretty: pretty
  }

  req = Request.new(params = params,
                    headers = nil,
                    body = nil)

  Scryfall::Search.get("/cards/search", self, req)
end