Class: Bnet::WOW::Character

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

Constant Summary

Constants inherited from BnetResource

BnetResource::PARAMS_MAPPING

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BnetResource

#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

#raw_attributesObject

Returns the value of attribute raw_attributes.



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

def raw_attributes
  @raw_attributes
end

#realmObject

Returns the value of attribute realm.



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

def realm
  @realm
end

#regionObject

Returns the value of attribute region.



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

def region
  @region
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


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
51
52
# File 'lib/bnet/wow/character.rb', line 26

def self.find args
  region     = args[:region]
  realm      = args[:realm]
  name       = args[:name]
  locale     = args[:locale] || 'en_US'
  api_key    = args[:api_key] || Bnet.configuration.api_key

  client = Bnet::WOW.new(region: region)
  call_url = client.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)
      bnet_object.region = region
    else
      bnet_object = nil
    end

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

  return bnet_object
end

.from_api(raw_response) ⇒ Object



54
55
56
57
58
# File 'lib/bnet/wow/character.rb', line 54

def self.from_api(raw_response)
  character = super(raw_response)
  character.raw_attributes = raw_response
  character
end

Instance Method Details

#achievementsObject



69
70
71
72
73
# File 'lib/bnet/wow/character.rb', line 69

def achievements
  return @achievements if @achievements
  client = Bnet::WOW.new(region: region)
  @achievements = client.scoped('achievements', realm: realm, name: name)
end

#appearanceObject



75
76
77
78
79
# File 'lib/bnet/wow/character.rb', line 75

def appearance
  return @appearance if @appearance
  client = Bnet::WOW.new(region: region)
  @appearance = client.scoped('appearance', realm: realm, name: name)
end

#auditObject



159
160
161
162
163
# File 'lib/bnet/wow/character.rb', line 159

def audit
  return @audit if @audit
  client = Bnet::WOW.new(region: region)
  @audit = client.scoped('audit', realm: realm, name: name)
end

#feedObject



81
82
83
84
85
# File 'lib/bnet/wow/character.rb', line 81

def feed
  return @feed if @feed
  client = Bnet::WOW.new(region: region)
  @feed = client.scoped('feed', realm: realm, name: name)
end

#guildObject



87
88
89
90
91
# File 'lib/bnet/wow/character.rb', line 87

def guild
  return @guild if @guild
  client = Bnet::WOW.new(region: region)
  @guild = client.scoped('guild', realm: realm, name: name)
end

#hunter_petsObject



93
94
95
96
97
# File 'lib/bnet/wow/character.rb', line 93

def hunter_pets
  return @hunter_pets if @hunter_pets
  client = Bnet::WOW.new(region: region)
  @hunter_pets = client.scoped('hunterPets', realm: realm, name: name)
end

#itemsObject



99
100
101
102
103
# File 'lib/bnet/wow/character.rb', line 99

def items
  return @items if @items
  client = Bnet::WOW.new(region: region)
  @items = client.scoped('items', realm: realm, name: name)
end

#mountsObject



105
106
107
108
109
# File 'lib/bnet/wow/character.rb', line 105

def mounts
  return @mounts if @mounts
  client = Bnet::WOW.new(region: region)
  @mounts = client.scoped('mounts', realm: realm, name: name)
end

#pet_slotsObject



117
118
119
120
121
# File 'lib/bnet/wow/character.rb', line 117

def pet_slots
  return @pet_slots if @pet_slots
  client = Bnet::WOW.new(region: region)
  @pet_slots = client.scoped('petSlots', realm: realm, name: name)
end

#petsObject



111
112
113
114
115
# File 'lib/bnet/wow/character.rb', line 111

def pets
  return @pets if @pets
  client = Bnet::WOW.new(region: region)
  @pets = client.scoped('pets', realm: realm, name: name)
end

#progressionObject



123
124
125
126
127
# File 'lib/bnet/wow/character.rb', line 123

def progression
  return @progression if @progression
  client = Bnet::WOW.new(region: region)
  @progression = client.scoped('progression', realm: realm, name: name)
end

#pvpObject



129
130
131
132
133
# File 'lib/bnet/wow/character.rb', line 129

def pvp
  return @pvp if @pvp
  client = Bnet::WOW.new(region: region)
  @pvp = client.scoped('pvp', realm: realm, name: name)
end

#questsObject



135
136
137
138
139
# File 'lib/bnet/wow/character.rb', line 135

def quests
  return @quests if @quests
  client = Bnet::WOW.new(region: region)
  @quests = client.scoped('quests', realm: realm, name: name)
end

#reputationObject



141
142
143
144
145
# File 'lib/bnet/wow/character.rb', line 141

def reputation
  return @reputation if @reputation
  client = Bnet::WOW.new(region: region)
  @reputation = client.scoped('reputation', realm: realm, name: name)
end

#statsObject



147
148
149
150
151
# File 'lib/bnet/wow/character.rb', line 147

def stats
  return @stats if @stats
  client = Bnet::WOW.new(region: region)
  @stats = client.scoped('stats', realm: realm, name: name)
end

#talentsObject



153
154
155
156
157
# File 'lib/bnet/wow/character.rb', line 153

def talents
  return @talents if @talents
  client = Bnet::WOW.new(region: region)
  @talents = client.scoped('talents', realm: realm, name: name)
end