Class: Hearthstone::Api
- Inherits:
-
Object
- Object
- Hearthstone::Api
- Defined in:
- lib/hearthstone/api.rb
Constant Summary collapse
- OAUTH_URL =
"https://us.battle.net/oauth/token"
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#is_valid ⇒ Object
readonly
Returns the value of attribute is_valid.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
Instance Method Summary collapse
-
#deck(deckcode, options = {}) ⇒ Object
Finds a deck by its deck code.
- #endpoint ⇒ Object
-
#fetch(slug, options = {}) ⇒ Object
Returns the card with an ID or slug that matches the one you specify.
-
#fetch_metadata(type, options = {}) ⇒ Object
Returns information about just one type of metadata.
-
#initialize(options = {}) ⇒ Api
constructor
A new instance of Api.
-
#metadata(options = {}) ⇒ Object
Returns information about the categorization of cards.
-
#search(options = {}) ⇒ Object
Returns an up-to-date list of all cards matching the search criteria.
- #valid? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Api
Returns a new instance of Api.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hearthstone/api.rb', line 13 def initialize(={}) @client_id = [:client_id] @client_secret = [:client_secret] @region = [:region] || "us" @locale = [:locale] || "en_US" @access_token = get_token @is_valid = true rescue Hearthstone::InvalidClientError => e @is_valid = false end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
9 10 11 |
# File 'lib/hearthstone/api.rb', line 9 def access_token @access_token end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
9 10 11 |
# File 'lib/hearthstone/api.rb', line 9 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
9 10 11 |
# File 'lib/hearthstone/api.rb', line 9 def client_secret @client_secret end |
#is_valid ⇒ Object (readonly)
Returns the value of attribute is_valid.
9 10 11 |
# File 'lib/hearthstone/api.rb', line 9 def is_valid @is_valid end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
9 10 11 |
# File 'lib/hearthstone/api.rb', line 9 def locale @locale end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
9 10 11 |
# File 'lib/hearthstone/api.rb', line 9 def region @region end |
Instance Method Details
#deck(deckcode, options = {}) ⇒ Object
Finds a deck by its deck code. Allow Options
- none
71 72 73 |
# File 'lib/hearthstone/api.rb', line 71 def deck(deckcode, ={}) request(:get, "/hearthstone/deck/#{deckcode}", ()) end |
#endpoint ⇒ Object
24 25 26 27 28 29 |
# File 'lib/hearthstone/api.rb', line 24 def endpoint @endpoint ||= Faraday::Connection.new(url: "https://#{region}.api.blizzard.com") do |builder| builder.use Faraday::Request::UrlEncoded builder.use Faraday::Adapter::NetHttp end end |
#fetch(slug, options = {}) ⇒ Object
Returns the card with an ID or slug that matches the one you specify. Allow Options
- none
64 65 66 |
# File 'lib/hearthstone/api.rb', line 64 def fetch(slug, ={}) request(:get, "/hearthstone/cards/#{slug}", ()) end |
#fetch_metadata(type, options = {}) ⇒ Object
Returns information about just one type of metadata.
82 83 84 |
# File 'lib/hearthstone/api.rb', line 82 def (type, ={}) request(:get, "/hearthstone/metadata/#{type}", ()) end |
#metadata(options = {}) ⇒ Object
Returns information about the categorization of cards. Metadata includes the card set, set group (for example, Standard or Year of the Dragon), rarity, class, card type, minion type, and keywords.
77 78 79 |
# File 'lib/hearthstone/api.rb', line 77 def (={}) request(:get, "/hearthstone/metadata", ()) end |
#search(options = {}) ⇒ Object
Returns an up-to-date list of all cards matching the search criteria. Allow Options
- set[string] : The slug of the set the card belongs to. If you do not supply a value, cards from all sets will be returned.
- class[string] : The slug of the card's class.
- manaCost[numbers] : The mana cost required to play the card. You can include multiple values in a comma-separated list of numeric values.
- attack[numbers] : The attack power of the minion or weapon. You can include multiple values in a comma-separated list of numeric values.
- health[numbers] : The health of a minion. You can include multiple values in a comma-separated list of numeric values.
- collectible[numbers] : 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'.
- rarity[string] : The rarity of a card. This value must match the rarity slugs found in metadata.
- type[string] : The type of card (for example, minion, spell, and so on). This value must match the type slugs found in metadata.
- minionType[string] : The type of minion card (for example, beast, murloc, dragon, and so on).
This value must match the minion type slugs found in metadata.
- keyword[string] : A required keyword on the card (for example, battlecry, deathrattle, and so on).
This value must match the keyword slugs found in metadata.
- textFilter[string] : A text string used to filter cards. You must include a locale along with the textFilter parameter.
- page[number] : A page number.
- pageSize[number] : 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.
- sort[string] : 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.
- order[string] : The order in which to sort the results. Valid values are asc or desc. The default value is asc.
57 58 59 |
# File 'lib/hearthstone/api.rb', line 57 def search(={}) request(:get, "/hearthstone/cards", ()) end |
#valid? ⇒ Boolean
31 32 33 |
# File 'lib/hearthstone/api.rb', line 31 def valid? is_valid end |