ruby-lol 0.0.2 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -0
  3. data/lib/lol.rb +13 -1
  4. data/lib/lol/aggregated_statistic.rb +21 -0
  5. data/lib/lol/champion.rb +0 -4
  6. data/lib/lol/champion_statistic.rb +25 -0
  7. data/lib/lol/champion_statistics_summary.rb +27 -0
  8. data/lib/lol/client.rb +52 -4
  9. data/lib/lol/game.rb +4 -8
  10. data/lib/lol/league.rb +2 -5
  11. data/lib/lol/league_entry.rb +86 -0
  12. data/lib/lol/match_summary.rb +59 -0
  13. data/lib/lol/mini_series.rb +29 -0
  14. data/lib/lol/model.rb +5 -1
  15. data/lib/lol/player.rb +1 -5
  16. data/lib/lol/player_statistic.rb +43 -0
  17. data/lib/lol/ranked_statistics_summary.rb +35 -0
  18. data/lib/lol/{statistic.rb → raw_statistic.rb} +2 -6
  19. data/lib/lol/roster.rb +23 -0
  20. data/lib/lol/team.rb +122 -0
  21. data/lib/lol/team_member.rb +33 -0
  22. data/lib/lol/team_statistic.rb +45 -0
  23. data/lib/lol/version.rb +1 -1
  24. data/spec/fixtures/v1.1/get-ranked_stats.json +1 -0
  25. data/spec/fixtures/v1.1/get-stats.json +1 -0
  26. data/spec/fixtures/v2.1/get-team.json +962 -0
  27. data/spec/lol/aggregated_statistic_spec.rb +19 -0
  28. data/spec/lol/champion_statistic_spec.rb +19 -0
  29. data/spec/lol/champion_statistics_summary_spec.rb +26 -0
  30. data/spec/lol/client_spec.rb +117 -0
  31. data/spec/lol/game_spec.rb +2 -7
  32. data/spec/lol/league_entry_spec.rb +56 -0
  33. data/spec/lol/league_spec.rb +4 -1
  34. data/spec/lol/match_summary_spec.rb +25 -0
  35. data/spec/lol/mini_series_spec.rb +25 -0
  36. data/spec/lol/player_statistic_spec.rb +32 -0
  37. data/spec/lol/ranked_statistics_summary_spec.rb +32 -0
  38. data/spec/lol/{statistic_spec.rb → raw_statistic_spec.rb} +1 -1
  39. data/spec/lol/roster_spec.rb +24 -0
  40. data/spec/lol/team_member_spec.rb +27 -0
  41. data/spec/lol/team_spec.rb +66 -0
  42. data/spec/lol/team_statistic_spec.rb +31 -0
  43. data/spec/support/model_helpers.rb +25 -3
  44. metadata +47 -5
@@ -0,0 +1,19 @@
1
+ require "lol"
2
+ require "spec_helper"
3
+
4
+ include Lol
5
+
6
+ describe AggregatedStatistic do
7
+ it_behaves_like 'Lol model' do
8
+ let(:valid_attributes) { { id: 1 } }
9
+ end
10
+
11
+ %w(id name count).each do |attribute|
12
+ describe "#{attribute} attribute" do
13
+ it_behaves_like 'plain attribute' do
14
+ let(:attribute) { attribute }
15
+ let(:attribute_value) { 'asd' }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+ require "lol"
3
+
4
+ include Lol
5
+
6
+ describe ChampionStatistic do
7
+ it_behaves_like 'Lol model' do
8
+ let(:valid_attributes) { { id: 1 } }
9
+ end
10
+
11
+ %w(id name c value).each do |attribute|
12
+ describe "#{attribute} attribute" do
13
+ it_behaves_like 'plain attribute' do
14
+ let(:attribute) { attribute }
15
+ let(:attribute_value) { 'asd' }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+ require "lol"
3
+
4
+ include Lol
5
+
6
+ describe ChampionStatisticsSummary do
7
+ it_behaves_like 'Lol model' do
8
+ let(:valid_attributes) { { id: 1 } }
9
+ end
10
+
11
+ %w(id name).each do |attribute|
12
+ describe "#{attribute} attribute" do
13
+ it_behaves_like 'plain attribute' do
14
+ let(:attribute) { attribute }
15
+ let(:attribute_value) { 'asd' }
16
+ end
17
+ end
18
+ end
19
+
20
+ describe 'stats attribute' do
21
+ it_behaves_like 'collection attribute' do
22
+ let(:attribute) { 'stats' }
23
+ let(:attribute_class) { ChampionStatistic }
24
+ end
25
+ end
26
+ end
@@ -93,6 +93,119 @@ describe Client do
93
93
  end
94
94
  end
95
95
 
96
+ describe '#stats' do
97
+ it 'defaults to v1.1' do
98
+ expect(subject).to receive(:stats11).with 'foo'
99
+ subject.stats 'foo'
100
+ end
101
+ end
102
+
103
+ describe '#stats11' do
104
+ let(:client) { Client.new 'foo' }
105
+ let(:fixture) { load_fixture 'stats', 'v1.1', 'get' }
106
+
107
+ subject do
108
+ expect(Client).to receive(:get).with(client.api_url('v1.1', "stats/by-summoner/1/summary")).and_return fixture
109
+ client.stats11 1
110
+ end
111
+
112
+ it 'requires a summoner' do
113
+ expect { client.stats }.to raise_error ArgumentError
114
+ end
115
+
116
+ it 'returns an array' do
117
+ expect(subject).to be_a Array
118
+ end
119
+
120
+ it 'returns an array of PlayerStatistic' do
121
+ expect(subject.map(&:class).uniq).to eq [PlayerStatistic]
122
+ end
123
+
124
+ it 'fetches PlayerStatistics from the API' do
125
+ expect(subject.size).to eq load_fixture('stats', 'v1.1', 'get')['playerStatSummaries'].size
126
+ end
127
+
128
+ it 'optionally accepts a season' do
129
+ expect(Client).to receive(:get).with(client.api_url('v1.1', 'stats/by-summoner/1/summary', season: '1')).and_return fixture
130
+ client.stats11 '1', season: '1'
131
+ end
132
+
133
+ it 'raises an error when unexpected parameter is received' do
134
+ expect { client.stats11 '1', asd: 'foo' }.to raise_error ArgumentError
135
+ end
136
+ end
137
+
138
+ describe '#ranked_stats' do
139
+ it 'defaults to v1.1' do
140
+ expect(subject).to receive(:ranked_stats11).with 'foo'
141
+ subject.ranked_stats 'foo'
142
+ end
143
+ end
144
+
145
+ describe '#ranked_stats11' do
146
+ let(:client) { Client.new 'foo' }
147
+ let(:fixture) { load_fixture 'ranked_stats', 'v1.1', 'get' }
148
+
149
+ subject do
150
+ expect(Client).to receive(:get).with(client.api_url('v1.1', "stats/by-summoner/1/ranked")).and_return fixture
151
+ client.ranked_stats11 1
152
+ end
153
+
154
+ it 'requires a summoner' do
155
+ expect { client.ranked_stats }.to raise_error ArgumentError
156
+ end
157
+
158
+ it 'returns a RankedStatisticsSummary' do
159
+ expect(subject).to be_a RankedStatisticsSummary
160
+ end
161
+
162
+ it 'fetches RankedStatisticsSummary from the API' do
163
+ expect(subject.champions.size).to eq load_fixture('ranked_stats', 'v1.1', 'get')['champions'].size
164
+ end
165
+
166
+ it 'optionally accepts a season' do
167
+ expect(Client).to receive(:get).with(client.api_url('v1.1', 'stats/by-summoner/1/ranked', season: '1')).and_return fixture
168
+ client.ranked_stats11 '1', season: '1'
169
+ end
170
+
171
+ it 'raises an error when unexpected parameter is received' do
172
+ expect { client.ranked_stats11 '1', asd: 'foo' }.to raise_error ArgumentError
173
+ end
174
+ end
175
+
176
+ describe '#team' do
177
+ it 'defaults to v2.1' do
178
+ expect(subject).to receive(:team21).with 'foo'
179
+ subject.team 'foo'
180
+ end
181
+ end
182
+
183
+ describe '#team21' do
184
+ let(:client) { Client.new 'foo' }
185
+ let(:fixture) { load_fixture 'team', 'v2.1', 'get' }
186
+
187
+ subject do
188
+ expect(Client).to receive(:get).with(client.api_url('v2.1', "team/by-summoner/1")).and_return fixture
189
+ client.team21 1
190
+ end
191
+
192
+ it 'requires a summoner' do
193
+ expect { client.team21 }.to raise_error ArgumentError
194
+ end
195
+
196
+ it 'returns an array' do
197
+ expect(subject).to be_a Array
198
+ end
199
+
200
+ it 'returns an array of Team' do
201
+ expect(subject.map(&:class).uniq).to eq [Team]
202
+ end
203
+
204
+ it 'fetches Team from the API' do
205
+ expect(subject.size).to eq fixture.size
206
+ end
207
+ end
208
+
96
209
  describe "#region" do
97
210
  it "returns current region" do
98
211
  expect(subject.region).to eq("euw")
@@ -134,6 +247,10 @@ describe Client do
134
247
  it "does not have lol if url is v2.1 or greater" do
135
248
  expect(subject.api_url("v2.1", "foo")).to eq("http://prod.api.pvp.net/api/euw/v2.1/foo?api_key=foo")
136
249
  end
250
+
251
+ it "optionally accept query string parameters" do
252
+ expect(subject.api_url("v2.1", "foo", a: 'b')).to eq("http://prod.api.pvp.net/api/euw/v2.1/foo?a=b&api_key=foo")
253
+ end
137
254
  end
138
255
 
139
256
  describe "league" do
@@ -27,18 +27,13 @@ describe Game do
27
27
  describe 'statistics attribute' do
28
28
  it_behaves_like 'collection attribute' do
29
29
  let(:attribute) { 'statistics' }
30
- let(:attribute_class) { Statistic }
30
+ let(:attribute_class) { RawStatistic }
31
31
  end
32
32
  end
33
33
 
34
34
  describe 'create_date attribute' do
35
- it_behaves_like 'plain attribute' do
35
+ it_behaves_like 'time attribute' do
36
36
  let(:attribute) { 'create_date' }
37
- let(:attribute_value) { DateTime.now }
38
- end
39
-
40
- it "parses the value is it's not a DateTime object" do
41
- expect(Game.new(:create_date => Time.now.to_i).create_date).to be_a DateTime
42
37
  end
43
38
  end
44
39
  end
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+ require "lol"
3
+
4
+ include Lol
5
+
6
+ describe LeagueEntry do
7
+ it "inherits from Lol::Model" do
8
+ expect(League.ancestors[1]).to eq(Model)
9
+ end
10
+
11
+ context "initialization" do
12
+ it_behaves_like 'Lol model' do
13
+ let(:valid_attributes) { { player_or_team_id: 123456 } }
14
+ end
15
+
16
+ %w(player_or_team_id player_or_team_name league_name queue_type tier rank league_points wins losses is_hot_streak is_veteran is_fresh_blood is_inactive last_played time_until_decay).each do |attribute|
17
+ describe "#{attribute} attribute" do
18
+ it_behaves_like 'plain attribute' do
19
+ let(:attribute) { attribute }
20
+ let(:attribute_value) { 'asd' }
21
+ end
22
+ end
23
+ end
24
+
25
+ it "returns a MiniSeries object if a miniseries is available" do
26
+ mini_series =<<-EOF
27
+ {
28
+ "playerOrTeamId" : "30247742",
29
+ "playerOrTeamName" : "Danterno",
30
+ "leagueName" : "Annie's Blades",
31
+ "queueType" : "RANKED_SOLO_5x5",
32
+ "tier" : "SILVER",
33
+ "rank" : "II",
34
+ "leaguePoints" : 84,
35
+ "wins" : 35,
36
+ "losses" : 0,
37
+ "isHotStreak" : false,
38
+ "isVeteran" : false,
39
+ "isFreshBlood" : false,
40
+ "isInactive" : false,
41
+ "lastPlayed" : 0,
42
+ "timeUntilDecay" : -1,
43
+ "miniSeries" : {
44
+ "target" : 2,
45
+ "wins" : 0,
46
+ "losses" : 1,
47
+ "timeLeftToPlayMillis" : 0,
48
+ "progress" : "LNN"
49
+ }
50
+ }
51
+ EOF
52
+ subject = LeagueEntry.new JSON.parse(mini_series)
53
+ expect(subject.mini_series).to be_a(MiniSeries)
54
+ end
55
+ end
56
+ end
@@ -22,6 +22,9 @@ describe League do
22
22
  end
23
23
  end
24
24
 
25
- pending "fills entries with LeagueEntry objects"
25
+ it "fills entries with LeagueEntry objects" do
26
+ league = League.new(load_fixture("league", "v2.1", "get")["foo"])
27
+ expect(league.entries.map(&:class).uniq).to eq([LeagueEntry])
28
+ end
26
29
  end
27
30
  end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+ require "lol"
3
+
4
+ include Lol
5
+
6
+ describe MatchSummary do
7
+ it_behaves_like 'Lol model' do
8
+ let(:valid_attributes) { { win: true } }
9
+ end
10
+
11
+ %w(assists deaths game_id game_mode invalid kills map_id opposing_team_kills opposing_team_name win).each do |attribute|
12
+ describe "#{attribute} attribute" do
13
+ it_behaves_like 'plain attribute' do
14
+ let(:attribute) { attribute }
15
+ let(:attribute_value) { 'asd' }
16
+ end
17
+ end
18
+ end
19
+
20
+ describe "date attribute" do
21
+ it_behaves_like 'time attribute' do
22
+ let(:attribute) { 'date' }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+ require "lol"
3
+
4
+ include Lol
5
+
6
+ describe MiniSeries do
7
+ it "inherits from Lol::Model" do
8
+ expect(MiniSeries.ancestors[1]).to eq(Model)
9
+ end
10
+
11
+ context "initialization" do
12
+ it_behaves_like 'Lol model' do
13
+ let(:valid_attributes) { { target: 3 } }
14
+ end
15
+
16
+ %w(target wins losses time_left_to_play_millis progress).each do |attribute|
17
+ describe "#{attribute} attribute" do
18
+ it_behaves_like 'plain attribute' do
19
+ let(:attribute) { attribute }
20
+ let(:attribute_value) { 'asd' }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+ require "lol"
3
+
4
+ include Lol
5
+
6
+ describe PlayerStatistic do
7
+ it_behaves_like 'Lol model' do
8
+ let(:valid_attributes) { { wins: 1 } }
9
+ end
10
+
11
+ %w(losses modify_date_str player_stat_summary_type wins).each do |attribute|
12
+ describe "#{attribute} attribute" do
13
+ it_behaves_like 'plain attribute' do
14
+ let(:attribute) { attribute }
15
+ let(:attribute_value) { 'asd' }
16
+ end
17
+ end
18
+ end
19
+
20
+ describe 'aggregated_stats attribute' do
21
+ it_behaves_like 'collection attribute' do
22
+ let(:attribute) { 'aggregated_stats' }
23
+ let(:attribute_class) { AggregatedStatistic }
24
+ end
25
+ end
26
+
27
+ describe 'modify_date attribute' do
28
+ it_behaves_like 'time attribute' do
29
+ let(:attribute) { 'modify_date' }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+ require "lol"
3
+
4
+ include Lol
5
+
6
+ describe RankedStatisticsSummary do
7
+ it_behaves_like 'Lol model' do
8
+ let(:valid_attributes) { { summoner_id: 1 } }
9
+ end
10
+
11
+ %w(summoner_id modify_date_str).each do |attribute|
12
+ describe "#{attribute} attribute" do
13
+ it_behaves_like 'plain attribute' do
14
+ let(:attribute) { attribute }
15
+ let(:attribute_value) { 'asd' }
16
+ end
17
+ end
18
+ end
19
+
20
+ describe 'champions attribute' do
21
+ it_behaves_like 'collection attribute' do
22
+ let(:attribute) { 'champions' }
23
+ let(:attribute_class) { ChampionStatisticsSummary }
24
+ end
25
+ end
26
+
27
+ describe 'modify_date attribute' do
28
+ it_behaves_like 'time attribute' do
29
+ let(:attribute) { 'modify_date' }
30
+ end
31
+ end
32
+ end
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
 
4
4
  include Lol
5
5
 
6
- describe Statistic do
6
+ describe RawStatistic do
7
7
  it_behaves_like 'Lol model' do
8
8
  let(:valid_attributes) { { id: 1 } }
9
9
  end
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+ require "lol"
3
+
4
+ include Lol
5
+
6
+ describe Roster do
7
+ it_behaves_like 'Lol model' do
8
+ let(:valid_attributes) { { owner_id: 1 } }
9
+ end
10
+
11
+ describe "owner_id attribute" do
12
+ it_behaves_like 'plain attribute' do
13
+ let(:attribute) { 'owner_id' }
14
+ let(:attribute_value) { 'asd' }
15
+ end
16
+ end
17
+
18
+ describe 'member_list attribute' do
19
+ it_behaves_like 'collection attribute' do
20
+ let(:attribute) { 'member_list' }
21
+ let(:attribute_class) { TeamMember }
22
+ end
23
+ end
24
+ end