starcraft2 0.0.10 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/fixtures/cassettes/matches_999000.yml +1145 -0
- data/fixtures/cassettes/profile_999000.yml +961 -0
- data/lib/starcraft2/client.rb +34 -2
- data/lib/starcraft2/errors/missing_arguments_error.rb +4 -0
- data/lib/starcraft2/loader.rb +14 -1
- data/lib/starcraft2/member.rb +1 -1
- data/lib/starcraft2/profile.rb +27 -0
- data/lib/starcraft2/profile/achievement_item.rb +17 -0
- data/lib/starcraft2/profile/achievements.rb +11 -0
- data/lib/starcraft2/profile/campaign.rb +11 -0
- data/lib/starcraft2/profile/career.rb +12 -0
- data/lib/starcraft2/profile/match.rb +18 -0
- data/lib/starcraft2/profile/points.rb +11 -0
- data/lib/starcraft2/profile/rewards.rb +11 -0
- data/lib/starcraft2/profile/season.rb +11 -0
- data/lib/starcraft2/profile/stats.rb +17 -0
- data/lib/starcraft2/profile/swarm_levels.rb +11 -0
- data/lib/starcraft2/profile/swarm_race.rb +11 -0
- data/lib/starcraft2/utils.rb +7 -4
- data/spec/starcraft2/client_spec.rb +26 -3
- data/spec/starcraft2/member_spec.rb +7 -7
- data/spec/starcraft2/profile/achievements_spec.rb +35 -0
- data/spec/starcraft2/profile/campaign_spec.rb +21 -0
- data/spec/starcraft2/profile/career_spec.rb +54 -0
- data/spec/starcraft2/profile/match_spec.rb +34 -0
- data/spec/starcraft2/profile/rewards_spec.rb +19 -0
- data/spec/starcraft2/profile/season_spec.rb +31 -0
- data/spec/starcraft2/profile/swarm_levels_spec.rb +40 -0
- data/spec/starcraft2/profile_spec.rb +215 -0
- data/starcraft2.gemspec +1 -1
- metadata +25 -2
data/lib/starcraft2/client.rb
CHANGED
@@ -7,13 +7,25 @@ module Starcraft2
|
|
7
7
|
attr_accessor :locale, :host
|
8
8
|
|
9
9
|
def initialize(options = {})
|
10
|
-
options.each do |k,v|
|
10
|
+
options.each do |k, v|
|
11
11
|
self.send(:"#{k}=", v)
|
12
12
|
end
|
13
13
|
|
14
14
|
self.host = 'us.battle.net' if self.host.nil?
|
15
15
|
end
|
16
16
|
|
17
|
+
def profile(options = {})
|
18
|
+
if (args = [:character_name, :id, :realm] - options.keys).empty?
|
19
|
+
Profile.build(self, profile_json(options))
|
20
|
+
else
|
21
|
+
raise MissingArgumentsError, "Missing Keys: #{args.map {|i| ":#{i}"}.join(', ')}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def matches(options = {})
|
26
|
+
Profile::Match.build(match_json(options))
|
27
|
+
end
|
28
|
+
|
17
29
|
def achievements
|
18
30
|
Achievement.build(achievements_json)
|
19
31
|
end
|
@@ -36,6 +48,26 @@ module Starcraft2
|
|
36
48
|
|
37
49
|
private
|
38
50
|
|
51
|
+
def profile_json(options)
|
52
|
+
HTTParty.get(profile_url(options)).body
|
53
|
+
end
|
54
|
+
|
55
|
+
def profile_url(options)
|
56
|
+
'https://' + host + profile_path(options) + locale_param
|
57
|
+
end
|
58
|
+
|
59
|
+
def profile_path(options)
|
60
|
+
"/api/sc2/profile/#{options[:id]}/#{options[:realm]}/#{options[:character_name]}/" + locale_param
|
61
|
+
end
|
62
|
+
|
63
|
+
def match_json(options)
|
64
|
+
HTTParty.get(match_url(options)).body
|
65
|
+
end
|
66
|
+
|
67
|
+
def match_url(options)
|
68
|
+
'https://' + host + profile_path(options) + 'matches' + locale_param
|
69
|
+
end
|
70
|
+
|
39
71
|
def achievements_json
|
40
72
|
HTTParty.get(achievements_url).body
|
41
73
|
end
|
@@ -64,4 +96,4 @@ module Starcraft2
|
|
64
96
|
locale.nil? ? '' : "?locale=#{locale}"
|
65
97
|
end
|
66
98
|
end
|
67
|
-
end
|
99
|
+
end
|
data/lib/starcraft2/loader.rb
CHANGED
@@ -2,6 +2,7 @@ require 'ostruct'
|
|
2
2
|
require 'httparty'
|
3
3
|
require 'json'
|
4
4
|
|
5
|
+
require File.join('starcraft2', 'errors', 'missing_arguments_error')
|
5
6
|
require File.join('starcraft2', 'utils')
|
6
7
|
require File.join('starcraft2', 'icon')
|
7
8
|
require File.join('starcraft2', 'client')
|
@@ -9,4 +10,16 @@ require File.join('starcraft2', 'achievement')
|
|
9
10
|
require File.join('starcraft2', 'reward')
|
10
11
|
require File.join('starcraft2', 'ladder')
|
11
12
|
require File.join('starcraft2', 'member')
|
12
|
-
require File.join('starcraft2', 'character')
|
13
|
+
require File.join('starcraft2', 'character')
|
14
|
+
require File.join('starcraft2', 'profile', 'match')
|
15
|
+
require File.join('starcraft2', 'profile', 'swarm_race')
|
16
|
+
require File.join('starcraft2', 'profile', 'swarm_levels')
|
17
|
+
require File.join('starcraft2', 'profile', 'career')
|
18
|
+
require File.join('starcraft2', 'profile', 'campaign')
|
19
|
+
require File.join('starcraft2', 'profile', 'season')
|
20
|
+
require File.join('starcraft2', 'profile', 'stats')
|
21
|
+
require File.join('starcraft2', 'profile', 'rewards')
|
22
|
+
require File.join('starcraft2', 'profile', 'achievements')
|
23
|
+
require File.join('starcraft2', 'profile', 'points')
|
24
|
+
require File.join('starcraft2', 'profile', 'achievement_item')
|
25
|
+
require File.join('starcraft2', 'profile')
|
data/lib/starcraft2/member.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Starcraft2
|
2
2
|
class Member
|
3
3
|
attr_accessor :character, :join_timestamp, :points, :wins,
|
4
|
-
|
4
|
+
:losses, :highest_rank, :previous_rank, :favorite_race_p1, :favorite_race_p2, :favorite_race_p3, :favorite_race_p4
|
5
5
|
|
6
6
|
def initialize(options = {})
|
7
7
|
Utils.load(self, options, {:character => Character})
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Starcraft2
|
2
|
+
class Profile
|
3
|
+
attr_accessor :id, :realm, :display_name, :clan_name, :clan_tag, :profile_path, :portrait,
|
4
|
+
:career, :swarm_levels, :campaign, :season, :rewards, :achievements, :client
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
Utils.load(self, options, {
|
8
|
+
:portrait => Icon,
|
9
|
+
:campaign => Campaign,
|
10
|
+
:career => Career,
|
11
|
+
:swarm_levels => SwarmLevels,
|
12
|
+
:season => Season,
|
13
|
+
:rewards => Rewards,
|
14
|
+
:achievements => Achievements
|
15
|
+
})
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.build(client, profile_json)
|
19
|
+
profile = JSON.parse(profile_json)
|
20
|
+
new(profile.merge!(:client => client))
|
21
|
+
end
|
22
|
+
|
23
|
+
def matches
|
24
|
+
client.matches(:character_name => self.display_name, :id => self.id, :realm => self.realm)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Starcraft2
|
2
|
+
class Profile
|
3
|
+
class AchievementItem
|
4
|
+
attr_accessor :achievement_id, :completion_date
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
Utils.load(self, options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.build(achievement_item_data)
|
11
|
+
achievement_item_data.map do |a|
|
12
|
+
new(a)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Starcraft2
|
2
|
+
class Profile
|
3
|
+
class Career
|
4
|
+
attr_accessor :primary_race, :league, :terran_wins, :protoss_wins, :zerg_wins,
|
5
|
+
:highest1v1_rank, :highest_team_rank, :season_total_games, :career_total_games
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
Utils.load(self, options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Starcraft2
|
2
|
+
class Profile
|
3
|
+
class Match
|
4
|
+
attr_accessor :map, :type, :decision, :speed, :date
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
Utils.load(self, options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.build(match_json)
|
11
|
+
data = JSON.parse(match_json)
|
12
|
+
data['matches'].map do |m|
|
13
|
+
new(m)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Starcraft2
|
2
|
+
class Profile
|
3
|
+
class Stats
|
4
|
+
attr_accessor :type, :wins, :games
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
Utils.load(self, options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.build(stats_data)
|
11
|
+
stats_data.map do |s|
|
12
|
+
new(s)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/starcraft2/utils.rb
CHANGED
@@ -10,12 +10,15 @@ module Starcraft2
|
|
10
10
|
word
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.load(klass, options, class_map = {})
|
13
|
+
def self.load(klass, options, class_map = {}, build_map = {})
|
14
14
|
options.each do |k, v|
|
15
|
-
|
15
|
+
k = self.underscore(k.to_s)
|
16
|
+
k = k.to_sym
|
17
|
+
v = class_map[k].new(v) if class_map.keys.include?(k)
|
18
|
+
v = build_map[k].build(v) if build_map.keys.include?(k)
|
16
19
|
|
17
|
-
klass.send(:"#{
|
20
|
+
klass.send(:"#{k}=", v)
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|
21
|
-
end
|
24
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Starcraft2::Client do
|
4
|
-
let(:client) { Starcraft2::Client.new(@options)}
|
4
|
+
let(:client) { Starcraft2::Client.new(@options) }
|
5
5
|
|
6
6
|
before do
|
7
7
|
@options = {:host => 'us.battle.net'}
|
@@ -23,16 +23,39 @@ describe Starcraft2::Client do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should store the locale' do
|
26
|
-
@options = {
|
26
|
+
@options = {:locale => 'en_US'}
|
27
27
|
client.locale.should == 'en_US'
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should store the host' do
|
31
|
-
@options = {
|
31
|
+
@options = {:host => 'someserver.com'}
|
32
32
|
client.host.should == 'someserver.com'
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
describe '.profile' do
|
37
|
+
it 'should return an sc2 profile' do
|
38
|
+
VCR.use_cassette("profile_#{999000}") do
|
39
|
+
options = {:character_name => 'DayNine', :id => 999000, :realm => 1}
|
40
|
+
client.profile(options).class.should == Starcraft2::Profile
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should error with invalid arguments' do
|
45
|
+
expect {
|
46
|
+
client.profile({})
|
47
|
+
}.to raise_error(Starcraft2::MissingArgumentsError, 'Missing Keys: :character_name, :id, :realm')
|
48
|
+
|
49
|
+
expect {
|
50
|
+
client.profile({:character_name => 'DayNine'})
|
51
|
+
}.to raise_error(Starcraft2::MissingArgumentsError, 'Missing Keys: :id, :realm')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
VCR.use_cassette("profile_#{999000}") do
|
56
|
+
@profile_json = HTTParty.get('https://us.battle.net/api/sc2/profile/999000/1/DayNine/').body
|
57
|
+
end
|
58
|
+
|
36
59
|
describe '.achievements' do
|
37
60
|
it 'should return an array of achievements' do
|
38
61
|
VCR.use_cassette('achievements') do
|
@@ -4,12 +4,12 @@ describe Starcraft2::Member do
|
|
4
4
|
describe '.initialize' do
|
5
5
|
let(:member) { Starcraft2::Member.new(@options) }
|
6
6
|
let(:character) { {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
'id' => 333319,
|
8
|
+
'realm' => 1,
|
9
|
+
'displayName' => 'NajM',
|
10
|
+
'clanName' => '',
|
11
|
+
'clanTag' => '',
|
12
|
+
'profilePath' => '/profile/333319/1/NajM/'
|
13
13
|
} }
|
14
14
|
|
15
15
|
before do
|
@@ -20,7 +20,7 @@ describe Starcraft2::Member do
|
|
20
20
|
@options = {:character => character}
|
21
21
|
member.character.class.should == Starcraft2::Character
|
22
22
|
|
23
|
-
member.character.id
|
23
|
+
member.character.id.should == 333319
|
24
24
|
member.character.realm.should == 1
|
25
25
|
member.character.display_name.should == 'NajM'
|
26
26
|
member.character.clan_name.should == ''
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Starcraft2::Profile::Achievements do
|
4
|
+
let(:achievements) { Starcraft2::Profile::Achievements.new(@options) }
|
5
|
+
|
6
|
+
before do
|
7
|
+
@options = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should store points' do
|
11
|
+
@options = {:points => {
|
12
|
+
:total_points => 3420,
|
13
|
+
:categoryPoints => {
|
14
|
+
"4325382" => 0,
|
15
|
+
"4325380" => 80,
|
16
|
+
"4325408" => 0,
|
17
|
+
"4325379" => 1560,
|
18
|
+
"4325410" => 1280,
|
19
|
+
"4325377" => 500
|
20
|
+
}
|
21
|
+
}}
|
22
|
+
achievements.points.total_points.should == 3420
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should store achievement_items' do
|
26
|
+
@options = {:achievements => [{ :achievement_id => 91475035553845, :completion_date => 1365790265},
|
27
|
+
{ :achievement_id => 91475320768475, :completion_date => 1365392587},
|
28
|
+
{ :achievement_id => 91475320768585, :completion_date => 1364634012}]}
|
29
|
+
|
30
|
+
achievements.achievements.class.should == Array
|
31
|
+
achievements.achievements.first.class.should == Starcraft2::Profile::AchievementItem
|
32
|
+
achievements.achievements.first.achievement_id.should == 91475035553845
|
33
|
+
achievements.achievements.first.completion_date.should == 1365790265
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Starcraft2::Profile::Campaign do
|
4
|
+
let(:campaign) { Starcraft2::Profile::Campaign.new(@options) }
|
5
|
+
|
6
|
+
before do
|
7
|
+
@options = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.initialize' do
|
11
|
+
it 'should store wol' do
|
12
|
+
@options = {:wol => 'BRUTAL'}
|
13
|
+
campaign.wol.should == 'BRUTAL'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should store hots' do
|
17
|
+
@options = {:hots => 'BRUTAL'}
|
18
|
+
campaign.hots.should == 'BRUTAL'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|