ruby-lol 0.9.19.1 → 0.10.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.
@@ -161,6 +161,38 @@ describe Client do
161
161
  end
162
162
  end
163
163
 
164
+ describe '#current_game' do
165
+ it 'returns an instance of CurrentGameRequest' do
166
+ expect(subject.current_game).to be_a CurrentGameRequest
167
+ end
168
+
169
+ it 'initializes CurrentGameRequest with the current API key an region' do
170
+ expect(CurrentGameRequest).to receive(:new).with subject.api_key, subject.region, subject.cache_store
171
+ subject.current_game
172
+ end
173
+
174
+ it 'memoizes the result' do
175
+ expect(CurrentGameRequest).to receive(:new).and_return(double).exactly(:once)
176
+ 2.times { subject.current_game }
177
+ end
178
+ end
179
+
180
+ describe '#featured_games' do
181
+ it 'returns an instance of FeaturedGamesRequest' do
182
+ expect(subject.featured_games).to be_a FeaturedGamesRequest
183
+ end
184
+
185
+ it 'initializes FeaturedGamesRequest with the current API key an region' do
186
+ expect(FeaturedGamesRequest).to receive(:new).with subject.api_key, subject.region, subject.cache_store
187
+ subject.featured_games
188
+ end
189
+
190
+ it 'memoizes the result' do
191
+ expect(FeaturedGamesRequest).to receive(:new).and_return(double).exactly(:once)
192
+ 2.times { subject.featured_games }
193
+ end
194
+ end
195
+
164
196
  describe "#api_key" do
165
197
  it "returns an api key" do
166
198
  expect(subject.api_key).to eq("foo")
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ require 'lol'
3
+
4
+ describe Lol::CurrentGameRequest do
5
+ subject { Lol::CurrentGameRequest.new 'api_key', 'euw' }
6
+
7
+ it 'inherits from Lol::Request' do
8
+ expect(subject.class.ancestors[1]).to eq Lol::Request
9
+ end
10
+
11
+ describe '#api_url' do
12
+ it 'returns base_url joined with the given path and the api query string' do
13
+ expect(subject.api_url 'foo').to eq "https://euw.api.pvp.net/observer-mode/rest/consumer/foo?api_key=api_key"
14
+ end
15
+
16
+ it 'delegates to api_base_url' do
17
+ allow(subject).to receive(:api_base_url).and_return 'bar'
18
+ expect(subject.api_url 'foo').to match /^bar\/observer-mode\/rest\/consumer\/foo/
19
+ end
20
+
21
+ it 'delegates to api_query_string' do
22
+ allow(subject).to receive(:api_query_string).with(a: 'a').and_return 'baz'
23
+ expect(subject.api_url 'foo', a: 'a').to match /foo\?baz$/
24
+ end
25
+ end
26
+
27
+ describe '#spectator_game_info' do
28
+ let(:expected_url) { 'getSpectatorGameInfo/EUW1/1' }
29
+
30
+ it 'requires platform and summoner id' do
31
+ expect {
32
+ subject.spectator_game_info
33
+ }.to raise_error ArgumentError, /\(0 for 2\)/
34
+ end
35
+
36
+ it 'returns a DynamicModel' do
37
+ stub_request subject, 'current-game', expected_url
38
+ expect(subject.spectator_game_info 1, '1').to be_a DynamicModel
39
+ end
40
+
41
+ it 'gives the response to DynamicModel' do
42
+ allow(subject).to receive(:perform_request).with(instance_of(String)).and_return 'a'
43
+ expect(Lol::DynamicModel).to receive(:new).with('a').and_return 'foo'
44
+ subject.spectator_game_info 1, '1'
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'lol'
3
+
4
+ describe Lol::FeaturedGamesRequest do
5
+ subject { Lol::FeaturedGamesRequest.new 'api_key', 'euw' }
6
+
7
+ it 'inherits from Lol::Request' do
8
+ expect(subject.class.ancestors[1]).to eq Lol::Request
9
+ end
10
+
11
+ describe '#api_url' do
12
+ it 'returns base_url joined with the given path and the api query string' do
13
+ expect(subject.api_url 'foo').to eq "https://euw.api.pvp.net/observer-mode/rest/foo?api_key=api_key"
14
+ end
15
+
16
+ it 'delegates to api_base_url' do
17
+ allow(subject).to receive(:api_base_url).and_return 'bar'
18
+ expect(subject.api_url 'foo').to match /^bar\/observer-mode\/rest\/foo/
19
+ end
20
+
21
+ it 'delegates to api_query_string' do
22
+ allow(subject).to receive(:api_query_string).with(a: 'a').and_return 'baz'
23
+ expect(subject.api_url 'foo', a: 'a').to match /foo\?baz$/
24
+ end
25
+ end
26
+
27
+ describe '#get' do
28
+ it 'returns a dynamic model' do
29
+ stub_request subject, 'featured-games', 'featured'
30
+ expect(subject.get).to be_a Lol::DynamicModel
31
+ end
32
+
33
+ it 'gives the response to DynamicModel' do
34
+ allow(subject).to receive(:perform_request).with(instance_of(String)).and_return 'a'
35
+ expect(Lol::DynamicModel).to receive(:new).with('a').and_return 'foo'
36
+ subject.get
37
+ end
38
+ end
39
+ end
@@ -99,25 +99,51 @@ describe Request do
99
99
  end
100
100
  end
101
101
 
102
- describe "api_url" do
103
- it "defaults on Request#region" do
104
- expect(subject.api_url("bar")).to match(/\/euw\//)
105
- end
102
+ describe "api_url" do
103
+ it "defaults on Request#region" do
104
+ expect(subject.api_url("bar")).to match(/\/euw\//)
105
+ end
106
106
 
107
- it "defaults on Reques.api_version" do
108
- expect(subject.api_url("bar")).to match(/\/v1.1\//)
109
- end
107
+ it "defaults on Reques.api_version" do
108
+ expect(subject.api_url("bar")).to match(/\/v1.1\//)
109
+ end
110
110
 
111
- it "a path" do
112
- expect { subject.api_url }.to raise_error(ArgumentError)
113
- end
111
+ it "a path" do
112
+ expect { subject.api_url }.to raise_error(ArgumentError)
113
+ end
114
114
 
115
- it "returns a full fledged api url" do
116
- expect(subject.api_url("bar")).to eq("https://euw.api.pvp.net/api/lol/euw/v1.1/bar?api_key=api_key")
117
- end
115
+ it "returns a full fledged api url" do
116
+ expect(subject.api_url("bar")).to eq("https://euw.api.pvp.net/api/lol/euw/v1.1/bar?api_key=api_key")
117
+ end
118
118
 
119
- it "optionally accept query string parameters" do
120
- expect(subject.api_url("foo", a: 'b')).to eq("https://euw.api.pvp.net/api/lol/euw/v1.1/foo?a=b&api_key=api_key")
121
- end
119
+ it "optionally accept query string parameters" do
120
+ expect(subject.api_url("foo", a: 'b')).to eq("https://euw.api.pvp.net/api/lol/euw/v1.1/foo?a=b&api_key=api_key")
121
+ end
122
+
123
+ it "delegates the base url to #api_base_url" do
124
+ allow(subject).to receive(:api_base_url).and_return 'foo'
125
+ expect(subject.api_url 'bar').to match /^foo/
126
+ end
127
+
128
+ it "delegates the query string to #api_query_string" do
129
+ allow(subject).to receive(:api_query_string).and_return 'foo'
130
+ expect(subject.api_url 'bar').to match /\?foo$/
131
+ end
132
+ end
133
+
134
+ describe "#api_base_url" do
135
+ it "returns the base domain" do
136
+ expect(subject.api_base_url).to eq "https://euw.api.pvp.net"
137
+ end
138
+ end
139
+
140
+ describe "#api_query_string" do
141
+ it "returns the api key as query string" do
142
+ expect(subject.api_query_string).to eq "api_key=api_key"
143
+ end
144
+
145
+ it "optionally accept other params" do
146
+ expect(subject.api_query_string foo: 'bar').to eq "foo=bar&api_key=api_key"
122
147
  end
123
148
  end
149
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.19.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Intini
@@ -278,7 +278,9 @@ files:
278
278
  - lib/lol/champion_request.rb
279
279
  - lib/lol/champion_statistics_summary.rb
280
280
  - lib/lol/client.rb
281
+ - lib/lol/current_game_request.rb
281
282
  - lib/lol/dynamic_model.rb
283
+ - lib/lol/featured_games_request.rb
282
284
  - lib/lol/game.rb
283
285
  - lib/lol/game_request.rb
284
286
  - lib/lol/invalid_api_response.rb
@@ -312,6 +314,8 @@ files:
312
314
  - ruby-lol.gemspec
313
315
  - spec/acceptance_spec.rb
314
316
  - spec/api_version_spec.rb
317
+ - spec/fixtures/v1.0/get-current-game.json
318
+ - spec/fixtures/v1.0/get-featured-games.json
315
319
  - spec/fixtures/v1.0/get-lol-status-shard-by-region.json
316
320
  - spec/fixtures/v1.0/get-lol-status-shards.json
317
321
  - spec/fixtures/v1.2/get-champion-266.json
@@ -348,7 +352,9 @@ files:
348
352
  - spec/lol/champion_spec.rb
349
353
  - spec/lol/champion_statistics_summary_spec.rb
350
354
  - spec/lol/client_spec.rb
355
+ - spec/lol/current_game_request_spec.rb
351
356
  - spec/lol/dynamic_model_spec.rb
357
+ - spec/lol/featured_games_request_spec.rb
352
358
  - spec/lol/game_request_spec.rb
353
359
  - spec/lol/game_spec.rb
354
360
  - spec/lol/invalid_api_response_spec.rb
@@ -408,6 +414,8 @@ summary: Ruby wrapper to Riot Games API
408
414
  test_files:
409
415
  - spec/acceptance_spec.rb
410
416
  - spec/api_version_spec.rb
417
+ - spec/fixtures/v1.0/get-current-game.json
418
+ - spec/fixtures/v1.0/get-featured-games.json
411
419
  - spec/fixtures/v1.0/get-lol-status-shard-by-region.json
412
420
  - spec/fixtures/v1.0/get-lol-status-shards.json
413
421
  - spec/fixtures/v1.2/get-champion-266.json
@@ -444,7 +452,9 @@ test_files:
444
452
  - spec/lol/champion_spec.rb
445
453
  - spec/lol/champion_statistics_summary_spec.rb
446
454
  - spec/lol/client_spec.rb
455
+ - spec/lol/current_game_request_spec.rb
447
456
  - spec/lol/dynamic_model_spec.rb
457
+ - spec/lol/featured_games_request_spec.rb
448
458
  - spec/lol/game_request_spec.rb
449
459
  - spec/lol/game_spec.rb
450
460
  - spec/lol/invalid_api_response_spec.rb