HearthstoneCardApi

Gem Version

An easy to use ruby wrapper for the Hearthstone game api located at HearthstoneApi.com

Get cards back in your favorite format (JSON, hash, even ruby objects!)

This gem is currently in beta and may be changing frequently until I post otherwise. Use with caution in production applications.

How To Install

If using a Gemfile, add the following line :

gem 'hearthstone_card_api'

Then run bundler :

bundle install

If not using a Gemfile run :

gem install hearthstone_card_api

Configuration

Get your api key at https://market.mashape.com/omgvamp/hearthstone

Place this config block in your application, if you are using Rails that place may be in a file you create at config/initializers/hearthstone_card_api.rb

HearthstoneCardApi.configuration do |config|
   config.api_key = "YOUR_API_KEY_123123"
   config.data_format = "objects" #THIS LINE IS OPTIONAL!
end

Optionally you can also pick your preferred format for the data you receive, currently supported values are "objects", "json", and "hash".

If you do not indicate a data_format, "objects" will be the default value.

Basic Usage

foo = HearthstoneCardApi::Public.new

When you add the above to your code you can access Hearthstone card data very easily :

cards = foo.get_cards()

cards.count
  => 1070

All card methods will return an array of Ruby objects (Assuming your set data format is the default "objects").

When returning objects the only exception to receiving an array is in the get_card_by_id method which returns a single object.

By default only player collectible cards are returned, this is equivalent to passing in collectible: 1

Passing in collectible: 0 will return both collectible and non-collectible cards.

cards = foo.get_cards(collectible:0) 

cards.count
  => 2844

See below for many more ways to filter your returned cards.

Endpoints

Return a hash (regardless of set data format) of HearthstoneApi.com info.

info = foo.get_info

info.keys 
  => ["patch","classes","sets","standard","wild","types","factions","qualities","races","locales"]

Return all cards.

foo.get_cards

Search cards by partial name.

cards = foo.search_cards(name:"Boar")

cards[0].name 
  => "Stonetusk Boar"

cards[0].flavor 
  => "This card is boaring." 

Return a card by its card id.

card = foo.get_card_by_id(id:"AT_005")

card.name
  => "Polymorph: Boar"

card.img
  => "http://media.services.zam.com/v1/media/byName/hs/cards/enus/AT_005.png"

Return cards by name. (For partial names use the search method instead.)

This may return more than one card if there are multiple cards with that same name (especially if you are choosing to return both collectible and non-collectible cards), for example "Loatheb" is a collectible card, as well as a boss card.

foo.get_card_by_name(name:"Elven Archer")

Returns cards by Type/Race/Quality/Faction/Class.

foo.get_cards_by(trait:"qualities", value:"Common") 

Available trait strings => "types","races","qualities","factions","classes"

For a thorough look at the optional values for the above you can call the get_info method or check out HearthstoneApi.com

Additional Filters

Pass in a hash with the key "filters" to narrow your card results even further:

foo.get_cards(filters:{attack:2, cost:3})

foo.search_cards(name:"Archer", filters:{health:1})

foo.get_cards_by(trait:"qualities", value:"Common", filters:{attack:4})

Available keys for filters => attack: , cost: , durability: , health: , collectible: