class Warcraft::Client
Attributes
region[RW]
token[RW]
Public Class Methods
new(token, region)
click to toggle source
@param [String] token Access Token @param [Symbol] region Region to query for, e.g. :eu
# File lib/warcraft/client.rb, line 13 def initialize(token, region) self.token = token self.region = region end
Public Instance Methods
account(token: self.token, region: self.region)
click to toggle source
# File lib/warcraft/client.rb, line 40 def account(token: self.token, region: self.region) AccountRequest.new(self, region, token) end
character(realm:, character_name:, region: self.region)
click to toggle source
# File lib/warcraft/client.rb, line 44 def character(realm:, character_name:, region: self.region) CharacterRequest.new(self, region, realm.slugify, character_name.slugify) end
get(url, region = nil, token = self.token)
click to toggle source
@param [String] url @param [Symbol] region @return [Hash]
# File lib/warcraft/client.rb, line 21 def get(url, region = nil, token = self.token) token = self.token if token.nil? response = HTTParty.get(region.nil? ? url : "https://#{region}.api.blizzard.com#{url}", headers: { 'Authorization': "Bearer #{token}" }, format: :plain) JSON.parse(response.body, symbolize_names: true) end
userinfo(token = self.token, region = nil)
click to toggle source
@param [Symbol] region Region to fetch data for (optional)
# File lib/warcraft/client.rb, line 31 def userinfo(token = self.token, region = nil) domain = region == :cn ? "www.battlenet.com.cn" : "#{region}.api.blizzard.com" response = HTTParty.get("https://#{domain}/oauth/userinfo?access_token", headers: { 'Authorization': "Bearer #{token}" }, format: :plain) JSON.parse(response.body, symbolize_names: true) end