Class: Warcraft::Client
- Inherits:
-
Object
- Object
- Warcraft::Client
- Defined in:
- lib/warcraft/client.rb
Instance Attribute Summary collapse
-
#region ⇒ Object
Returns the value of attribute region.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #account(token: self.token, region: self.region) ⇒ Object
- #character(realm:, character_name:, region: self.region) ⇒ Object
- #get(url, region = nil, token = self.token) ⇒ Hash
-
#initialize(token, region) ⇒ Client
constructor
A new instance of Client.
- #userinfo(token = self.token, region = nil) ⇒ Object
Constructor Details
#initialize(token, region) ⇒ Client
Returns a new instance of Client.
13 14 15 16 |
# File 'lib/warcraft/client.rb', line 13 def initialize(token, region) self.token = token self.region = region end |
Instance Attribute Details
#region ⇒ Object
Returns the value of attribute region.
9 10 11 |
# File 'lib/warcraft/client.rb', line 9 def region @region end |
#token ⇒ Object
Returns the value of attribute token.
9 10 11 |
# File 'lib/warcraft/client.rb', line 9 def token @token end |
Instance Method Details
#account(token: self.token, region: self.region) ⇒ Object
40 41 42 |
# 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) ⇒ Object
44 45 46 |
# 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) ⇒ Hash
21 22 23 24 25 26 27 28 |
# 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) ⇒ Object
31 32 33 34 35 36 37 38 |
# 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 |