class Battlenet::Client
Public Class Methods
new(options={})
click to toggle source
# File lib/battlenet/api/client.rb, line 10 def initialize(options={}) options = Battlenet.options.merge(options) Configuration::OPTIONS_KEYS.each do |key| send("#{key}=", options[key]) end end
Public Instance Methods
base_uri()
click to toggle source
# File lib/battlenet/api/client.rb, line 18 def base_uri "https://#{domain}#{endpoint}" end
domain()
click to toggle source
# 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()
click to toggle source
# File lib/battlenet/api/client.rb, line 39 def endpoint raise "Invalid Game Endpoint" if @endpoint == nil @endpoint end
get(path, params = {})
click to toggle source
# File lib/battlenet/api/client.rb, line 44 def get(path, params = {}) make_request :get, path, params end
make_request(verb, path, params = {})
click to toggle source
# File lib/battlenet/api/client.rb, line 48 def make_request(verb, path, params = {}) options = {} headers = {} options[:headers] = headers unless headers.empty? options[:query] = params unless params.empty? if @api_key options[:query] ||= {} options[:query].merge!({ :apikey => @api_key }) end encoded_path = Addressable::URI.encode(path) response = HTTParty.send(verb, "#{base_uri}#{encoded_path}" , options) end