Class: Bnet::WOW

Inherits:
API
  • Object
show all
Defined in:
lib/bnet/wow.rb

Defined Under Namespace

Modules: Data Classes: Character

Instance Attribute Summary

Attributes inherited from API

#region

Instance Method Summary collapse

Methods inherited from API

#initialize, valid_call?

Constructor Details

This class inherits a constructor from Bnet::API

Instance Method Details

#scoped(scope, args = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bnet/wow.rb', line 7

def scoped(scope, args ={})
  api_key = args[:api_key] || Bnet.configuration.api_key
  locale = args[:locale] || 'en_US'
  realm = args[:realm]
  name = args[:name]

  call_url = url + "character/#{realm}/#{name}?fields=#{scope}&locale=#{locale}&apikey=#{api_key}"

  begin
    data = open(call_url)
    raw_response = JSON.parse(data.read)

    if data.status == ['200', 'OK'] && raw_response["code"] != 'NOTFOUND'
      raw_response
    else
      raw_response = {}
    end

  rescue OpenURI::HTTPError => e
    raw_response = {}
  end

  return raw_response[scope]
end

#urlObject



3
4
5
# File 'lib/bnet/wow.rb', line 3

def url
  super + "wow/"
end