Class: Bnet::Starcraft2::Profile
- Inherits:
-
BnetResource
- Object
- BnetResource
- Bnet::Starcraft2::Profile
- Defined in:
- lib/bnet/starcraft2/profile.rb
Overview
TODO: Associations for career, current_season
Constant Summary collapse
- PARAMS_MAPPING =
{ "id" => :profile_id, "realm" => :realm, "displayName" => :name, "clanName" => :clan_name, "clanTag" => :clan_tag }
Instance Attribute Summary collapse
-
#achievement_points ⇒ Object
Returns the value of attribute achievement_points.
-
#acievement_points ⇒ Object
Returns the value of attribute acievement_points.
-
#career ⇒ Object
Returns the value of attribute career.
-
#clan_name ⇒ Object
Returns the value of attribute clan_name.
-
#clan_tag ⇒ Object
Returns the value of attribute clan_tag.
-
#name ⇒ Object
Returns the value of attribute name.
-
#profile_id ⇒ Object
Returns the value of attribute profile_id.
-
#protoss_level ⇒ Object
Returns the value of attribute protoss_level.
-
#raw_attributes ⇒ Object
Returns the value of attribute raw_attributes.
-
#realm ⇒ Object
Returns the value of attribute realm.
-
#region ⇒ Object
Returns the value of attribute region.
-
#swarm_level ⇒ Object
Returns the value of attribute swarm_level.
-
#terran_level ⇒ Object
Returns the value of attribute terran_level.
-
#zerg_level ⇒ Object
Returns the value of attribute zerg_level.
Class Method Summary collapse
-
.find(args) ⇒ Object
Query Battlenet API for the SC2 profile recordand create an instance of an SC2 Profile.
- .from_api(response) ⇒ Object
Instance Method Summary collapse
- #current_ladder_season ⇒ Object
-
#initialize(args) ⇒ Profile
constructor
A new instance of Profile.
- #matches ⇒ Object
- #previous_ladder_season ⇒ Object
Constructor Details
#initialize(args) ⇒ Profile
Returns a new instance of Profile.
17 18 19 20 21 |
# File 'lib/bnet/starcraft2/profile.rb', line 17 def initialize args args.each do |k,v| instance_variable_set("@#{k}", v) unless v.nil? end end |
Instance Attribute Details
#achievement_points ⇒ Object
Returns the value of attribute achievement_points.
4 5 6 |
# File 'lib/bnet/starcraft2/profile.rb', line 4 def achievement_points @achievement_points end |
#acievement_points ⇒ Object
Returns the value of attribute acievement_points.
4 5 6 |
# File 'lib/bnet/starcraft2/profile.rb', line 4 def acievement_points @acievement_points end |
#career ⇒ Object
Returns the value of attribute career.
4 5 6 |
# File 'lib/bnet/starcraft2/profile.rb', line 4 def career @career end |
#clan_name ⇒ Object
Returns the value of attribute clan_name.
4 5 6 |
# File 'lib/bnet/starcraft2/profile.rb', line 4 def clan_name @clan_name end |
#clan_tag ⇒ Object
Returns the value of attribute clan_tag.
4 5 6 |
# File 'lib/bnet/starcraft2/profile.rb', line 4 def clan_tag @clan_tag end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/bnet/starcraft2/profile.rb', line 4 def name @name end |
#profile_id ⇒ Object
Returns the value of attribute profile_id.
4 5 6 |
# File 'lib/bnet/starcraft2/profile.rb', line 4 def profile_id @profile_id end |
#protoss_level ⇒ Object
Returns the value of attribute protoss_level.
4 5 6 |
# File 'lib/bnet/starcraft2/profile.rb', line 4 def protoss_level @protoss_level end |
#raw_attributes ⇒ Object
Returns the value of attribute raw_attributes.
4 5 6 |
# File 'lib/bnet/starcraft2/profile.rb', line 4 def raw_attributes @raw_attributes end |
#realm ⇒ Object
Returns the value of attribute realm.
4 5 6 |
# File 'lib/bnet/starcraft2/profile.rb', line 4 def realm @realm end |
#region ⇒ Object
Returns the value of attribute region.
4 5 6 |
# File 'lib/bnet/starcraft2/profile.rb', line 4 def region @region end |
#swarm_level ⇒ Object
Returns the value of attribute swarm_level.
4 5 6 |
# File 'lib/bnet/starcraft2/profile.rb', line 4 def swarm_level @swarm_level end |
#terran_level ⇒ Object
Returns the value of attribute terran_level.
4 5 6 |
# File 'lib/bnet/starcraft2/profile.rb', line 4 def terran_level @terran_level end |
#zerg_level ⇒ Object
Returns the value of attribute zerg_level.
4 5 6 |
# File 'lib/bnet/starcraft2/profile.rb', line 4 def zerg_level @zerg_level end |
Class Method Details
.find(args) ⇒ Object
Query Battlenet API for the SC2 profile recordand create an instance of an SC2 Profile.
Hash Params:
Required
:realm - (required but defaults to '1')
:profile_id - ID (Honestly i do not know why Blizzard still needs this if
localized Battletag is unique enough)
:name - Just the name string in the Battle tag.
Optional
:locale - (defaults to 'en_US')
:api_key - the api key
Example: If US account ‘Playerone#1309’ the profile can be accessible via web from ‘us.battle.net/sc2/en/profile/2143215/1/PlayerOne/’
find(region: 'us', profile_id: 2143215, name: 'PlayerOne')
Returns a Profile object with the following attributes
:profile_id, :realm, :name, :clan_name, :clan_tag,
:achievement_points, :swarm_level, :terran_level, :zerg_level,
:protoss_level, :acievement_points
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/bnet/starcraft2/profile.rb', line 47 def self.find args region = args[:region] profile_id = args[:profile_id] name = args[:name] realm = args[:realm] || '1' locale = args[:locale] || 'en_US' api_key = args[:api_key] || Bnet.configuration.api_key base_api = Bnet::Starcraft2.new(region: region) call_url = base_api.url + "profile/#{profile_id}/#{realm}/#{name}/?locale=#{locale}&apikey=#{api_key}" begin data = open(call_url) raw_response = JSON.parse(data.read) if Bnet::API.valid_call?(data.status, raw_response) bnet_object = from_api(raw_response) bnet_object.raw_attributes = 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(response) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/bnet/starcraft2/profile.rb', line 94 def self.from_api(response) bnet_resource = super(response) if bnet_resource && response["achievements"] bnet_resource.achievement_points = response["achievements"]["points"]["totalPoints"] end if bnet_resource && response["swarmLevels"] bnet_resource.swarm_level = response["swarmLevels"]["level"] bnet_resource.terran_level = response["swarmLevels"]["terran"]["level"] bnet_resource.protoss_level = response["swarmLevels"]["protoss"]["level"] bnet_resource.zerg_level = response["swarmLevels"]["zerg"]["level"] end assign_career_from_raw_career(bnet_resource, response["career"]) if response["career"] bnet_resource end |
Instance Method Details
#current_ladder_season ⇒ Object
86 87 88 |
# File 'lib/bnet/starcraft2/profile.rb', line 86 def current_ladder_season @ladders ||= Bnet::Starcraft2::Ladder.find_current(self) end |
#matches ⇒ Object
82 83 84 |
# File 'lib/bnet/starcraft2/profile.rb', line 82 def matches @matches ||= Bnet::Starcraft2::Match.all(self) end |
#previous_ladder_season ⇒ Object
90 91 92 |
# File 'lib/bnet/starcraft2/profile.rb', line 90 def previous_ladder_season @ladders ||= Bnet::Starcraft2::Ladder.find_previous(self) end |