Class: Bnet::WOW::Character
- Inherits:
-
BnetResource
- Object
- BnetResource
- Bnet::WOW::Character
- Defined in:
- lib/bnet/wow/character.rb
Instance Attribute Summary collapse
-
#achievement_points ⇒ Object
Returns the value of attribute achievement_points.
-
#battlegroup ⇒ Object
Returns the value of attribute battlegroup.
-
#calc_class ⇒ Object
Returns the value of attribute calc_class.
-
#class ⇒ Object
Returns the value of attribute class.
-
#gender ⇒ Object
Returns the value of attribute gender.
-
#level ⇒ Object
Returns the value of attribute level.
-
#name ⇒ Object
Returns the value of attribute name.
-
#race ⇒ Object
Returns the value of attribute race.
-
#realm ⇒ Object
Returns the value of attribute realm.
-
#total_honorable_kills ⇒ Object
Returns the value of attribute total_honorable_kills.
Class Method Summary collapse
-
.find(args) ⇒ Object
Query Battlenet API for the character profile.
Methods inherited from BnetResource
Constructor Details
This class inherits a constructor from Bnet::BnetResource
Instance Attribute Details
#achievement_points ⇒ Object
Returns the value of attribute achievement_points.
3 4 5 |
# File 'lib/bnet/wow/character.rb', line 3 def achievement_points @achievement_points end |
#battlegroup ⇒ Object
Returns the value of attribute battlegroup.
3 4 5 |
# File 'lib/bnet/wow/character.rb', line 3 def battlegroup @battlegroup end |
#calc_class ⇒ Object
Returns the value of attribute calc_class.
3 4 5 |
# File 'lib/bnet/wow/character.rb', line 3 def calc_class @calc_class end |
#class ⇒ Object
Returns the value of attribute class.
3 4 5 |
# File 'lib/bnet/wow/character.rb', line 3 def class @class end |
#gender ⇒ Object
Returns the value of attribute gender.
3 4 5 |
# File 'lib/bnet/wow/character.rb', line 3 def gender @gender end |
#level ⇒ Object
Returns the value of attribute level.
3 4 5 |
# File 'lib/bnet/wow/character.rb', line 3 def level @level end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/bnet/wow/character.rb', line 3 def name @name end |
#race ⇒ Object
Returns the value of attribute race.
3 4 5 |
# File 'lib/bnet/wow/character.rb', line 3 def race @race end |
#realm ⇒ Object
Returns the value of attribute realm.
3 4 5 |
# File 'lib/bnet/wow/character.rb', line 3 def realm @realm end |
#total_honorable_kills ⇒ Object
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 |