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
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Starcraft2::Profile::Ladder do
4
+ describe '.initialize' do
5
+ let(:ladder) { Starcraft2::Profile::Ladder.new(@options) }
6
+
7
+ it 'should store attributes as underscored' do
8
+ @options = {
9
+ 'ladderName' => 'Shuttle Tango',
10
+ 'ladderId' => 153300,
11
+ 'division' => 34,
12
+ 'rank' => 28,
13
+ 'league' => 'PLATINUM',
14
+ 'matchMakingQueue' => 'HOTS_TWOS',
15
+ 'wins' => 7,
16
+ 'losses' => 1,
17
+ 'showcase' => true
18
+ }
19
+
20
+ ladder.ladder_name.should == 'Shuttle Tango'
21
+ ladder.ladder_id.should == 153300
22
+ ladder.division.should == 34
23
+ ladder.rank.should == 28
24
+ ladder.league.should == 'PLATINUM'
25
+ ladder.match_making_queue.should == 'HOTS_TWOS'
26
+ ladder.wins.should == 7
27
+ ladder.losses.should == 1
28
+ ladder.showcase.should == true
29
+ end
30
+
31
+ it 'should use Stracraft2::Utils.load to populate the model' do
32
+ Starcraft2::Utils.should_receive(:load).with(anything, @options)
33
+
34
+ ladder
35
+ end
36
+ end
37
+
38
+ describe '#build' do
39
+ let(:ladders) { Starcraft2::Profile::Ladder.build(@items) }
40
+
41
+ before do
42
+ @items = [
43
+ {'ladderName' => 'Shuttle Tango'},
44
+ {'ladderName' => 'Other'}
45
+ ]
46
+ end
47
+
48
+ it 'should build multiple ladders' do
49
+ ladders.class.should == Array
50
+ ladders.each do |l|
51
+ l.class.should == Starcraft2::Profile::Ladder
52
+ end
53
+ end
54
+
55
+ it 'should build items using new' do
56
+ @items.each do |i|
57
+ Starcraft2::Profile::Ladder.should_receive(:new).with(i)
58
+ end
59
+
60
+ ladders
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,197 @@
1
+ require 'spec_helper'
2
+
3
+ describe Starcraft2::Profile::Ladders do
4
+ let(:ladder) { Starcraft2::Profile::Ladders.new(@options) }
5
+
6
+ describe '.initialize' do
7
+ before do
8
+ @options = {}
9
+ end
10
+
11
+ it 'should store the current_season attributes as underscored' do
12
+ @options = {
13
+ 'currentSeason' => [
14
+ {
15
+ 'ladder' => [
16
+ {
17
+ 'ladderName' => 'Shuttle Tango',
18
+ 'ladderId' => 153300,
19
+ 'division' => 34,
20
+ 'rank' => 28,
21
+ 'league' => 'PLATINUM',
22
+ 'matchMakingQueue' => 'HOTS_TWOS',
23
+ 'wins' => 7,
24
+ 'losses' => 1,
25
+ 'showcase' => true
26
+ }
27
+ ],
28
+ 'characters' => [
29
+ {
30
+ 'id' => 999000,
31
+ 'realm' => 1,
32
+ 'displayName' => 'DayNine',
33
+ 'clanName' => 'Team 9',
34
+ 'clanTag' => 'Nine',
35
+ 'profilePath' => '/profile/999000/1/DayNine/'
36
+ }, {
37
+ 'id' => 1283116,
38
+ 'realm' => 1,
39
+ 'displayName' => 'megumixbear',
40
+ 'clanName' => '',
41
+ 'clanTag' => '',
42
+ 'profilePath' => '/profile/1283116/1/megumixbear/'
43
+ }
44
+ ],
45
+ 'nonRanked' => []
46
+ }, {
47
+ 'ladder' => [
48
+ {
49
+ 'ladderName' => 'Torrasque Upsilon',
50
+ 'ladderId' => 154764,
51
+ 'division' => 59,
52
+ 'rank' => 90,
53
+ 'league' => 'PLATINUM',
54
+ 'matchMakingQueue' => 'HOTS_TWOS',
55
+ 'wins' => 4,
56
+ 'losses' => 1,
57
+ 'showcase' => true
58
+ }
59
+ ],
60
+ 'characters' => [
61
+ {
62
+ 'id' => 999000,
63
+ 'realm' => 1,
64
+ 'displayName' => 'DayNine',
65
+ 'clanName' => 'Team 9',
66
+ 'clanTag' => 'Nine',
67
+ 'profilePath' => '/profile/999000/1/DayNine/'
68
+ }, {
69
+ 'id' => 788150,
70
+ 'realm' => 1,
71
+ 'displayName' => 'JPMcD',
72
+ 'clanName' => 'itme',
73
+ 'clanTag' => 'itme',
74
+ 'profilePath' => '/profile/788150/1/JPMcD/'
75
+ }
76
+ ],
77
+ 'nonRanked' => []
78
+ }
79
+ ]
80
+ }
81
+ ladder.current_season.class.should == Array
82
+ ladder.current_season.each do |cs|
83
+ cs.class.should == Starcraft2::Profile::DetailedSeason
84
+ end
85
+
86
+ detailed_season = ladder.current_season.first
87
+ detailed_season.ladder.class.should == Array
88
+ detailed_season.ladder.first.class.should == Starcraft2::Profile::Ladder
89
+
90
+ detailed_season.ladder.first.ladder_name.should == 'Shuttle Tango'
91
+ detailed_season.ladder.first.ladder_id.should == 153300
92
+ detailed_season.ladder.first.division.should == 34
93
+ detailed_season.ladder.first.rank.should == 28
94
+ detailed_season.ladder.first.league.should == 'PLATINUM'
95
+ detailed_season.ladder.first.match_making_queue.should == 'HOTS_TWOS'
96
+ detailed_season.ladder.first.wins.should == 7
97
+ detailed_season.ladder.first.losses.should == 1
98
+
99
+ detailed_season.characters.class.should == Array
100
+ detailed_season.characters.first.id.should == 999000
101
+ detailed_season.characters.first.realm.should == 1
102
+ detailed_season.characters.first.display_name.should == 'DayNine'
103
+ detailed_season.characters.first.clan_name.should == 'Team 9'
104
+ detailed_season.characters.first.clan_tag.should == 'Nine'
105
+ detailed_season.characters.first.profile_path.should == '/profile/999000/1/DayNine/'
106
+
107
+ detailed_season.non_ranked.class.should == Array
108
+ detailed_season.non_ranked.should == []
109
+ end
110
+
111
+ it 'should store the previous_season attributes as underscored' do
112
+ @options = {
113
+ 'previousSeason' => [
114
+ {
115
+ 'ladder' => [],
116
+ 'characters' => [
117
+ {
118
+ 'id' => 3113795,
119
+ 'realm' => 1,
120
+ 'displayName' => 'Smix',
121
+ 'clanName' => '',
122
+ 'clanTag' => '',
123
+ 'profilePath' => '/profile/3113795/1/Smix/'
124
+ }, {
125
+ 'id' => 1283116,
126
+ 'realm' => 1,
127
+ 'displayName' => 'megumixbear',
128
+ 'clanName' => '',
129
+ 'clanTag' => '',
130
+ 'profilePath' => '/profile/1283116/1/megumixbear/'
131
+ }
132
+ ],
133
+ 'nonRanked' => [
134
+ {
135
+ 'mmq' => 'HOTS_TWOS',
136
+ 'gamesPlayed' => 2
137
+ }
138
+ ]
139
+ }, {
140
+ 'ladder' => [
141
+ {
142
+ 'ladderName' => 'Immortal Romeo',
143
+ 'ladderId' => 148509,
144
+ 'division' => 120,
145
+ 'rank' => 61,
146
+ 'league' => 'DIAMOND',
147
+ 'matchMakingQueue' => 'HOTS_SOLO',
148
+ 'wins' => 11,
149
+ 'losses' => 2,
150
+ 'showcase' => false
151
+ }
152
+ ],
153
+ 'characters' => [
154
+ {
155
+ 'id' => 1283116,
156
+ 'realm' => 1,
157
+ 'displayName' => 'megumixbear',
158
+ 'clanName' => '',
159
+ 'clanTag' => '',
160
+ 'profilePath' => '/profile/1283116/1/megumixbear/'
161
+ }
162
+ ],
163
+ 'nonRanked' => []
164
+ }
165
+ ]
166
+ }
167
+
168
+ ladder.previous_season.class.should == Array
169
+ ladder.previous_season.each do |ds|
170
+ ds.class.should == Starcraft2::Profile::DetailedSeason
171
+ end
172
+
173
+ detailed_season = ladder.previous_season.first
174
+ detailed_season.ladder.class.should == Array
175
+ detailed_season.ladder.should == []
176
+
177
+ detailed_season.characters.class.should == Array
178
+ detailed_season.characters.first.id.should == 3113795
179
+ detailed_season.characters.first.realm.should == 1
180
+ detailed_season.characters.first.display_name.should == 'Smix'
181
+ detailed_season.characters.first.clan_name.should == ''
182
+ detailed_season.characters.first.clan_tag.should == ''
183
+ detailed_season.characters.first.profile_path.should == '/profile/3113795/1/Smix/'
184
+
185
+ detailed_season.non_ranked.class.should == Array
186
+ detailed_season.non_ranked.first.class.should == Starcraft2::Profile::NonRank
187
+ detailed_season.non_ranked.first.mmq.should == 'HOTS_TWOS'
188
+ detailed_season.non_ranked.first.games_played.should == 2
189
+ end
190
+
191
+ it 'should set the showcase_placement' do
192
+ @options = {:showcase_placement => []}
193
+ ladder.showcase_placement.should == []
194
+ end
195
+ end
196
+ end
197
+
@@ -1,34 +1,53 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Starcraft2::Profile::Match do
4
- let(:match) {Starcraft2::Profile::Match.new(@options)}
4
+ describe '.initialize' do
5
+ let(:match) { Starcraft2::Profile::Match.new(@options) }
5
6
 
6
- before do
7
- @options = {}
8
- end
7
+ before do
8
+ @options = {'map' => 'foo', 'type' => 'bar', 'decision' => 'wowzer', 'speed' => 'slow', 'date' => 37373837}
9
+ end
9
10
 
10
- it 'should set the map' do
11
- @options = {:map => 'foo'}
12
- match.map.should == 'foo'
13
- end
11
+ it 'should store attributes as underscored' do
12
+ match.map.should == 'foo'
13
+ match.type.should == 'bar'
14
+ match.decision.should == 'wowzer'
15
+ match.speed.should == 'slow'
16
+ match.date.should == 37373837
17
+ end
14
18
 
15
- it 'should set the type' do
16
- @options = {:type => 'bar'}
17
- match.type.should == 'bar'
18
- end
19
+ it 'should use Stracraft2::Utils.load to populate the model' do
20
+ Starcraft2::Utils.should_receive(:load).with(anything, @options)
19
21
 
20
- it 'should set the decision' do
21
- @options = {:decision => 'wowzer'}
22
- match.decision.should == 'wowzer'
22
+ match
23
+ end
23
24
  end
24
25
 
25
- it 'should set the speed' do
26
- @options = {:speed => 'slow'}
27
- match.speed.should == 'slow'
28
- end
26
+ describe '#build' do
27
+ let(:matches) { Starcraft2::Profile::Match.build(@items) }
28
+
29
+ before do
30
+ @items = {
31
+ 'matches' => [
32
+ {'map' => 'uno'},
33
+ {'map' => 'due'}
34
+ ]
35
+ }
36
+ end
37
+
38
+ it 'should build multiple matches' do
39
+ matches.class.should == Array
40
+ matches.each do |ai|
41
+ ai.class.should == Starcraft2::Profile::Match
42
+ end
43
+ end
44
+
45
+ it 'should build items using new' do
46
+ @items['matches'].each do |i|
47
+ Starcraft2::Profile::Match.should_receive(:new).with(i)
48
+ end
29
49
 
30
- it 'should set the date' do
31
- @options = {:date => 37373837}
32
- match.date.should == 37373837
50
+ matches
51
+ end
33
52
  end
34
53
  end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Starcraft2::Profile::NonRank do
4
+ describe '.initialize' do
5
+ let(:non_rank) { Starcraft2::Profile::NonRank.new(@options) }
6
+
7
+ before do
8
+ @options = {'mmq' => 'foo', 'gamesPlayed' => 10}
9
+ end
10
+
11
+ it 'should store attributes as underscored' do
12
+ non_rank.mmq.should == 'foo'
13
+ non_rank.games_played.should == 10
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
+ non_rank
20
+ end
21
+ end
22
+
23
+ describe '#build' do
24
+ let(:non_ranks) { Starcraft2::Profile::NonRank.build(@items) }
25
+
26
+ before do
27
+ @items = [
28
+ {'mmq' => 'uno'},
29
+ {'mmq' => 'due'}
30
+ ]
31
+ end
32
+
33
+ it 'should build multiple non_rank objects' do
34
+ non_ranks.class.should == Array
35
+ non_ranks.each do |ai|
36
+ ai.class.should == Starcraft2::Profile::NonRank
37
+ end
38
+ end
39
+
40
+ it 'should build items using new' do
41
+ @items.each do |i|
42
+ Starcraft2::Profile::NonRank.should_receive(:new).with(i)
43
+ end
44
+
45
+ non_ranks
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Starcraft2::Profile::Points do
4
+ describe '.initialize' do
5
+ let(:points) { Starcraft2::Profile::Points.new(@options) }
6
+
7
+ before do
8
+ @options = {'totalPoints' => 5, 'categoryPoints' => 10}
9
+ end
10
+
11
+ it 'should store attributes as underscored' do
12
+ points.total_points.should == 5
13
+ points.category_points.should == 10
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
+ points
20
+ end
21
+ end
22
+ end
@@ -1,19 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Starcraft2::Profile::Rewards do
4
- let(:rewards) { Starcraft2::Profile::Rewards.new(@options) }
4
+ describe '.initialize' do
5
+ let(:rewards) { Starcraft2::Profile::Rewards.new(@options) }
5
6
 
6
- before do
7
- @options = {}
8
- end
7
+ before do
8
+ @options = {
9
+ 'selected' => [18730036, 2009110693, 2359737029, 3319454886],
10
+ 'earned' => [19065053, 97993138, 171155159, 199895074, 354595443, 367294557, 382993515, 414497095, 540410724]
11
+ }
12
+ end
9
13
 
10
- it 'should store selected' do
11
- @options = {:selected => [18730036, 2009110693, 2359737029, 3319454886]}
12
- rewards.selected.should == [18730036, 2009110693, 2359737029, 3319454886]
13
- end
14
+ it 'should store attributes as underscored' do
15
+ rewards.selected.should == [18730036, 2009110693, 2359737029, 3319454886]
16
+ rewards.earned.should == [19065053, 97993138, 171155159, 199895074, 354595443, 367294557, 382993515, 414497095, 540410724]
17
+ end
18
+
19
+ it 'should use Stracraft2::Utils.load to populate the model' do
20
+ Starcraft2::Utils.should_receive(:load).with(anything, @options)
14
21
 
15
- it 'should store earned' do
16
- @options = {:earned => [19065053, 97993138, 171155159, 199895074, 354595443, 367294557, 382993515, 414497095, 540410724]}
17
- rewards.earned.should == [19065053, 97993138, 171155159, 199895074, 354595443, 367294557, 382993515, 414497095, 540410724]
22
+ rewards
23
+ end
18
24
  end
19
25
  end