starcraft2 0.1.1 → 0.2.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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/fixtures/cassettes/ladders_999000.yml +1053 -0
  3. data/lib/starcraft2/character.rb +7 -1
  4. data/lib/starcraft2/client.rb +33 -19
  5. data/lib/starcraft2/loader.rb +4 -0
  6. data/lib/starcraft2/profile.rb +5 -1
  7. data/lib/starcraft2/profile/achievement_item.rb +3 -3
  8. data/lib/starcraft2/profile/achievements.rb +2 -2
  9. data/lib/starcraft2/profile/campaign.rb +2 -2
  10. data/lib/starcraft2/profile/career.rb +2 -2
  11. data/lib/starcraft2/profile/detailed_season.rb +17 -0
  12. data/lib/starcraft2/profile/ladder.rb +17 -0
  13. data/lib/starcraft2/profile/ladders.rb +11 -0
  14. data/lib/starcraft2/profile/match.rb +1 -1
  15. data/lib/starcraft2/profile/non_rank.rb +18 -0
  16. data/lib/starcraft2/profile/points.rb +1 -1
  17. data/lib/starcraft2/profile/season.rb +1 -1
  18. data/lib/starcraft2/profile/stats.rb +2 -2
  19. data/spec/starcraft2/achievement_spec.rb +42 -45
  20. data/spec/starcraft2/character_spec.rb +37 -19
  21. data/spec/starcraft2/client_spec.rb +2 -4
  22. data/spec/starcraft2/icon_spec.rb +7 -22
  23. data/spec/starcraft2/member_spec.rb +24 -54
  24. data/spec/starcraft2/profile/achievement_item_spec.rb +48 -0
  25. data/spec/starcraft2/profile/achievements_spec.rb +36 -27
  26. data/spec/starcraft2/profile/campaign_spec.rb +8 -7
  27. data/spec/starcraft2/profile/career_spec.rb +30 -47
  28. data/spec/starcraft2/profile/detailed_season_spec.rb +98 -0
  29. data/spec/starcraft2/profile/ladder_spec.rb +63 -0
  30. data/spec/starcraft2/profile/ladders_spec.rb +197 -0
  31. data/spec/starcraft2/profile/match_spec.rb +41 -22
  32. data/spec/starcraft2/profile/non_rank_spec.rb +48 -0
  33. data/spec/starcraft2/profile/points_spec.rb +22 -0
  34. data/spec/starcraft2/profile/rewards_spec.rb +17 -11
  35. data/spec/starcraft2/profile/season_spec.rb +33 -23
  36. data/spec/starcraft2/profile/stats_spec.rb +49 -0
  37. data/spec/starcraft2/profile/swarm_levels_spec.rb +29 -16
  38. data/spec/starcraft2/profile/swarm_race_spec.rb +25 -0
  39. data/spec/starcraft2/profile_spec.rb +80 -73
  40. data/spec/starcraft2/reward_spec.rb +22 -31
  41. data/spec/starcraft2/utils_spec.rb +30 -0
  42. data/starcraft2.gemspec +1 -1
  43. metadata +15 -2
@@ -1,31 +1,41 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Starcraft2::Profile::Season do
4
- let(:season) { Starcraft2::Profile::Season.new(@options) }
4
+ describe '.initialize' do
5
+ let(:season) { Starcraft2::Profile::Season.new(@options) }
5
6
 
6
- before do
7
- @options = {}
8
- end
7
+ before do
8
+ @options = {
9
+ 'seasonId' => 11,
10
+ 'totalGamesThisSeason' => 252,
11
+ 'stats' => [{'type' => '1v1', 'wins' => 129, 'games' => 102}, {'type' => '2v2', 'wins' => 21, 'games' => 9}]
12
+ }
13
+ end
9
14
 
10
- it 'should store the season_id' do
11
- @options = {:season_id => 11}
12
- season.season_id.should == 11
13
- end
15
+ it 'should store attributes as underscored' do
16
+ season.season_id.should == 11
17
+ season.total_games_this_season.should == 252
14
18
 
15
- it 'should store the total_games_this_season' do
16
- @options = {:total_games_this_season => 252}
17
- season.total_games_this_season.should == 252
18
- end
19
+ season.stats.class.should == Array
20
+ season.stats.each do |s|
21
+ s.class.should == Starcraft2::Profile::Stats
22
+ end
23
+
24
+ s1 = season.stats.first
25
+ s1.type.should == '1v1'
26
+ s1.wins.should == 129
27
+ s1.games.should == 102
28
+
29
+ s2 = season.stats.last
30
+ s2.type.should == '2v2'
31
+ s2.wins.should == 21
32
+ s2.games.should == 9
33
+ end
34
+
35
+ it 'should use Stracraft2::Utils.load to populate the model' do
36
+ Starcraft2::Utils.should_receive(:load).with(anything, @options, {}, {:stats => Starcraft2::Profile::Stats})
19
37
 
20
- it 'should store the stats' do
21
- @options = {:stats => [{ :type => '1v1', :wins => 129, :games => 102 }, { :type => '2v2', :wins => 21, :games => 9}]}
22
- season.stats.class.should == Array
23
- season.stats.first.class.should == Starcraft2::Profile::Stats
24
- season.stats.first.type.should == '1v1'
25
- season.stats.first.wins.should == 129
26
- season.stats.first.games.should == 102
27
- season.stats.last.type.should == '2v2'
28
- season.stats.last.wins.should == 21
29
- season.stats.last.games.should == 9
38
+ season
39
+ end
30
40
  end
31
- end
41
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe Starcraft2::Profile::Stats do
4
+ describe '.initialize' do
5
+ let(:stats) { Starcraft2::Profile::Stats.new(@options) }
6
+
7
+ before do
8
+ @options = {'type' => 'foo', 'wins' => 5, 'games' => 40}
9
+ end
10
+
11
+ it 'should store attributes as underscored' do
12
+ stats.type.should == 'foo'
13
+ stats.wins.should == 5
14
+ stats.games.should == 40
15
+ end
16
+
17
+ it 'should use Stracraft2::Utils.load to populate the model' do
18
+ Starcraft2::Utils.should_receive(:load).with(anything, @options)
19
+
20
+ stats
21
+ end
22
+ end
23
+
24
+ describe '#build' do
25
+ let(:stats_array) { Starcraft2::Profile::Stats.build(@items) }
26
+
27
+ before do
28
+ @items = [
29
+ {'type' => 'foo'},
30
+ {'type' => 'bar'}
31
+ ]
32
+ end
33
+
34
+ it 'should build multiple stats objects' do
35
+ stats_array.class.should == Array
36
+ stats_array.each do |s|
37
+ s.class.should == Starcraft2::Profile::Stats
38
+ end
39
+ end
40
+
41
+ it 'should build items using new' do
42
+ @items.each do |i|
43
+ Starcraft2::Profile::Stats.should_receive(:new).with(i)
44
+ end
45
+
46
+ stats_array
47
+ end
48
+ end
49
+ end
@@ -1,40 +1,53 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Starcraft2::Profile::SwarmLevels do
4
- let(:swarm_levels) { Starcraft2::Profile::SwarmLevels.new(@options) }
4
+ describe '.initialize' do
5
+ let(:swarm_levels) { Starcraft2::Profile::SwarmLevels.new(@options) }
5
6
 
6
- before do
7
- @options = {}
8
- end
7
+ before do
8
+ @options = {
9
+ 'level' => 10,
10
+ 'terran' => {
11
+ 'level' => 9,
12
+ 'totalLevelXP' => 150000,
13
+ 'currentLevelXP' => 8826
14
+ },
15
+ 'zerg' => {
16
+ 'level' => 9,
17
+ 'totalLevelXP' => 150000,
18
+ 'currentLevelXP' => 8826
19
+ },
20
+ 'protoss' => {
21
+ 'level' => 9,
22
+ 'totalLevelXP' => 150000,
23
+ 'current_level_XP' => 8826
24
+ }
25
+ }
26
+ end
9
27
 
10
- describe '.initialize' do
11
- it 'should store the level' do
12
- @options = {:level => 10}
28
+ it 'should store attributes as underscored' do
13
29
  swarm_levels.level.should == 10
14
- end
15
30
 
16
- it 'should store terran info' do
17
- @options = {:terran => {:level => 9, :total_level_XP => 150000, :current_level_XP => 8826}}
18
31
  swarm_levels.terran.class.should == Starcraft2::Profile::SwarmRace
19
32
  swarm_levels.terran.level.should == 9
20
33
  swarm_levels.terran.total_level_xp.should == 150000
21
34
  swarm_levels.terran.current_level_xp.should == 8826
22
- end
23
35
 
24
- it 'should store zerg info' do
25
- @options = {:zerg => {:level => 9, :total_level_XP => 150000, :current_level_XP => 8826}}
26
36
  swarm_levels.zerg.class.should == Starcraft2::Profile::SwarmRace
27
37
  swarm_levels.zerg.level.should == 9
28
38
  swarm_levels.zerg.total_level_xp.should == 150000
29
39
  swarm_levels.zerg.current_level_xp.should == 8826
30
- end
31
40
 
32
- it 'should store protoss info' do
33
- @options = {:protoss => {:level => 9, :total_level_XP => 150000, :current_level_XP => 8826}}
34
41
  swarm_levels.protoss.class.should == Starcraft2::Profile::SwarmRace
35
42
  swarm_levels.protoss.level.should == 9
36
43
  swarm_levels.protoss.total_level_xp.should == 150000
37
44
  swarm_levels.protoss.current_level_xp.should == 8826
38
45
  end
46
+
47
+ it 'should use Stracraft2::Utils.load to populate the model' do
48
+ Starcraft2::Utils.should_receive(:load).with(anything, @options, {:terran => Starcraft2::Profile::SwarmRace, :zerg => Starcraft2::Profile::SwarmRace, :protoss => Starcraft2::Profile::SwarmRace})
49
+
50
+ swarm_levels
51
+ end
39
52
  end
40
53
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Starcraft2::Profile::SwarmRace do
4
+ describe '.initialize' do
5
+ let(:swarm_race) { Starcraft2::Profile::SwarmRace.new(@options) }
6
+
7
+ before do
8
+ @options = {
9
+ 'level' => 5, 'totalLevelXP' => 5000, 'currentLevelXP' => 2
10
+ }
11
+ end
12
+
13
+ it 'should store attributes as underscored' do
14
+ swarm_race.level.should == 5
15
+ swarm_race.total_level_xp.should == 5000
16
+ swarm_race.current_level_xp.should == 2
17
+ end
18
+
19
+ it 'should use Stracraft2::Utils.load to populate the model' do
20
+ Starcraft2::Utils.should_receive(:load).with(anything, @options)
21
+
22
+ swarm_race
23
+ end
24
+ end
25
+ end
@@ -23,33 +23,21 @@ describe Starcraft2::Profile do
23
23
  @options = {}
24
24
  end
25
25
 
26
- it 'should store the id' do
27
- @options = {:id => 12345}
28
- profile.id.should == 12345
29
- end
26
+ it 'should store the attributes as underscored' do
27
+ @options = {
28
+ 'id' => 12345,
29
+ 'realm' => 1,
30
+ 'displayName' => 'steve',
31
+ 'clanName' => 'clan',
32
+ 'clanTag' => 'tag',
33
+ 'profilePath' => '/profile/example'
34
+ }
30
35
 
31
- it 'should store the realm' do
32
- @options = {:realm => 1}
36
+ profile.id.should == 12345
33
37
  profile.realm.should == 1
34
- end
35
-
36
- it 'should store the display_name' do
37
- @options = {:display_name => 'steve'}
38
38
  profile.display_name.should == 'steve'
39
- end
40
-
41
- it 'should store the clan_name' do
42
- @options = {:clan_name => 'clan'}
43
39
  profile.clan_name.should == 'clan'
44
- end
45
-
46
- it 'should store the clan_tag' do
47
- @options = {:clan_tag => 'tag'}
48
40
  profile.clan_tag.should == 'tag'
49
- end
50
-
51
- it 'should store the profile_path' do
52
- @options = {:profile_path => '/profile/example'}
53
41
  profile.profile_path.should == '/profile/example'
54
42
  end
55
43
 
@@ -63,18 +51,18 @@ describe Starcraft2::Profile do
63
51
  profile.portrait.url.should == 'https://example.com'
64
52
  end
65
53
 
66
- it 'should store the career' do
54
+ it 'should store the career attributes as underscored' do
67
55
  @options = {
68
- :career => {
69
- :primary_race => 'TERRAN',
70
- :league => 'KAPPA',
71
- :terran_wins => 1,
72
- :protoss_wins => 268,
73
- :zerg_wins => 7,
74
- :highest1v1_rank => 'MASTER',
75
- :highest_team_rank => 'MASTER',
76
- :season_total_games => 399,
77
- :career_total_games => 1531
56
+ 'career' => {
57
+ 'primaryRace' => 'TERRAN',
58
+ 'league' => 'KAPPA',
59
+ 'terranWins' => 1,
60
+ 'protossWins' => 268,
61
+ 'zergWins' => 7,
62
+ 'highest1v1Rank' => 'MASTER',
63
+ 'highestTeamRank' => 'MASTER',
64
+ 'seasonTotalGames' => 399,
65
+ 'careerTotalGames' => 1531
78
66
  }
79
67
  }
80
68
  profile.career.primary_race.should == 'TERRAN'
@@ -88,24 +76,24 @@ describe Starcraft2::Profile do
88
76
  profile.career.career_total_games.should == 1531
89
77
  end
90
78
 
91
- it 'should store the swarm_levels' do
79
+ it 'should store the swarm_levels as underscored' do
92
80
  @options = {
93
- :swarm_levels => {
94
- :level => 45,
95
- :terran => {
96
- :level => 9,
97
- :total_level_XP => 150000,
98
- :current_level_XP => 8826
81
+ 'swarmLevels' => {
82
+ 'level' => 45,
83
+ 'terran' => {
84
+ 'level' => 9,
85
+ 'totalLevelXP' => 150000,
86
+ 'currentLevelXP' => 8826
99
87
  },
100
- :zerg => {
101
- :level => 6,
102
- :total_level_XP => 150000,
103
- :current_level_XP => 1231
88
+ 'zerg' => {
89
+ 'level' => 6,
90
+ 'totalLevelXP' => 150000,
91
+ 'currentLevelXP' => 1231
104
92
  },
105
- :protoss => {
106
- :level => 30,
107
- :total_level_XP => 150000,
108
- :current_level_XP => 8826
93
+ 'protoss' => {
94
+ 'level' => 30,
95
+ 'totalLevelXP' => 150000,
96
+ 'currentLevelXP' => 8826
109
97
  }
110
98
  }
111
99
  }
@@ -133,35 +121,39 @@ describe Starcraft2::Profile do
133
121
  end
134
122
 
135
123
  it 'should store the campaign' do
136
- @options = {:campaign => {:wol => 'BRUTAL', :hots => 'BRUTAL'}}
124
+ @options = {:campaign => {'wol' => 'BRUTAL', 'hots' => 'BRUTAL'}}
137
125
  profile.campaign.wol.should == 'BRUTAL'
138
126
  profile.campaign.hots.should == 'BRUTAL'
139
127
  end
140
128
 
141
- it 'should store the season' do
129
+ it 'should store the season as underscored' do
142
130
  @options = {
143
- :season => {
144
- :season_id => 14,
145
- :total_games_this_season => 399,
146
- :stats => [
131
+ 'season' => {
132
+ 'seasonId' => 14,
133
+ 'totalGamesThisSeason' => 399,
134
+ 'stats' => [
147
135
  {
148
- :type => '1v1',
149
- :wins => 254,
150
- :games => 357
136
+ 'type' => '1v1',
137
+ 'wins' => 254,
138
+ 'games' => 357
151
139
  }, {
152
- :type => '2v2',
153
- :wins => 27,
154
- :games => 39
140
+ 'type' => '2v2',
141
+ 'wins' => 27,
142
+ 'games' => 39
155
143
  }
156
144
  ]
157
145
  }}
146
+ profile.season.class.should == Starcraft2::Profile::Season
147
+ profile.season.season_id.should == 14
148
+ profile.season.stats.class.should == Array
149
+ profile.season.stats.first.class.should == Starcraft2::Profile::Stats
158
150
  end
159
151
 
160
152
  it 'should store the rewards' do
161
153
  @options = {
162
- :rewards => {
163
- :selected => [18730036, 2009110693, 2359737029, 4189275055],
164
- :earned => [144654643, 171155159, 199895074, 234481452, 367294557, 531423509, 533048170, 637508413]
154
+ 'rewards' => {
155
+ 'selected' => [18730036, 2009110693, 2359737029, 4189275055],
156
+ 'earned' => [144654643, 171155159, 199895074, 234481452, 367294557, 531423509, 533048170, 637508413]
165
157
  }
166
158
  }
167
159
  profile.rewards.selected.should == [18730036, 2009110693, 2359737029, 4189275055]
@@ -170,10 +162,10 @@ describe Starcraft2::Profile do
170
162
 
171
163
  it 'should store the achievements' do
172
164
  @options = {
173
- :achievements => {
174
- :points => {
175
- :totalPoints => 3375,
176
- :categoryPoints => {
165
+ 'achievements' => {
166
+ 'points' => {
167
+ 'totalPoints' => 3375,
168
+ 'categoryPoints' => {
177
169
  '4325382' => 0,
178
170
  '4325380' => 390,
179
171
  '4325408' => 90,
@@ -182,17 +174,21 @@ describe Starcraft2::Profile do
182
174
  '4325377' => 600
183
175
  }
184
176
  },
185
- :achievements => [
177
+ 'achievements' => [
186
178
  {
187
- :achievementId => 91475320766493,
188
- :completionDate => 1375779974
179
+ 'achievementId' => 91475320766493,
180
+ 'completionDate' => 1375779974
189
181
  }, {
190
- :achievementId => 91475035553809,
191
- :completionDate => 1371117026
182
+ 'achievementId' => 91475035553809,
183
+ 'completionDate' => 1371117026
192
184
  }
193
185
  ]
194
186
  }
195
187
  }
188
+ profile.achievements.class.should == Starcraft2::Profile::Achievements
189
+ profile.achievements.points.class.should == Starcraft2::Profile::Points
190
+ profile.achievements.achievements.class.should == Array
191
+ profile.achievements.achievements.first.class.should == Starcraft2::Profile::AchievementItem
196
192
  end
197
193
  end
198
194
 
@@ -200,7 +196,7 @@ describe Starcraft2::Profile do
200
196
  let(:client) { Starcraft2::Client.new() }
201
197
 
202
198
  it 'should return a list of matches' do
203
- VCR.use_cassette("matches_999000") do
199
+ VCR.use_cassette('matches_999000') do
204
200
  matches = client.profile(:character_name => 'DayNine', :id => 999000, :realm => 1).matches
205
201
  matches.class.should == Array
206
202
  matches.first.class.should == Starcraft2::Profile::Match
@@ -212,4 +208,15 @@ describe Starcraft2::Profile do
212
208
  end
213
209
  end
214
210
  end
211
+
212
+ describe '.ladders' do
213
+ it 'should return a profiles ladder information' do
214
+ VCR.use_cassette('ladders_999000') do
215
+ ladders = client.profile(:character_name => 'DayNine', :id => 999000, :realm => 1).ladders
216
+ ladders.class.should == Starcraft2::Profile::Ladders
217
+ ladders.current_season.first.class.should == Starcraft2::Profile::DetailedSeason
218
+ ladders.current_season.first.ladder.first.ladder_name.should == 'Shuttle Tango'
219
+ end
220
+ end
221
+ end
215
222
  end
@@ -16,53 +16,44 @@ describe Starcraft2::Reward do
16
16
  r.class.should == Starcraft2::Reward
17
17
  end
18
18
  end
19
+
20
+ it 'should import the first reward' do
21
+ reward = rewards.first
22
+
23
+ reward.title.should == 'Kachinsky'
24
+ reward.id.should == 2951153716
25
+ reward.icon.x.should == 0
26
+ reward.icon.y.should == 0
27
+ reward.icon.w.should == 90
28
+ reward.icon.h.should == 90
29
+ reward.icon.offset.should == 0
30
+ reward.icon.url.should == 'http://media.blizzard.com/sc2/portraits/0-90.jpg'
31
+ reward.achievement_id.should == 0
32
+ end
19
33
  end
20
34
 
21
35
  describe '.initialize' do
22
36
  let(:reward) { Starcraft2::Reward.new(@options) }
23
37
 
24
38
  before do
25
- @options = {}
26
- end
27
-
28
- it 'should import the first reward' do
29
- VCR.use_cassette('rewards') do
30
- @reward = Starcraft2::Reward.build(JSON.parse(HTTParty.get('https://us.battle.net/api/sc2/data/rewards').body)).first
31
- end
32
-
33
- @reward.title.should == 'Kachinsky'
34
- @reward.id.should == 2951153716
35
- @reward.icon.x.should == 0
36
- @reward.icon.y.should == 0
37
- @reward.icon.w.should == 90
38
- @reward.icon.h.should == 90
39
- @reward.icon.offset.should == 0
40
- @reward.icon.url.should == 'http://media.blizzard.com/sc2/portraits/0-90.jpg'
41
- @reward.achievement_id.should == 0
39
+ @options = {
40
+ 'title' => 'Test Title',
41
+ 'id' => 3,
42
+ 'icon' => {'x' => 1, 'y' => 2, 'w' => 3, 'h' => 4, 'offset' => 0, 'url' => 'https://example.com'},
43
+ 'achievement_id' => 5
44
+ }
42
45
  end
43
46
 
44
- it 'should store the title' do
45
- @options = {:title => 'Test Title'}
47
+ it 'should store attributes as underscored' do
46
48
  reward.title.should == 'Test Title'
47
- end
48
-
49
- it 'should store the id' do
50
- @options = {:id => 3}
51
49
  reward.id.should == 3
52
- end
53
-
54
- it 'should store the icon data' do
55
- @options = {:icon => {'x' => 1, 'y' => 2, 'w' => 3, 'h' => 4, 'offset' => 0, 'url' => 'https://example.com'}}
50
+ reward.icon.class.should == Starcraft2::Icon
56
51
  reward.icon.x.should == 1
57
52
  reward.icon.y.should == 2
58
53
  reward.icon.w.should == 3
59
54
  reward.icon.h.should == 4
60
55
  reward.icon.offset.should == 0
61
56
  reward.icon.url.should == 'https://example.com'
62
- end
63
-
64
- it 'should store the achievement id' do
65
- @options = {:achievement_id => 5}
66
57
  reward.achievement_id.should == 5
67
58
  end
68
59
  end