Class: Bnet::WOW::Data::Base
- Inherits:
-
BnetResource
- Object
- BnetResource
- Bnet::WOW::Data::Base
- Defined in:
- lib/bnet/wow/data/base.rb
Direct Known Subclasses
Constant Summary
Constants inherited from BnetResource
Class Method Summary collapse
-
.find_all(args) ⇒ Object
Query Battlenet API for the the data based on the subclass’s scope.
Methods inherited from BnetResource
Constructor Details
This class inherits a constructor from Bnet::BnetResource
Class Method Details
.find_all(args) ⇒ Object
Query Battlenet API for the the data based on the subclass’s scope
Hash Params:
:region - (e.g. 'us', 'ea')
:name - String name of the toon
:realm - String name of the server the character is on (String)
:locale - String locale (defaults to 'en_US')
:api_key - String api key
Example : If a character named ‘AlexeiStukov’ is on ‘DragonMaw’ ‘US’ server
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bnet/wow/data/base.rb', line 12 def self.find_all(args) region = args.delete(:region) api_key = args.delete(:api_key) || Bnet::configuration.api_key locale = args.delete(:locale) || 'en_US' base_api = Bnet::WOW.new(region: region) call_url = base_api.url + 'data/' + scopes[:url] + "?locale=#{locale}&apikey=#{api_key}" begin data = open(call_url) raw_response = JSON.parse(data.read) if Bnet::API.valid_call?(data.status, raw_response) collection = collection_from_api(raw_response) else collection = [] end rescue OpenURI::HTTPError => e collection = [] end return collection end |