Class: Battlenet::Client
- Inherits:
-
Object
show all
- Includes:
- HTTParty
- Defined in:
- lib/battlenet/api/client.rb
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
13
14
15
16
17
18
19
20
|
# File 'lib/battlenet/api/client.rb', line 13
def initialize(options={})
options = Battlenet.options.merge(options)
Configuration::OPTIONS_KEYS.each do |key|
send("#{key}=", options[key])
end
self.class.base_uri "https://#{domain}#{endpoint}"
end
|
Instance Method Details
#domain ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/battlenet/api/client.rb', line 22
def domain
domain = case @region
when :us
'us.api.battle.net'
when :eu
'eu.api.battle.net'
when :kr
'kr.api.battle.net'
when :tw
'tw.api.battle.net'
when :cn
'api.battlenet.com.cn'
else
raise "Invalid region: #{region.to_s}"
end
end
|
#endpoint ⇒ Object
39
40
41
42
|
# File 'lib/battlenet/api/client.rb', line 39
def endpoint
raise "Invalid Game Endpoint" if @endpoint == nil
@endpoint
end
|
#get(path, params = {}) ⇒ Object
44
45
46
|
# File 'lib/battlenet/api/client.rb', line 44
def get(path, params = {})
make_request :get, path, params
end
|
#make_request(verb, path, params = {}) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/battlenet/api/client.rb', line 48
def make_request(verb, path, params = {})
options = {}
= {}
options[:headers] = unless .empty?
options[:query] = params unless params.empty?
if @api_key
options[:query] ||= {}
options[:query].merge!({ :apikey => @api_key })
end
response = self.class.send(verb, Addressable::URI.encode(path), options)
end
|