starcraft2 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fixtures/cassettes/ladders_999000.yml +1053 -0
- data/lib/starcraft2/character.rb +7 -1
- data/lib/starcraft2/client.rb +33 -19
- data/lib/starcraft2/loader.rb +4 -0
- data/lib/starcraft2/profile.rb +5 -1
- data/lib/starcraft2/profile/achievement_item.rb +3 -3
- data/lib/starcraft2/profile/achievements.rb +2 -2
- data/lib/starcraft2/profile/campaign.rb +2 -2
- data/lib/starcraft2/profile/career.rb +2 -2
- data/lib/starcraft2/profile/detailed_season.rb +17 -0
- data/lib/starcraft2/profile/ladder.rb +17 -0
- data/lib/starcraft2/profile/ladders.rb +11 -0
- data/lib/starcraft2/profile/match.rb +1 -1
- data/lib/starcraft2/profile/non_rank.rb +18 -0
- data/lib/starcraft2/profile/points.rb +1 -1
- data/lib/starcraft2/profile/season.rb +1 -1
- data/lib/starcraft2/profile/stats.rb +2 -2
- data/spec/starcraft2/achievement_spec.rb +42 -45
- data/spec/starcraft2/character_spec.rb +37 -19
- data/spec/starcraft2/client_spec.rb +2 -4
- data/spec/starcraft2/icon_spec.rb +7 -22
- data/spec/starcraft2/member_spec.rb +24 -54
- data/spec/starcraft2/profile/achievement_item_spec.rb +48 -0
- data/spec/starcraft2/profile/achievements_spec.rb +36 -27
- data/spec/starcraft2/profile/campaign_spec.rb +8 -7
- data/spec/starcraft2/profile/career_spec.rb +30 -47
- data/spec/starcraft2/profile/detailed_season_spec.rb +98 -0
- data/spec/starcraft2/profile/ladder_spec.rb +63 -0
- data/spec/starcraft2/profile/ladders_spec.rb +197 -0
- data/spec/starcraft2/profile/match_spec.rb +41 -22
- data/spec/starcraft2/profile/non_rank_spec.rb +48 -0
- data/spec/starcraft2/profile/points_spec.rb +22 -0
- data/spec/starcraft2/profile/rewards_spec.rb +17 -11
- data/spec/starcraft2/profile/season_spec.rb +33 -23
- data/spec/starcraft2/profile/stats_spec.rb +49 -0
- data/spec/starcraft2/profile/swarm_levels_spec.rb +29 -16
- data/spec/starcraft2/profile/swarm_race_spec.rb +25 -0
- data/spec/starcraft2/profile_spec.rb +80 -73
- data/spec/starcraft2/reward_spec.rb +22 -31
- data/spec/starcraft2/utils_spec.rb +30 -0
- data/starcraft2.gemspec +1 -1
- metadata +15 -2
@@ -8,12 +8,10 @@ describe Starcraft2::Client do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
context 'url constants' do
|
11
|
-
it 'should store the
|
11
|
+
it 'should store the key endpoint paths' do
|
12
12
|
Starcraft2::Client::ACHIEVEMENTS_PATH.should == '/api/sc2/data/achievements'
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should store the rewards url' do
|
16
13
|
Starcraft2::Client::REWARDS_PATH.should == '/api/sc2/data/rewards'
|
14
|
+
Starcraft2::Client::LADDER_PATH.should == '/api/sc2/ladder/'
|
17
15
|
end
|
18
16
|
end
|
19
17
|
|
@@ -5,37 +5,22 @@ describe Starcraft2::Icon do
|
|
5
5
|
let(:icon) { Starcraft2::Icon.new(@options) }
|
6
6
|
|
7
7
|
before do
|
8
|
-
@options = {}
|
8
|
+
@options = {'x' => 5, 'y' => 6, 'w' => 7, 'h' => 8, 'offset' => 0, 'url' => 'https://example.com'}
|
9
9
|
end
|
10
10
|
|
11
|
-
it 'should store
|
12
|
-
@options = {:x => 5}
|
11
|
+
it 'should store attributes as underscored' do
|
13
12
|
icon.x.should == 5
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should store y' do
|
17
|
-
@options = {:y => 6}
|
18
13
|
icon.y.should == 6
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should store w' do
|
22
|
-
@options = {:w => 7}
|
23
14
|
icon.w.should == 7
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should store h' do
|
27
|
-
@options = {:h => 8}
|
28
15
|
icon.h.should == 8
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should store the offset' do
|
32
|
-
@options = {:offset => 0}
|
33
16
|
icon.offset.should == 0
|
17
|
+
icon.url.should == 'https://example.com'
|
34
18
|
end
|
35
19
|
|
36
|
-
it 'should
|
37
|
-
@options
|
38
|
-
|
20
|
+
it 'should use Stracraft2::Utils.load to populate the model' do
|
21
|
+
Starcraft2::Utils.should_receive(:load).with(anything, @options)
|
22
|
+
|
23
|
+
icon
|
39
24
|
end
|
40
25
|
end
|
41
26
|
end
|
@@ -3,79 +3,49 @@ require 'spec_helper'
|
|
3
3
|
describe Starcraft2::Member do
|
4
4
|
describe '.initialize' do
|
5
5
|
let(:member) { Starcraft2::Member.new(@options) }
|
6
|
-
let(:character) { {
|
7
|
-
'id' => 333319,
|
8
|
-
'realm' => 1,
|
9
|
-
'displayName' => 'NajM',
|
10
|
-
'clanName' => '',
|
11
|
-
'clanTag' => '',
|
12
|
-
'profilePath' => '/profile/333319/1/NajM/'
|
13
|
-
} }
|
14
6
|
|
15
7
|
before do
|
16
|
-
@options = {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
8
|
+
@options = {
|
9
|
+
'character' => {
|
10
|
+
'id' => 333319,
|
11
|
+
'realm' => 1,
|
12
|
+
'displayName' => 'NajM',
|
13
|
+
'clanName' => '',
|
14
|
+
'clanTag' => '',
|
15
|
+
'profilePath' => '/profile/333319/1/NajM/'
|
16
|
+
},
|
17
|
+
'joinTimestamp' => 123456,
|
18
|
+
'points' => 1234,
|
19
|
+
'wins' => 123,
|
20
|
+
'losses' => 12,
|
21
|
+
'highestRank' => 1,
|
22
|
+
'previousRank' => 5,
|
23
|
+
'favoriteRaceP1' => 'Protoss',
|
24
|
+
'favoriteRaceP2' => 'Protoss',
|
25
|
+
'favoriteRaceP3' => 'Protoss',
|
26
|
+
'favoriteRaceP4' => 'Protoss'
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should store attributes as underscored' do
|
21
31
|
member.character.class.should == Starcraft2::Character
|
22
|
-
|
23
32
|
member.character.id.should == 333319
|
24
33
|
member.character.realm.should == 1
|
25
34
|
member.character.display_name.should == 'NajM'
|
26
35
|
member.character.clan_name.should == ''
|
27
36
|
member.character.clan_tag.should == ''
|
28
37
|
member.character.profile_path.should == '/profile/333319/1/NajM/'
|
29
|
-
end
|
30
38
|
|
31
|
-
it 'should store the join timestamp' do
|
32
|
-
@options = {:join_timestamp => 123456}
|
33
39
|
member.join_timestamp.should == 123456
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should store the points' do
|
37
|
-
@options = {:points => 1234}
|
38
40
|
member.points.should == 1234
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should store the wins' do
|
42
|
-
@options = {:wins => 123}
|
43
41
|
member.wins.should == 123
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should store the losses' do
|
47
|
-
@options = {:losses => 12}
|
48
42
|
member.losses.should == 12
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should store the highest rank' do
|
52
|
-
@options = {:highest_rank => 1}
|
53
43
|
member.highest_rank.should == 1
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should store the previous rank' do
|
57
|
-
@options = {:previous_rank => 5}
|
58
44
|
member.previous_rank.should == 5
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'should store the favorite race for player 1' do
|
62
|
-
@options = {:favorite_race_p1 => 'Protoss'}
|
63
45
|
member.favorite_race_p1.should == 'Protoss'
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'should store the favorite race for player 2' do
|
67
|
-
@options = {:favorite_race_p2 => 'Protoss'}
|
68
46
|
member.favorite_race_p2.should == 'Protoss'
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should store the favorite race for player 3' do
|
72
|
-
@options = {:favorite_race_p3 => 'Protoss'}
|
73
47
|
member.favorite_race_p3.should == 'Protoss'
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'should store the favorite race for player 4' do
|
77
|
-
@options = {:favorite_race_p4 => 'Protoss'}
|
78
48
|
member.favorite_race_p4.should == 'Protoss'
|
79
49
|
end
|
80
50
|
end
|
81
|
-
end
|
51
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Starcraft2::Profile::AchievementItem do
|
4
|
+
describe '.initialize' do
|
5
|
+
let(:achievement_item) { Starcraft2::Profile::AchievementItem.new(@options) }
|
6
|
+
|
7
|
+
before do
|
8
|
+
@options = {'achievementId' => 1, 'completionDate' => 13333333}
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should store attributes as underscored' do
|
12
|
+
achievement_item.achievement_id.should == 1
|
13
|
+
achievement_item.completion_date.should == 13333333
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should use Stracraft2::Utils.load to populate the model' do
|
17
|
+
Starcraft2::Utils.should_receive(:load).with(anything, @options)
|
18
|
+
|
19
|
+
achievement_item
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#build' do
|
24
|
+
let(:achievement_items) { Starcraft2::Profile::AchievementItem.build(@items) }
|
25
|
+
|
26
|
+
before do
|
27
|
+
@items = [
|
28
|
+
{'achievementId' => 1},
|
29
|
+
{'achievementId' => 2}
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should build multiple achievement items' do
|
34
|
+
achievement_items.class.should == Array
|
35
|
+
achievement_items.each do |ai|
|
36
|
+
ai.class.should == Starcraft2::Profile::AchievementItem
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should build items using new' do
|
41
|
+
@items.each do |i|
|
42
|
+
Starcraft2::Profile::AchievementItem.should_receive(:new).with(i)
|
43
|
+
end
|
44
|
+
|
45
|
+
achievement_items
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,35 +1,44 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Starcraft2::Profile::Achievements do
|
4
|
-
|
4
|
+
describe '.initialize' do
|
5
|
+
let(:achievements) { Starcraft2::Profile::Achievements.new(@options) }
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
7
|
+
before do
|
8
|
+
@options = {
|
9
|
+
'points' => {
|
10
|
+
'totalPoints' => 3420,
|
11
|
+
'categoryPoints' => {
|
12
|
+
'4325382' => 0,
|
13
|
+
'4325380' => 80
|
14
|
+
}
|
15
|
+
},
|
16
|
+
'achievements' => [
|
17
|
+
{
|
18
|
+
'achievementId' => 91475035553845,
|
19
|
+
'completionDate' => 1365790265
|
20
|
+
}
|
21
|
+
]
|
20
22
|
}
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should store attributes as underscored' do
|
26
|
+
achievements.points.class.should == Starcraft2::Profile::Points
|
27
|
+
achievements.points.total_points.should == 3420
|
28
|
+
achievements.points.category_points.should == @options['points']['categoryPoints']
|
29
|
+
|
30
|
+
achievements.achievements.class.should == Array
|
31
|
+
|
32
|
+
achievement_item = achievements.achievements.first
|
33
|
+
achievement_item.class.should == Starcraft2::Profile::AchievementItem
|
34
|
+
achievement_item.achievement_id.should == 91475035553845
|
35
|
+
achievement_item.completion_date.should == 1365790265
|
36
|
+
end
|
24
37
|
|
25
|
-
|
26
|
-
|
27
|
-
{ :achievement_id => 91475320768475, :completion_date => 1365392587},
|
28
|
-
{ :achievement_id => 91475320768585, :completion_date => 1364634012}]}
|
38
|
+
it 'should use Stracraft2::Utils.load to populate the model' do
|
39
|
+
Starcraft2::Utils.should_receive(:load).with(anything, @options, {:points => Starcraft2::Profile::Points}, {:achievements => Starcraft2::Profile::AchievementItem})
|
29
40
|
|
30
|
-
|
31
|
-
|
32
|
-
achievements.achievements.first.achievement_id.should == 91475035553845
|
33
|
-
achievements.achievements.first.completion_date.should == 1365790265
|
41
|
+
achievements
|
42
|
+
end
|
34
43
|
end
|
35
|
-
end
|
44
|
+
end
|
@@ -4,18 +4,19 @@ describe Starcraft2::Profile::Campaign do
|
|
4
4
|
let(:campaign) { Starcraft2::Profile::Campaign.new(@options) }
|
5
5
|
|
6
6
|
before do
|
7
|
-
@options = {}
|
7
|
+
@options = {'wol' => 'BRUTAL', 'hots' => 'BRUTAL'}
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '.initialize' do
|
11
|
-
it 'should store
|
12
|
-
@options = {:wol => 'BRUTAL'}
|
11
|
+
it 'should store attributes as underscored' do
|
13
12
|
campaign.wol.should == 'BRUTAL'
|
13
|
+
campaign.hots.should == 'BRUTAL'
|
14
14
|
end
|
15
15
|
|
16
|
-
it 'should
|
17
|
-
@options
|
18
|
-
|
16
|
+
it 'should use Stracraft2::Utils.load to populate the model' do
|
17
|
+
Starcraft2::Utils.should_receive(:load).with(anything, @options)
|
18
|
+
|
19
|
+
campaign
|
19
20
|
end
|
20
21
|
end
|
21
|
-
end
|
22
|
+
end
|
@@ -1,54 +1,37 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Starcraft2::Profile::Career do
|
4
|
-
let(:
|
4
|
+
let(:career) { Starcraft2::Profile::Career.new(@options) }
|
5
5
|
|
6
6
|
before do
|
7
|
-
@options = {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should store
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
@options = {:highest1v1_rank => 'GOLD'}
|
37
|
-
profile.highest1v1_rank.should == 'GOLD'
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should store the highest_team_rank' do
|
41
|
-
@options = {:highest_team_rank => 'MASTER'}
|
42
|
-
profile.highest_team_rank.should =='MASTER'
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should store the season_total_games' do
|
46
|
-
@options = {:season_total_games => 596}
|
47
|
-
profile.season_total_games.should == 596
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should store the career_total_games' do
|
51
|
-
@options = {:career_total_games => 1293}
|
52
|
-
profile.career_total_games.should == 1293
|
7
|
+
@options = {
|
8
|
+
'primaryRace' => 'PROTOSS',
|
9
|
+
'league' => 'GAMMA',
|
10
|
+
'terranWins' => 121,
|
11
|
+
'protossWins' => 123,
|
12
|
+
'zergWins' => 82,
|
13
|
+
'highest1v1Rank' => 'GOLD',
|
14
|
+
'highestTeamRank' => 'MASTER',
|
15
|
+
'seasonTotalGames' => 596,
|
16
|
+
'careerTotalGames' => 1293
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should store attributes as underscored' do
|
21
|
+
career.primary_race.should == 'PROTOSS'
|
22
|
+
career.league.should == 'GAMMA'
|
23
|
+
career.terran_wins.should == 121
|
24
|
+
career.protoss_wins.should == 123
|
25
|
+
career.zerg_wins.should == 82
|
26
|
+
career.highest1v1_rank.should == 'GOLD'
|
27
|
+
career.highest_team_rank.should =='MASTER'
|
28
|
+
career.season_total_games.should == 596
|
29
|
+
career.career_total_games.should == 1293
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should use Stracraft2::Utils.load to populate the model' do
|
33
|
+
Starcraft2::Utils.should_receive(:load).with(anything, @options)
|
34
|
+
|
35
|
+
career
|
53
36
|
end
|
54
37
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Starcraft2::Profile::DetailedSeason do
|
4
|
+
describe '.initialize' do
|
5
|
+
let(:detailed_season) { Starcraft2::Profile::DetailedSeason.new(@options) }
|
6
|
+
|
7
|
+
it 'should store attributes as underscored' do
|
8
|
+
@options = {
|
9
|
+
'ladder' => [],
|
10
|
+
'characters' => [
|
11
|
+
{
|
12
|
+
'id' => 3113795,
|
13
|
+
'realm' => 1,
|
14
|
+
'displayName' => 'Smix',
|
15
|
+
'clanName' => '',
|
16
|
+
'clanTag' => '',
|
17
|
+
'profilePath' => '/profile/3113795/1/Smix/'
|
18
|
+
}, {
|
19
|
+
'id' => 1283116,
|
20
|
+
'realm' => 1,
|
21
|
+
'displayName' => 'megumixbear',
|
22
|
+
'clanName' => '',
|
23
|
+
'clanTag' => '',
|
24
|
+
'profilePath' => '/profile/1283116/1/megumixbear/'
|
25
|
+
}
|
26
|
+
],
|
27
|
+
'nonRanked' => []
|
28
|
+
}
|
29
|
+
|
30
|
+
detailed_season.ladder.should == []
|
31
|
+
|
32
|
+
detailed_season.characters.class.should == Array
|
33
|
+
detailed_season.characters.each do |c|
|
34
|
+
c.class.should == Starcraft2::Character
|
35
|
+
end
|
36
|
+
|
37
|
+
c1 = detailed_season.characters.first
|
38
|
+
c1.id.should == 3113795
|
39
|
+
c1.realm.should == 1
|
40
|
+
c1.display_name.should == 'Smix'
|
41
|
+
c1.clan_name.should == ''
|
42
|
+
c1.clan_tag.should == ''
|
43
|
+
c1.profile_path.should == '/profile/3113795/1/Smix/'
|
44
|
+
|
45
|
+
c2 = detailed_season.characters.last
|
46
|
+
c2.id.should == 1283116
|
47
|
+
c2.realm.should == 1
|
48
|
+
c2.display_name.should == 'megumixbear'
|
49
|
+
c2.clan_name.should == ''
|
50
|
+
c2.clan_tag.should == ''
|
51
|
+
c2.profile_path.should == '/profile/1283116/1/megumixbear/'
|
52
|
+
|
53
|
+
detailed_season.non_ranked.should == []
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should use Stracraft2::Utils.load to populate the model' do
|
57
|
+
Starcraft2::Utils.should_receive(:load).with(anything, @options, {}, {:ladder => Starcraft2::Profile::Ladder, :characters => Starcraft2::Character, :non_ranked => Starcraft2::Profile::NonRank})
|
58
|
+
|
59
|
+
detailed_season
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#build' do
|
64
|
+
let(:detailed_seasons) { Starcraft2::Profile::DetailedSeason.build(@items) }
|
65
|
+
|
66
|
+
before do
|
67
|
+
@items = [
|
68
|
+
{
|
69
|
+
'characters' => [
|
70
|
+
{'id' => 3113795},
|
71
|
+
{'id' => 1283116}
|
72
|
+
]
|
73
|
+
},
|
74
|
+
{
|
75
|
+
'characters' => [
|
76
|
+
{'id' => 3113796},
|
77
|
+
{'id' => 1283117}
|
78
|
+
]
|
79
|
+
}
|
80
|
+
]
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should build multiple detailed seasons' do
|
84
|
+
detailed_seasons.class.should == Array
|
85
|
+
detailed_seasons.each do |ds|
|
86
|
+
ds.class.should == Starcraft2::Profile::DetailedSeason
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should build items using new' do
|
91
|
+
@items.each do |i|
|
92
|
+
Starcraft2::Profile::DetailedSeason.should_receive(:new).with(i)
|
93
|
+
end
|
94
|
+
|
95
|
+
detailed_seasons
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|