Class: Bnet::WOW::Character

Inherits:
BnetResource show all
Defined in:
lib/bnet/wow/character.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from BnetResource

from_api, #initialize

Constructor Details

This class inherits a constructor from Bnet::BnetResource

Instance Attribute Details

#achievement_pointsObject

Returns the value of attribute achievement_points.



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

def achievement_points
  @achievement_points
end

#battlegroupObject

Returns the value of attribute battlegroup.



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

def battlegroup
  @battlegroup
end

#calc_classObject

Returns the value of attribute calc_class.



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

def calc_class
  @calc_class
end

#classObject

Returns the value of attribute class.



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

def class
  @class
end

#genderObject

Returns the value of attribute gender.



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

def gender
  @gender
end

#levelObject

Returns the value of attribute level.



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

def level
  @level
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#raceObject

Returns the value of attribute race.



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

def race
  @race
end

#realmObject

Returns the value of attribute realm.



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

def realm
  @realm
end

#total_honorable_killsObject

Returns the value of attribute total_honorable_kills.



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

def total_honorable_kills
  @total_honorable_kills
end

Class Method Details

.find(args) ⇒ Object

Query Battlenet API for the character profile

Hash Params:

Required
  :region          - (e.g. 'us', 'ea')
  :name            - String name of the toon
  :realm           - String name of the server the character is on (String)
Optional
  :locale          - String locale (defaults to 'en_US')
  :api_key         - String api key

Example : IF a character named ‘AlexeiStukov’ is on ‘DragonMaw’ ‘US’ server

Bnet::WOW::Character.find(region: 'us', name: 'AlexeiStukov', realm: 'Dragonmaw')

Returns a Character with the following attributes

:name, :realm, :battlegroup, :class, :race, :gender, :level,
:achievement_points, :total_honorable_kills, :calc_class


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bnet/wow/character.rb', line 25

def self.find args
  region     = args.delete(:region)
  realm      = args.delete(:realm)
  name       = args.delete(:name)
  locale     = args.delete(:locale) || 'en_US'
  api_key    = args.delete(:api_key) || Bnet.configuration.api_key

  base_api = Bnet::WOW.new(region: region)
  call_url = base_api.url + "character/#{realm}/#{name}?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'
      bnet_object = from_api(raw_response)
    else
      bnet_object = nil
    end

  rescue OpenURI::HTTPError => e
    bnet_object = nil
  end

  return bnet_object
end