sc2ranks¶ ↑
A gem used to access the api of sc2ranks.com
Documentation about the api can be found at sc2ranks.com/api
Starting Out¶ ↑
First you need an instance of the Sc2ranks class. Just pass a app key to the new method. According to the api page at sc2ranks.com an appkey should be the domain that you are requesting from.
sc2ranks = Sc2ranks.new('sc2.kelsin.net')
Loading a Character¶ ↑
Right now the only api call implemented is the “Character with base team info” call since it handles everything I need currently. Just use the character method of the Sc2ranks object with a battle.net profile url:
character = sc2ranks.character('http://us.battle.net/sc2/en/profile/280904/1/Kelsin/')
This will return an object with the following methods
-
name
-
Character name
-
bnet_id
-
Battle.net ID
-
bnet_url
-
Passed in Battle.net profile url
-
region
-
Battle.net region
-
id
-
Sc2ranks id
-
updated_at
-
When the sc2ranks data was last updated
-
achievement_points
-
Current achievement point total
-
character_code
-
Character Code (sc2ranks won’t have access to these anymore)
-
portrait
-
Portrait object with portrait data
-
teams
-
An array of Team objects with team data
-
matches
-
An array of Match objects with match data
Battle.net Profile URL¶ ↑
This is what I’ve decided to use on my site in order for a user to point us to their character. Sc2ranks isn’t able to get character code information for new users anymore so they have advised API users to not use character code. The other way to look up a user is by battle.net id but I feel it’s much easier for a user to just copy their url instead of having them locate the id.
Portrait Data¶ ↑
The portrait object contains the following fields
-
icon_id
-
Which icon graphic to use
-
column
-
Which column in the graphic to use
-
row
-
Which row in the graphic to use
Please see sc2ranks.com/api for more information on using this data.
Team Data¶ ↑
To get to a certain team quick you can use the team method on your Character object
team = character.team(bracket, is_random)
Bracket can be 1 through 4. The is_random parameter defaults to false so you don’t need to use it. Team data does not include team members yet.
If you call method with a 1 or is_random set to true then you get a single team or nil if no team exists.
If you call this with 2, 3 or 4 and is_random set to false, you get an array of teams (or [] if there are none.)
# Get 1v1 team team = character.team(1) # single team object or nil # Get 2v2 random team team = character.team(2, true) # single team object or nil # Get 4v4 teams teams = character.team(4) # array of teams or []
Once you get the team you can use the following methods to reach the data.
-
bracket
-
The number of the bracket (1, 2, 3 or 4)
-
is_random
-
Whether this is a random team (true or false), also aliased as
is_random?
-
fav_race
-
Race most played for this team (zerg, terran or protoss)
-
updated_at
-
Time that sc2ranks.com last updated this team’s data
-
league
-
League that this team is currently in (bronze, silver, gold, platinum or diamond)
-
division
-
Division that this team is in
-
division_rank
-
Current rank in that division
-
world_rank
-
Current world rank
-
region_rank
-
Current region rank
-
wins
-
Number of wins
-
losses
-
Number of losses
-
points
-
Current ladder point total
-
ratio
-
Ratio of wins to loses
Match Data¶ ↑
Match data is scraped straight from battle.net via the supplied bnet_url
. I have not yet build an accessor method, but each Match
has the following attributes:
-
map
-
The map name, e.g. “Magma Core”
-
type
-
Match type, e.g. “2v2”
-
outcome
-
Either
:win
or:loss
-
date
-
Date of match as a
Date
(does not include a time)
Copyright¶ ↑
Copyright © 2011 Christopher Giroir. See LICENSE.txt for further details.