ruby-lol 0.9.1 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,7 @@ describe ChampionRequest do
12
12
  let(:request) { ChampionRequest.new "api_key", "euw" }
13
13
 
14
14
  subject do
15
- expect(request).to receive(:perform_request).with(request.api_url("v1.1", "champion")).and_return(load_fixture("champion", "v1.1", "get"))
15
+ expect(request).to receive(:perform_request).with(request.api_url("champion")).and_return(load_fixture("champion", ChampionRequest.api_version, "get"))
16
16
 
17
17
  request.get
18
18
  end
@@ -26,7 +26,7 @@ describe ChampionRequest do
26
26
  end
27
27
 
28
28
  it "fetches champions from the API" do
29
- expect(subject.size).to eq(load_fixture("champion", "v1.1", "get")["champions"].size)
29
+ expect(subject.size).to eq(load_fixture("champion", ChampionRequest.api_version, "get")["champions"].size)
30
30
  end
31
31
  end
32
32
  end
@@ -18,9 +18,21 @@ describe ChampionStatisticsSummary do
18
18
  end
19
19
 
20
20
  describe 'stats attribute' do
21
- it_behaves_like 'collection attribute' do
21
+ it_behaves_like 'plain attribute' do
22
22
  let(:attribute) { 'stats' }
23
- let(:attribute_class) { ChampionStatistic }
23
+ let(:attribute_value) { 'asd' }
24
+ end
25
+
26
+ context 'when is passed as an hash' do
27
+ subject { ChampionStatisticsSummary.new stats: { 'FooBar' => 'baz' } }
28
+
29
+ it 'will convert the hash in an openstruct object' do
30
+ expect(subject.stats).to be_a OpenStruct
31
+ end
32
+
33
+ it 'will convert each hash key in underscore' do
34
+ expect(subject.stats.foo_bar).to eq 'baz'
35
+ end
24
36
  end
25
37
  end
26
38
  end
@@ -12,7 +12,7 @@ describe GameRequest do
12
12
  let(:request) { GameRequest.new "api_key", "euw" }
13
13
 
14
14
  subject do
15
- expect(request.class).to receive(:get).with(request.api_url('v1.2', "game/by-summoner/1/recent")).and_return load_fixture('game', 'v1.2', 'get')
15
+ expect(request.class).to receive(:get).with(request.api_url("game/by-summoner/1/recent")).and_return load_fixture('game', GameRequest.api_version, 'get')
16
16
 
17
17
  request.recent 1
18
18
  end
@@ -26,7 +26,7 @@ describe GameRequest do
26
26
  end
27
27
 
28
28
  it 'fetches games from the API' do
29
- expect(subject.size).to eq load_fixture('game', 'v1.1', 'get')['games'].size
29
+ expect(subject.size).to eq load_fixture('game', GameRequest.api_version, 'get')['games'].size
30
30
  end
31
31
  end
32
32
 
@@ -13,7 +13,7 @@ describe LeagueEntry do
13
13
  let(:valid_attributes) { { player_or_team_id: 123456 } }
14
14
  end
15
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|
16
+ %w(player_or_team_id player_or_team_name league_name queue_type tier rank league_points wins is_hot_streak is_veteran is_fresh_blood is_inactive last_played time_until_decay).each do |attribute|
17
17
  describe "#{attribute} attribute" do
18
18
  it_behaves_like 'plain attribute' do
19
19
  let(:attribute) { attribute }
@@ -33,7 +33,6 @@ describe LeagueEntry do
33
33
  "rank" : "II",
34
34
  "leaguePoints" : 84,
35
35
  "wins" : 35,
36
- "losses" : 0,
37
36
  "isHotStreak" : false,
38
37
  "isVeteran" : false,
39
38
  "isFreshBlood" : false,
@@ -12,7 +12,7 @@ describe LeagueRequest do
12
12
  let(:request) { LeagueRequest.new "api_key", "euw" }
13
13
 
14
14
  subject do
15
- expect(request.class).to receive(:get).with(request.api_url("v2.1", "league/by-summoner/123")).and_return(load_fixture("league", "v2.1", "get"))
15
+ expect(request.class).to receive(:get).with(request.api_url("league/by-summoner/123")).and_return(load_fixture("league", LeagueRequest.api_version, "get"))
16
16
 
17
17
  request.get(123)
18
18
  end
@@ -10,10 +10,10 @@ describe League do
10
10
 
11
11
  context "initialization" do
12
12
  it_behaves_like 'Lol model' do
13
- let(:valid_attributes) { { timestamp: 123456 } }
13
+ let(:valid_attributes) { { name: 'foo' } }
14
14
  end
15
15
 
16
- %w(timestamp name tier queue).each do |attribute|
16
+ %w(name tier queue).each do |attribute|
17
17
  describe "#{attribute} attribute" do
18
18
  it_behaves_like 'plain attribute' do
19
19
  let(:attribute) { attribute }
@@ -23,7 +23,7 @@ describe League do
23
23
  end
24
24
 
25
25
  it "fills entries with LeagueEntry objects" do
26
- league = League.new(load_fixture("league", "v2.1", "get")["123"])
26
+ league = League.new(load_fixture("league", "v2.2", "get")["123"])
27
27
  expect(league.entries.map(&:class).uniq).to eq([LeagueEntry])
28
28
  end
29
29
  end
@@ -8,7 +8,7 @@ describe PlayerStatistic do
8
8
  let(:valid_attributes) { { wins: 1 } }
9
9
  end
10
10
 
11
- %w(losses modify_date_str player_stat_summary_type wins).each do |attribute|
11
+ %w(aggregated_stats losses modify_date_str player_stat_summary_type wins).each do |attribute|
12
12
  describe "#{attribute} attribute" do
13
13
  it_behaves_like 'plain attribute' do
14
14
  let(:attribute) { attribute }
@@ -18,9 +18,21 @@ describe PlayerStatistic do
18
18
  end
19
19
 
20
20
  describe 'aggregated_stats attribute' do
21
- it_behaves_like 'collection attribute' do
21
+ it_behaves_like 'plain attribute' do
22
22
  let(:attribute) { 'aggregated_stats' }
23
- let(:attribute_class) { AggregatedStatistic }
23
+ let(:attribute_value) { 'asd' }
24
+ end
25
+
26
+ context 'when is passed as an hash' do
27
+ subject { PlayerStatistic.new aggregated_stats: { 'FooBar' => 'baz' } }
28
+
29
+ it 'will convert the hash in an openstruct object' do
30
+ expect(subject.aggregated_stats).to be_a OpenStruct
31
+ end
32
+
33
+ it 'will convert each hash key in underscore' do
34
+ expect(subject.aggregated_stats.foo_bar).to eq 'baz'
35
+ end
24
36
  end
25
37
  end
26
38
 
@@ -44,27 +44,32 @@ describe Request do
44
44
 
45
45
  describe "api_url" do
46
46
  it "defaults on Request#region" do
47
- expect(subject.api_url("foo", "bar")).to match(/\/euw\//)
47
+ expect(subject.api_url("bar")).to match(/\/euw\//)
48
48
  end
49
49
 
50
- it "requires an api_key a version and a path" do
51
- expect { subject.api_url "foo" }.to raise_error(ArgumentError)
50
+ it "defaults on Reques.api_version" do
51
+ expect(subject.api_url("bar")).to match(/\/v1.1\//)
52
+ end
53
+
54
+ it "a path" do
55
+ expect { subject.api_url }.to raise_error(ArgumentError)
52
56
  end
53
57
 
54
58
  it "returns a full fledged api url" do
55
- expect(subject.api_url("foo", "bar")).to eq("http://prod.api.pvp.net/api/lol/euw/foo/bar?api_key=api_key")
59
+ expect(subject.api_url("bar")).to eq("http://prod.api.pvp.net/api/lol/euw/v1.1/bar?api_key=api_key")
56
60
  end
57
61
 
58
62
  it "has lol if url is different from v2.1" do
59
- expect(subject.api_url("v1.2", "foo")).to eq("http://prod.api.pvp.net/api/lol/euw/v1.2/foo?api_key=api_key")
63
+ expect(subject.api_url("foo")).to eq("http://prod.api.pvp.net/api/lol/euw/v1.1/foo?api_key=api_key")
60
64
  end
61
65
 
62
66
  it "does not have lol only url is v2.1" do
63
- expect(subject.api_url("v2.1", "foo")).to eq("http://prod.api.pvp.net/api/euw/v2.1/foo?api_key=api_key")
67
+ expect(Request).to receive(:api_version).at_least(:once).and_return("v2.1")
68
+ expect(subject.api_url("foo")).to eq("http://prod.api.pvp.net/api/euw/v2.1/foo?api_key=api_key")
64
69
  end
65
70
 
66
71
  it "optionally accept query string parameters" do
67
- 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=api_key")
72
+ expect(subject.api_url("foo", a: 'b')).to eq("http://prod.api.pvp.net/api/lol/euw/v1.1/foo?a=b&api_key=api_key")
68
73
  end
69
74
  end
70
75
  end
@@ -11,10 +11,10 @@ describe StatsRequest do
11
11
  end
12
12
 
13
13
  describe "#summary" do
14
- let(:fixture) { load_fixture 'stats', 'v1.1', 'get' }
14
+ let(:fixture) { load_fixture 'stats', StatsRequest.api_version, 'get' }
15
15
 
16
16
  subject do
17
- expect(request.class).to receive(:get).with(request.api_url('v1.1', "stats/by-summoner/1/summary")).and_return fixture
17
+ expect(request.class).to receive(:get).with(request.api_url("stats/by-summoner/1/summary")).and_return fixture
18
18
 
19
19
  request.summary 1
20
20
  end
@@ -32,11 +32,11 @@ describe StatsRequest do
32
32
  end
33
33
 
34
34
  it 'fetches PlayerStatistics from the API' do
35
- expect(subject.size).to eq load_fixture('stats', 'v1.1', 'get')['playerStatSummaries'].size
35
+ expect(subject.size).to eq load_fixture('stats', StatsRequest.api_version, 'get')['playerStatSummaries'].size
36
36
  end
37
37
 
38
38
  it 'optionally accepts a season' do
39
- expect(request.class).to receive(:get).with(request.api_url('v1.1', 'stats/by-summoner/1/summary', season: '1')).and_return fixture
39
+ expect(request.class).to receive(:get).with(request.api_url('stats/by-summoner/1/summary', season: '1')).and_return fixture
40
40
  request.summary '1', season: '1'
41
41
  end
42
42
 
@@ -46,10 +46,10 @@ describe StatsRequest do
46
46
  end
47
47
 
48
48
  describe "#ranked" do
49
- let(:fixture) { load_fixture 'ranked_stats', 'v1.1', 'get' }
49
+ let(:fixture) { load_fixture 'ranked_stats', StatsRequest.api_version, 'get' }
50
50
 
51
51
  subject do
52
- expect(request.class).to receive(:get).with(request.api_url('v1.1', "stats/by-summoner/1/ranked")).and_return fixture
52
+ expect(request.class).to receive(:get).with(request.api_url("stats/by-summoner/1/ranked")).and_return fixture
53
53
  request.ranked 1
54
54
  end
55
55
 
@@ -62,11 +62,11 @@ describe StatsRequest do
62
62
  end
63
63
 
64
64
  it 'fetches RankedStatisticsSummary from the API' do
65
- expect(subject.champions.size).to eq load_fixture('ranked_stats', 'v1.1', 'get')['champions'].size
65
+ expect(subject.champions.size).to eq load_fixture('ranked_stats', StatsRequest.api_version, 'get')['champions'].size
66
66
  end
67
67
 
68
68
  it 'optionally accepts a season' do
69
- expect(request.class).to receive(:get).with(request.api_url('v1.1', 'stats/by-summoner/1/ranked', season: '1')).and_return fixture
69
+ expect(request.class).to receive(:get).with(request.api_url('stats/by-summoner/1/ranked', season: '1')).and_return fixture
70
70
 
71
71
  request.ranked '1', season: '1'
72
72
  end
@@ -9,15 +9,15 @@ describe SummonerRequest do
9
9
  end
10
10
 
11
11
  let(:request) { SummonerRequest.new "api_key", "euw" }
12
- let(:by_name) { load_fixture("summoner-by-name", "v1.1", "get") }
13
- let(:name) { load_fixture("summoner-name", "v1.1", "get") }
14
- let(:summoner) { load_fixture("summoner", "v1.1", "get") }
15
- let(:runes) { load_fixture("summoner-runes", "v1.1", "get") }
16
- let(:masteries) { load_fixture("summoner-masteries", "v1.1", "get") }
12
+ let(:by_name) { load_fixture("summoner-by-name", SummonerRequest.api_version, "get") }
13
+ let(:name) { load_fixture("summoner-name", SummonerRequest.api_version, "get") }
14
+ let(:summoner) { load_fixture("summoner", SummonerRequest.api_version, "get") }
15
+ let(:runes) { load_fixture("summoner-runes", SummonerRequest.api_version, "get") }
16
+ let(:masteries) { load_fixture("summoner-masteries", SummonerRequest.api_version, "get") }
17
17
 
18
18
  describe "#by_name" do
19
19
  subject do
20
- expect(request.class).to receive(:get).with(request.api_url("v1.1", "summoner/by-name/foo")).and_return(by_name)
20
+ expect(request.class).to receive(:get).with(request.api_url("summoner/by-name/foo")).and_return(by_name)
21
21
 
22
22
  request.by_name "foo"
23
23
  end
@@ -29,7 +29,7 @@ describe SummonerRequest do
29
29
 
30
30
  describe "#name" do
31
31
  subject do
32
- expect(request.class).to receive(:get).with(request.api_url("v1.1", "summoner/foo,bar/name")).and_return(name)
32
+ expect(request.class).to receive(:get).with(request.api_url("summoner/foo,bar/name")).and_return(name)
33
33
 
34
34
  request.name "foo", "bar"
35
35
  end
@@ -41,7 +41,7 @@ describe SummonerRequest do
41
41
 
42
42
  describe "#get" do
43
43
  subject do
44
- expect(request.class).to receive(:get).with(request.api_url("v1.1", "summoner/foo")).and_return(summoner)
44
+ expect(request.class).to receive(:get).with(request.api_url("summoner/foo")).and_return(summoner)
45
45
 
46
46
  request.get "foo"
47
47
  end
@@ -53,7 +53,7 @@ describe SummonerRequest do
53
53
 
54
54
  describe "#runes" do
55
55
  subject do
56
- expect(request.class).to receive(:get).with(request.api_url("v1.1", "summoner/foo/runes")).and_return(runes)
56
+ expect(request.class).to receive(:get).with(request.api_url("summoner/foo/runes")).and_return(runes)
57
57
 
58
58
  request.runes "foo"
59
59
  end
@@ -65,7 +65,7 @@ describe SummonerRequest do
65
65
 
66
66
  describe "#masteries" do
67
67
  subject do
68
- expect(request.class).to receive(:get).with(request.api_url("v1.1", "summoner/foo/masteries")).and_return(masteries)
68
+ expect(request.class).to receive(:get).with(request.api_url("summoner/foo/masteries")).and_return(masteries)
69
69
 
70
70
  request.masteries "foo"
71
71
  end
@@ -12,10 +12,10 @@ describe TeamRequest do
12
12
 
13
13
  describe "get" do
14
14
  let(:request) { TeamRequest.new "api_key", "euw" }
15
- let(:fixture) { load_fixture 'team', 'v2.1', 'get' }
15
+ let(:fixture) { load_fixture 'team', TeamRequest.api_version, 'get' }
16
16
 
17
17
  subject do
18
- expect(request.class).to receive(:get).with(request.api_url('v2.1', "team/by-summoner/1")).and_return fixture
18
+ expect(request.class).to receive(:get).with(request.api_url("team/by-summoner/1")).and_return fixture
19
19
  request.get 1
20
20
  end
21
21
 
@@ -53,6 +53,6 @@ def summoners
53
53
  end
54
54
 
55
55
  RSpec.configure do |c|
56
- c.fail_fast = true
56
+ # c.fail_fast = true
57
57
  c.filter_run_excluding :remote => true
58
58
  end
@@ -110,4 +110,4 @@ shared_examples 'collection attribute' do
110
110
  end
111
111
  end
112
112
  end
113
- end
113
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Intini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-24 00:00:00.000000000 Z
11
+ date: 2013-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -241,12 +241,11 @@ files:
241
241
  - LICENSE.txt
242
242
  - README.md
243
243
  - Rakefile
244
+ - TODO.md
244
245
  - demo/demo.rb
245
246
  - lib/lol.rb
246
- - lib/lol/aggregated_statistic.rb
247
247
  - lib/lol/champion.rb
248
248
  - lib/lol/champion_request.rb
249
- - lib/lol/champion_statistic.rb
250
249
  - lib/lol/champion_statistics_summary.rb
251
250
  - lib/lol/client.rb
252
251
  - lib/lol/game.rb
@@ -278,6 +277,7 @@ files:
278
277
  - lib/lol/version.rb
279
278
  - ruby-lol.gemspec
280
279
  - spec/acceptance_spec.rb
280
+ - spec/api_version_spec.rb
281
281
  - spec/fixtures/v1.1/get-champion.json
282
282
  - spec/fixtures/v1.1/get-game.json
283
283
  - spec/fixtures/v1.1/get-ranked_stats.json
@@ -288,12 +288,13 @@ files:
288
288
  - spec/fixtures/v1.1/get-summoner-runes.json
289
289
  - spec/fixtures/v1.1/get-summoner.json
290
290
  - spec/fixtures/v1.2/get-game.json
291
+ - spec/fixtures/v1.2/get-ranked_stats.json
292
+ - spec/fixtures/v1.2/get-stats.json
291
293
  - spec/fixtures/v2.1/get-league.json
292
294
  - spec/fixtures/v2.1/get-team.json
293
- - spec/lol/aggregated_statistic_spec.rb
295
+ - spec/fixtures/v2.2/get-league.json
294
296
  - spec/lol/champion_request_spec.rb
295
297
  - spec/lol/champion_spec.rb
296
- - spec/lol/champion_statistic_spec.rb
297
298
  - spec/lol/champion_statistics_summary_spec.rb
298
299
  - spec/lol/client_spec.rb
299
300
  - spec/lol/game_request_spec.rb
@@ -349,6 +350,7 @@ specification_version: 4
349
350
  summary: Ruby wrapper to Riot Games API
350
351
  test_files:
351
352
  - spec/acceptance_spec.rb
353
+ - spec/api_version_spec.rb
352
354
  - spec/fixtures/v1.1/get-champion.json
353
355
  - spec/fixtures/v1.1/get-game.json
354
356
  - spec/fixtures/v1.1/get-ranked_stats.json
@@ -359,12 +361,13 @@ test_files:
359
361
  - spec/fixtures/v1.1/get-summoner-runes.json
360
362
  - spec/fixtures/v1.1/get-summoner.json
361
363
  - spec/fixtures/v1.2/get-game.json
364
+ - spec/fixtures/v1.2/get-ranked_stats.json
365
+ - spec/fixtures/v1.2/get-stats.json
362
366
  - spec/fixtures/v2.1/get-league.json
363
367
  - spec/fixtures/v2.1/get-team.json
364
- - spec/lol/aggregated_statistic_spec.rb
368
+ - spec/fixtures/v2.2/get-league.json
365
369
  - spec/lol/champion_request_spec.rb
366
370
  - spec/lol/champion_spec.rb
367
- - spec/lol/champion_statistic_spec.rb
368
371
  - spec/lol/champion_statistics_summary_spec.rb
369
372
  - spec/lol/client_spec.rb
370
373
  - spec/lol/game_request_spec.rb
@@ -1,21 +0,0 @@
1
- require 'lol/model'
2
-
3
- module Lol
4
- class AggregatedStatistic < Lol::Model
5
- # @!attribute [r] id
6
- # @return [Fixnum] Statistic Type Id
7
- attr_reader :id
8
-
9
- # @!attribute [r] name
10
- # @return [String] Statistic Type name
11
- attr_reader :name
12
-
13
- # @!attribute [r] count
14
- # @return [Fixnum] Statistic value
15
- attr_reader :count
16
-
17
- private
18
-
19
- attr_writer :id, :name, :count
20
- end
21
- end
@@ -1,25 +0,0 @@
1
- require 'lol/model'
2
-
3
- module Lol
4
- class ChampionStatistic < Lol::Model
5
- # @!attribute [r] c
6
- # @return [Fixnum] Count of samples (games) that make up the aggregated value, where relevant.
7
- attr_reader :c
8
-
9
- # @!attribute [r] id
10
- # @return [Fixnum] Aggregated stat type Id
11
- attr_reader :id
12
-
13
- # @!attribute [r] name
14
- # @return [String] Aggregated stat type Name
15
- attr_reader :name
16
-
17
- # @!attribute [r] value
18
- # @return [Fixnum] Aggregated stat type Value
19
- attr_reader :value
20
-
21
- private
22
-
23
- attr_writer :id, :name, :c, :value
24
- end
25
- end