class BlizzardApi::Hearthstone::Card
This class allows access to Hearthstone
card data
@see develop.battle.net/documentation/api-reference/hearthstone-game-data-api @see develop.battle.net/documentation/hearthstone/guides/card-search
You can get an instance of this class using the default region as follows:
api_instance = BlizzardApi::Hearthstone.card
Constants
- VALID_SEARCH_OPTIONS
Valid options for card search
Public Instance Methods
Returns the card with an ID or slug that matches the one you specify. For more information, see the Card
Search Guide.
@see develop.battle.net/documentation/hearthstone/guides/card-search @see develop.battle.net/documentation/hearthstone/guides/game-modes
@param id_or_slug [String] Card
ID or slug @param game_mode [String] A recognized game mode (for example, battlegrounds or constructed).
The default value is constructed. See the Game Modes Guide for more information.
@!macro request_options
@!macro response
BlizzardApi::Hearthstone::GenericDataEndpoint#get
# File lib/blizzard_api/hearthstone/game_data/card.rb, line 93 def get(id_or_slug, game_mode = 'constructed', **options) super id_or_slug, **{ gameMode: game_mode }.merge(options) end
Fetch all possible data for one of the items listed by the {#index} using its id
@param search_options [Hash] Search options accepted by the endpoint
@option search_options [String] :set The slug of the set the card belongs to. If you do not supply a value cards from all sets will be returned. @option search_options [String] :class The slug of the card's class. @option search_options [Integer] :manaCost The mana cost required to play the card. You can include multiple values in a comma-separated list of numeric values. @option search_options [Integer] :attack The attack power of the minion or weapon. You can include multiple values in a comma-separated list of numeric values. @option search_options [Integer] :health The health of a minion. You can include multiple values in a comma-separated list of numeric values. @option search_options [Float] :collectible Whether a card is collectible. A value of 1 indicates that collectible cards should be returned; 0 indicates uncollectible cards. To return all cards, use a value of '0,1'. @option search_options [String] :rarity The rarity of a card. This value must match the rarity slugs found in metadata. @option search_options [String] :type The type of card (for example, minion, spell, and so on). This value must match the type slugs found in metadata. @option search_options [String] :minionType The type of minion card (for example, beast, murloc, dragon, and so on). This value must match the minion type slugs found in metadata. @option search_options [String] :keyword A required keyword on the card (for example, battlecry, deathrattle, and so on). This value must match the keyword slugs found in metadata. @option search_options [String] :textFilter A text string used to filter cards. You must include a locale along with the textFilter parameter. @option search_options [String] :gameMode A recognized game mode (for example, battlegrounds or constructed). The default value is constructed. See the Game Modes Guide for more information. @option search_options [Integer] :page A page number. @option search_options [Integer] :pageSize The number of results to choose per page. A value will be selected automatically if you do not supply a pageSize or if the pageSize is higher than the maximum allowed. @option search_options [String] :sort The field used to sort the results. Valid values include manaCost, attack, health, and name. Results are sorted by manaCost by default. Cards will also be sorted by class automatically in most cases. @option search_options [String] :order The order in which to sort the results. Valid values are asc or desc. The default value is asc.
@!macro request_options @option options [Boolean] :validate_fields If set to true, this method will throw an exception if nay search
option is invalid
@!macro response
# File lib/blizzard_api/hearthstone/game_data/card.rb, line 75 def search(search_options = {}, **options) validate_search_options search_options if options.include? :validate_fields api_request "#{base_url(:community)}/cards", **default_options.merge(options).merge(search_options) end
Protected Instance Methods
# File lib/blizzard_api/hearthstone/game_data/card.rb, line 105 def endpoint_setup @endpoint = 'cards' @ttl = CACHE_TRIMESTER end
# File lib/blizzard_api/hearthstone/game_data/card.rb, line 99 def validate_search_options(search_options) search_options.each do |field| raise ArgumentError, "Unrecognized search option #{field}" unless VALID_SEARCH_OPTIONS.include? field end end