ruby-lol 0.12.2 → 1.0.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 (167) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +16 -0
  3. data/.gitignore +2 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +1157 -0
  6. data/.travis.yml +1 -1
  7. data/lib/lol/champion_mastery_request.rb +29 -57
  8. data/lib/lol/champion_request.rb +19 -23
  9. data/lib/lol/client.rb +16 -21
  10. data/lib/lol/dynamic_model.rb +14 -5
  11. data/lib/lol/featured_game_list.rb +15 -0
  12. data/lib/lol/league_request.rb +28 -49
  13. data/lib/lol/lol_status_request.rb +9 -26
  14. data/lib/lol/masteries_request.rb +14 -0
  15. data/lib/lol/match_request.rb +51 -9
  16. data/lib/lol/request.rb +55 -21
  17. data/lib/lol/runes_request.rb +14 -0
  18. data/lib/lol/spectator_request.rb +24 -0
  19. data/lib/lol/static_request.rb +34 -23
  20. data/lib/lol/summoner_request.rb +22 -51
  21. data/lib/lol/tournament_request.rb +95 -0
  22. data/lib/lol/version.rb +1 -1
  23. data/ruby-lol.gemspec +1 -1
  24. data/spec/api_version_spec.rb +10 -9
  25. data/spec/fixtures/{v1.2 → v3}/get-champion-266.json +0 -0
  26. data/spec/fixtures/{v1.2/get-champion.json → v3/get-champion-all.json} +0 -0
  27. data/spec/fixtures/{v1.0/get-champion-mastery-champions.json → v3/get-champion-masteries.json} +0 -0
  28. data/spec/fixtures/{v1.0/get-champion-mastery-champion.json → v3/get-champion-mastery.json} +0 -0
  29. data/spec/fixtures/v3/get-current-game.json +1 -0
  30. data/spec/fixtures/v3/get-featured-games.json +1 -0
  31. data/spec/fixtures/v3/get-ids-by-tc.json +1 -0
  32. data/spec/fixtures/v3/get-league-challenger.json +1 -0
  33. data/spec/fixtures/v3/get-league-master.json +1 -0
  34. data/spec/fixtures/v3/get-league-positions.json +1 -0
  35. data/spec/fixtures/v3/get-league-summoner.json +1 -0
  36. data/spec/fixtures/v3/get-lol-status-shard.json +1 -0
  37. data/spec/fixtures/v3/get-masteries.json +1 -0
  38. data/spec/fixtures/v3/get-match-with-tc.json +1 -0
  39. data/spec/fixtures/v3/get-match.json +1 -0
  40. data/spec/fixtures/v3/get-matches-recent.json +1 -0
  41. data/spec/fixtures/v3/get-matches.json +1 -0
  42. data/spec/fixtures/v3/get-runes.json +1 -0
  43. data/spec/fixtures/v3/get-static-champions-by-id.json +1 -0
  44. data/spec/fixtures/v3/get-static-champions.json +1 -0
  45. data/spec/fixtures/v3/get-static-items-by-id.json +1 -0
  46. data/spec/fixtures/v3/get-static-items.json +1 -0
  47. data/spec/fixtures/v3/get-static-maps.json +1 -0
  48. data/spec/fixtures/v3/get-static-masteries-by-id.json +1 -0
  49. data/spec/fixtures/v3/get-static-masteries.json +1 -0
  50. data/spec/fixtures/v3/get-static-realms.json +1 -0
  51. data/spec/fixtures/v3/get-static-runes-by-id.json +1 -0
  52. data/spec/fixtures/v3/get-static-runes.json +1 -0
  53. data/spec/fixtures/v3/get-static-summoner-spells-by-id.json +1 -0
  54. data/spec/fixtures/v3/get-static-summoner-spells.json +1 -0
  55. data/spec/fixtures/v3/get-static-versions.json +1 -0
  56. data/spec/fixtures/v3/get-summoner-by-name.json +1 -0
  57. data/spec/fixtures/v3/get-summoner.json +1 -0
  58. data/spec/fixtures/v3/get-timeline.json +1 -0
  59. data/spec/fixtures/v3/get-tournament-code.json +1 -0
  60. data/spec/lol/champion_mastery_request_spec.rb +33 -133
  61. data/spec/lol/champion_request_spec.rb +17 -30
  62. data/spec/lol/client_spec.rb +12 -56
  63. data/spec/lol/league_request_spec.rb +29 -72
  64. data/spec/lol/lol_status_request_spec.rb +6 -34
  65. data/spec/lol/masteries_request_spec.rb +15 -0
  66. data/spec/lol/match_request_spec.rb +45 -10
  67. data/spec/lol/request_spec.rb +5 -5
  68. data/spec/lol/runes_request_spec.rb +15 -0
  69. data/spec/lol/spectator_request_spec.rb +23 -0
  70. data/spec/lol/static_request_spec.rb +44 -48
  71. data/spec/lol/summoner_request_spec.rb +20 -71
  72. data/spec/lol/tournament_request_spec.rb +36 -0
  73. metadata +92 -175
  74. data/lib/lol/champion.rb +0 -37
  75. data/lib/lol/champion_mastery.rb +0 -50
  76. data/lib/lol/champion_statistics_summary.rb +0 -25
  77. data/lib/lol/current_game_request.rb +0 -16
  78. data/lib/lol/featured_games_request.rb +0 -15
  79. data/lib/lol/game.rb +0 -85
  80. data/lib/lol/game_request.rb +0 -19
  81. data/lib/lol/league.rb +0 -32
  82. data/lib/lol/league_entry.rb +0 -74
  83. data/lib/lol/mastery.rb +0 -16
  84. data/lib/lol/mastery_page.rb +0 -28
  85. data/lib/lol/match_list_request.rb +0 -15
  86. data/lib/lol/match_summary.rb +0 -59
  87. data/lib/lol/mini_series.rb +0 -29
  88. data/lib/lol/model.rb +0 -28
  89. data/lib/lol/player.rb +0 -21
  90. data/lib/lol/player_statistic.rb +0 -46
  91. data/lib/lol/ranked_statistics_summary.rb +0 -35
  92. data/lib/lol/roster.rb +0 -23
  93. data/lib/lol/rune_page.rb +0 -28
  94. data/lib/lol/rune_slot.rb +0 -29
  95. data/lib/lol/stats_request.rb +0 -35
  96. data/lib/lol/summoner.rb +0 -36
  97. data/lib/lol/team.rb +0 -110
  98. data/lib/lol/team_member.rb +0 -33
  99. data/lib/lol/team_request.rb +0 -32
  100. data/lib/lol/team_statistic.rb +0 -53
  101. data/lib/lol/tournament_code.rb +0 -58
  102. data/lib/lol/tournament_provider_request.rb +0 -111
  103. data/spec/fixtures/v1.0/get-champion-mastery-top-champions-10.json +0 -121
  104. data/spec/fixtures/v1.0/get-champion-mastery-top-champions.json +0 -38
  105. data/spec/fixtures/v1.0/get-current-game.json +0 -1065
  106. data/spec/fixtures/v1.0/get-featured-games.json +0 -730
  107. data/spec/fixtures/v1.0/get-lol-status-shard-by-region.json +0 -39
  108. data/spec/fixtures/v1.0/get-lol-status-shards.json +0 -78
  109. data/spec/fixtures/v1.2/get-champion-by-id.json +0 -6
  110. data/spec/fixtures/v1.2/get-item-by-id.json +0 -6
  111. data/spec/fixtures/v1.2/get-item.json +0 -1563
  112. data/spec/fixtures/v1.2/get-mastery-by-id.json +0 -9
  113. data/spec/fixtures/v1.2/get-mastery.json +0 -389
  114. data/spec/fixtures/v1.2/get-realm.json +0 -1
  115. data/spec/fixtures/v1.2/get-rune-by-id.json +0 -26
  116. data/spec/fixtures/v1.2/get-rune.json +0 -2966
  117. data/spec/fixtures/v1.2/get-static-champion.json +0 -714
  118. data/spec/fixtures/v1.2/get-summoner-spell-by-id.json +0 -39
  119. data/spec/fixtures/v1.2/get-summoner-spell.json +0 -97
  120. data/spec/fixtures/v1.2/get-versions.json +0 -1
  121. data/spec/fixtures/v1.3/get-game.json +0 -1040
  122. data/spec/fixtures/v1.3/get-ranked_stats.json +0 -1
  123. data/spec/fixtures/v1.3/get-stats.json +0 -1
  124. data/spec/fixtures/v1.4/get-summoner-by-name.json +0 -1
  125. data/spec/fixtures/v1.4/get-summoner-masteries.json +0 -898
  126. data/spec/fixtures/v1.4/get-summoner-name.json +0 -1
  127. data/spec/fixtures/v1.4/get-summoner-runes.json +0 -2547
  128. data/spec/fixtures/v1.4/get-summoner.json +0 -1
  129. data/spec/fixtures/v2.2/get-match.json +0 -1
  130. data/spec/fixtures/v2.2/get-match_list.json +0 -1
  131. data/spec/fixtures/v2.4/get-by-summoner.json +0 -1
  132. data/spec/fixtures/v2.4/get-team.json +0 -1
  133. data/spec/fixtures/v2.5/get-league-by-team.json +0 -1
  134. data/spec/fixtures/v2.5/get-league-challenger.json +0 -1
  135. data/spec/fixtures/v2.5/get-league-entry-by-team.json +0 -1
  136. data/spec/fixtures/v2.5/get-league-entry.json +0 -1
  137. data/spec/fixtures/v2.5/get-league-master.json +0 -1
  138. data/spec/fixtures/v2.5/get-league.json +0 -1
  139. data/spec/lol/champion_mastery_spec.rb +0 -20
  140. data/spec/lol/champion_spec.rb +0 -19
  141. data/spec/lol/champion_statistics_summary_spec.rb +0 -38
  142. data/spec/lol/current_game_request_spec.rb +0 -47
  143. data/spec/lol/featured_games_request_spec.rb +0 -39
  144. data/spec/lol/game_request_spec.rb +0 -32
  145. data/spec/lol/game_spec.rb +0 -51
  146. data/spec/lol/league_entry_spec.rb +0 -51
  147. data/spec/lol/league_spec.rb +0 -31
  148. data/spec/lol/mastery_page_spec.rb +0 -29
  149. data/spec/lol/mastery_spec.rb +0 -17
  150. data/spec/lol/match_list_request_spec.rb +0 -39
  151. data/spec/lol/match_summary_spec.rb +0 -25
  152. data/spec/lol/mini_series_spec.rb +0 -25
  153. data/spec/lol/model_spec.rb +0 -13
  154. data/spec/lol/player_spec.rb +0 -19
  155. data/spec/lol/player_statistic_spec.rb +0 -44
  156. data/spec/lol/ranked_statistics_summary_spec.rb +0 -32
  157. data/spec/lol/roster_spec.rb +0 -24
  158. data/spec/lol/rune_page_spec.rb +0 -28
  159. data/spec/lol/rune_slot_spec.rb +0 -16
  160. data/spec/lol/stats_request_spec.rb +0 -93
  161. data/spec/lol/summoner_spec.rb +0 -20
  162. data/spec/lol/team_member_spec.rb +0 -27
  163. data/spec/lol/team_request_spec.rb +0 -47
  164. data/spec/lol/team_spec.rb +0 -54
  165. data/spec/lol/team_statistic_spec.rb +0 -20
  166. data/spec/lol/tournament_code_spec.rb +0 -20
  167. data/spec/lol/tournament_provider_request_spec.rb +0 -73
@@ -4,94 +4,51 @@ require "lol"
4
4
  include Lol
5
5
 
6
6
  describe LeagueRequest do
7
- it "inherits from Request" do
8
- expect(LeagueRequest.ancestors[1]).to eq(Request)
9
- end
10
-
11
- let(:request) { LeagueRequest.new("api_key", "euw") }
12
-
13
- describe "#get" do
14
- subject { request.get(123) }
15
-
16
- let(:fixture) { load_fixture('league', request.class.api_version) }
17
-
18
- before(:each) { stub_request(request, 'league', 'league/by-summoner/123') }
19
-
20
- it "returns a hash of arrays of Leagues" do
21
- expect(subject.map {|_,v| v.map(&:class).uniq}.flatten).to eq([League])
22
- end
7
+ subject { LeagueRequest.new 'api_key', 'euw' }
23
8
 
24
- it 'has hash keys with string summoner ids' do
25
- expect(subject.keys).to eq(fixture.keys)
26
- end
9
+ it 'inherits from V3 Request' do
10
+ expect(LeagueRequest).to be < Request
27
11
  end
28
12
 
29
- describe "#get_entries" do
30
- subject { request.get_entries(123) }
31
-
32
- let(:fixture) { load_fixture('league-entry', request.class.api_version) }
33
-
34
- before(:each) { stub_request(request, 'league-entry', 'league/by-summoner/123/entry') }
35
-
36
- it 'returns a hash of arrays of Leagues' do
37
- expect(subject.map {|_,v| v.map(&:class).uniq}.flatten).to eq([League])
13
+ describe '#find_challenger' do
14
+ it 'returns a DynamicModel' do
15
+ stub_request subject, 'league-challenger', 'challengerleagues/by-queue/RANKED_SOLO_5x5'
16
+ expect(subject.find_challenger).to be_a DynamicModel
38
17
  end
39
18
 
40
- it 'has hash keys with summoner ids' do
41
- expect(subject.keys).to eq(fixture.keys)
19
+ it 'finds the challenger league for the given queue' do
20
+ stub_request subject, 'league-challenger', 'challengerleagues/by-queue/foo'
21
+ subject.find_challenger queue: 'foo'
42
22
  end
43
23
  end
44
24
 
45
- describe '#by_team' do
46
- subject { request.by_team('TEAM-7d7013d0-b38b-11e3-9e38-782bcb497d6f') }
47
-
48
- let(:fixture) { load_fixture('league-by-team', request.class.api_version) }
49
-
50
- before(:each) { stub_request(request, 'league-by-team', 'league/by-team/TEAM-7d7013d0-b38b-11e3-9e38-782bcb497d6f') }
51
-
52
- it 'returns a hash of arrays of Leagues' do
53
- expect(subject.map {|_,v| v.map(&:class).uniq}.flatten).to eq([League])
25
+ describe '#find_master' do
26
+ it 'returns a LeagueList' do
27
+ stub_request subject, 'league-master', 'masterleagues/by-queue/RANKED_SOLO_5x5'
28
+ expect(subject.find_master).to be_a DynamicModel
54
29
  end
55
30
 
56
- it 'has hash keys with string team id' do
57
- expect(subject.keys).to eq(fixture.keys)
31
+ it 'finds the master league for the given queue' do
32
+ stub_request subject, 'league-master', 'masterleagues/by-queue/foo'
33
+ subject.find_master queue: 'foo'
58
34
  end
59
35
  end
60
36
 
61
- describe '#entries_by_team' do
62
- subject { request.entries_by_team('TEAM-7d7013d0-b38b-11e3-9e38-782bcb497d6f') }
63
-
64
- let(:fixture) { load_fixture('league-entry-by-team', request.class.api_version) }
65
-
66
- before(:each) { stub_request(request, 'league-entry-by-team', 'league/by-team/TEAM-7d7013d0-b38b-11e3-9e38-782bcb497d6f/entry') }
67
-
68
- it 'returns a hash of arrays of Leagues' do
69
- expect(subject.map {|_,v| v.map(&:class).uniq}.flatten).to eq([League])
70
- end
71
-
72
- it 'has hash keys with string team id' do
73
- expect(subject.keys).to eq(fixture.keys)
37
+ describe '#summoner_leagues' do
38
+ it 'returns an array of LeagueList objects' do
39
+ stub_request subject, 'league-summoner', 'leagues/by-summoner/1'
40
+ result = subject.summoner_leagues summoner_id: 1
41
+ expect(result).to be_a Array
42
+ expect(result.map(&:class).uniq).to eq [DynamicModel]
74
43
  end
75
44
  end
76
45
 
77
- describe '#challenger' do
78
- subject { request.challenger('RANKED_SOLO_5x5') }
79
-
80
- before(:each) { stub_request(request, 'league-challenger', 'league/challenger', { :type => 'RANKED_SOLO_5x5' }) }
81
-
82
- it 'returns League' do
83
- expect(subject.class).to eq(League)
46
+ describe '#summoner_positions' do
47
+ it 'returns an array of DynamicModel objects' do
48
+ stub_request subject, 'league-positions', 'positions/by-summoner/1'
49
+ result = subject.summoner_positions summoner_id: 1
50
+ expect(result).to be_a Array
51
+ expect(result.map(&:class).uniq).to eq [DynamicModel]
84
52
  end
85
53
  end
86
-
87
- describe '#master' do
88
- subject { request.master('RANKED_SOLO_5x5')}
89
-
90
- before(:each) { stub_request(request, 'league-master', 'league/master', { :type => 'RANKED_SOLO_5x5'})}
91
-
92
- it 'returns League' do
93
- expect(subject.class).to eq(League)
94
- end
95
- end
96
-
97
54
  end
@@ -4,44 +4,16 @@ require "lol"
4
4
  include Lol
5
5
 
6
6
  describe LolStatusRequest do
7
- it 'inherits from Request' do
8
- expect(LolStatusRequest.ancestors[1]).to eq(Request)
9
- end
10
-
11
- describe '#api_url' do
12
- it 'returns full url for' do
13
- expect(subject.api_url('shards')).to eq 'http://status.leagueoflegends.com/shards'
14
- end
15
-
16
- it 'returns full url with path' do
17
- expect(subject.api_url('shards', 'something')).to eq 'http://status.leagueoflegends.com/shards/something'
18
- end
19
- end
20
-
21
- describe "#shards" do
22
- let(:response) { subject.shards }
7
+ subject { LolStatusRequest.new "api_key", "euw" }
23
8
 
24
- before(:each) { stub_request(subject, 'lol-status-shards', 'shards') }
25
-
26
- it 'returns an array' do
27
- expect(response).to be_a(Array)
28
- end
29
-
30
- it 'returns an array of Shard' do
31
- expect(response.map(&:class).uniq).to eq([DynamicModel])
32
- end
33
-
34
- it 'fetches shards from the API' do
35
- fixture = load_fixture('lol-status-shards', LolStatusRequest.api_version)
36
- expect(response.size).to eq(fixture.size)
37
- end
9
+ it 'inherits from Request' do
10
+ expect(LolStatusRequest).to be < Request
38
11
  end
39
12
 
40
- describe '#current_shard' do
41
- subject { LolStatusRequest.new 'euw'}
42
- let(:response) { subject.current_shard }
13
+ describe '#shard_data' do
14
+ let(:response) { subject.shard_data }
43
15
 
44
- before(:each) { stub_request(subject, 'lol-status-shard-by-region', 'shards', 'euw') }
16
+ before(:each) { stub_request(subject, 'lol-status-shard', 'shard-data') }
45
17
 
46
18
  it 'returns a Shard' do
47
19
  expect(response).to be_a(DynamicModel)
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+ require "lol"
3
+
4
+ describe Lol::MasteriesRequest do
5
+ subject { Lol::MasteriesRequest.new "api_key", "euw" }
6
+
7
+ describe "#by_summoner_id" do
8
+ it "returns an Array of DynamicModel" do
9
+ stub_request subject, "masteries", "masteries/by-summoner/1"
10
+ result = subject.by_summoner_id 1
11
+ expect(result).to be_a Array
12
+ expect(result.map(&:class).uniq).to eq [Lol::DynamicModel]
13
+ end
14
+ end
15
+ end
@@ -4,24 +4,59 @@ require "lol"
4
4
  include Lol
5
5
 
6
6
  describe MatchRequest do
7
+ subject { MatchRequest.new "api_key", "euw" }
8
+
7
9
  it "inherits from Request" do
8
- expect(MatchRequest.ancestors[1]).to eq(Request)
10
+ expect(MatchRequest).to be < Request
9
11
  end
10
12
 
11
- let(:request) { MatchRequest.new("api_key", "euw") }
13
+ describe "#find" do
14
+ context "without a tournament code" do
15
+ let(:result) { subject.find 1 }
16
+ before { stub_request subject, 'match', "matches/1" }
17
+
18
+ it "returns a DynamicModel" do
19
+ expect(result).to be_a DynamicModel
20
+ end
21
+ end
22
+
23
+ context "with a tournament code" do
24
+ let(:result) { subject.find 1, tournament_code: 2 }
25
+ before { stub_request subject, 'match-with-tc', "matches/1/by-tournament-code/2" }
26
+
27
+ it "returns a DynamicModel" do
28
+ expect(result).to be_a DynamicModel
29
+ end
30
+ end
31
+ end
12
32
 
13
- describe "#get" do
14
- subject { request.get(1) }
33
+ describe "#find_timeline" do
34
+ it "returns a DynamicModel" do
35
+ stub_request subject, 'timeline', "timelines/by-match/1"
36
+ expect(subject.find_timeline 1).to be_a DynamicModel
37
+ end
38
+ end
15
39
 
16
- before { stub_request(request, 'match', 'match/1') }
40
+ describe "#ids_by_tournament_code" do
41
+ it "returns a list of ids" do
42
+ stub_request subject, 'ids-by-tc', "matches/by-tournament-code/1/ids"
43
+ result = subject.ids_by_tournament_code '1'
44
+ expect(result).to be_a Array
45
+ expect(result.map(&:class).uniq).to eq [Integer]
46
+ end
47
+ end
17
48
 
18
- it 'returns an hash' do
19
- expect(subject).to be_a(Hash)
49
+ describe "#all" do
50
+ it "returns a DynamicModel" do
51
+ stub_request subject, 'matches', "matchlists/by-account/1"
52
+ expect(subject.all account_id: 1).to be_a DynamicModel
20
53
  end
54
+ end
21
55
 
22
- it 'fetches matches from the API' do
23
- fixture = load_fixture('match', MatchRequest.api_version)
24
- expect(subject.keys).to match_array fixture.keys
56
+ describe "#recent" do
57
+ it "returns a DynamicModel" do
58
+ stub_request subject, 'matches-recent', "matchlists/by-account/1/recent"
59
+ expect(subject.recent account_id: 1).to be_a DynamicModel
25
60
  end
26
61
  end
27
62
  end
@@ -162,11 +162,11 @@ describe Request do
162
162
 
163
163
  describe "api_url" do
164
164
  it "defaults on Request#region" do
165
- expect(subject.api_url("bar")).to match(/\/euw\//)
165
+ expect(subject.api_url("bar")).to match(/\/euw1\./)
166
166
  end
167
167
 
168
168
  it "defaults on Reques.api_version" do
169
- expect(subject.api_url("bar")).to match(/\/v1.1\//)
169
+ expect(subject.api_url("bar")).to match(/\/v3\//)
170
170
  end
171
171
 
172
172
  it "a path" do
@@ -174,11 +174,11 @@ describe Request do
174
174
  end
175
175
 
176
176
  it "returns a full fledged api url" do
177
- expect(subject.api_url("bar")).to eq("https://euw.api.pvp.net/api/lol/euw/v1.1/bar?api_key=api_key")
177
+ expect(subject.api_url("bar")).to eq("https://euw1.api.riotgames.com/lol/platform/v3/bar?api_key=api_key")
178
178
  end
179
179
 
180
180
  it "optionally accept query string parameters" do
181
- 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")
181
+ expect(subject.api_url("foo", a: 'b')).to eq("https://euw1.api.riotgames.com/lol/platform/v3/foo?a=b&api_key=api_key")
182
182
  end
183
183
 
184
184
  it "delegates the base url to #api_base_url" do
@@ -194,7 +194,7 @@ describe Request do
194
194
 
195
195
  describe "#api_base_url" do
196
196
  it "returns the base domain" do
197
- expect(subject.api_base_url).to eq "https://euw.api.pvp.net"
197
+ expect(subject.api_base_url).to eq "https://euw1.api.riotgames.com"
198
198
  end
199
199
  end
200
200
 
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+ require "lol"
3
+
4
+ describe Lol::RunesRequest do
5
+ subject { Lol::RunesRequest.new "api_key", "euw" }
6
+
7
+ describe "#by_summoner_id" do
8
+ it "returns an Array of DynamicModel" do
9
+ stub_request subject, "runes", "runes/by-summoner/1"
10
+ result = subject.by_summoner_id 1
11
+ expect(result).to be_a Array
12
+ expect(result.map(&:class).uniq).to eq [Lol::DynamicModel]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+ require "lol"
3
+
4
+ describe Lol::SpectatorRequest do
5
+ subject { described_class.new "api_key", "euw" }
6
+
7
+ describe "#current_game" do
8
+ it "returns a DynamicModel" do
9
+ stub_request subject, "current-game", "active-games/by-summoner/23"
10
+ expect(subject.current_game summoner_id: 23).to be_a Lol::DynamicModel
11
+ end
12
+ end
13
+
14
+ describe "#featured_games" do
15
+ it "returns a FeaturedGameList" do
16
+ stub_request subject, "featured-games", "featured-games"
17
+ result = subject.featured_games
18
+ expect(result).to be_a Lol::FeaturedGameList
19
+ expect(result.client_refresh_interval).not_to be_nil
20
+ expect(result.size).not_to be_zero
21
+ end
22
+ end
23
+ end
@@ -4,87 +4,83 @@ require "lol"
4
4
  include Lol
5
5
 
6
6
  describe StaticRequest do
7
- describe "api_version" do
8
- it "is v1.2" do
9
- expect(StaticRequest.api_version).to eq("v1.2")
10
- end
11
- end
12
-
13
- let(:request) { StaticRequest.new("api_key", "euw") }
14
-
15
- describe "#api_url" do
16
- it "contains a static-data path component" do
17
- expect(request.api_url("foo")).to eq("https://global.api.pvp.net/api/lol/static-data/euw/v1.2/foo?api_key=api_key")
18
- end
19
- end
20
-
21
- StaticRequest::STANDARD_ENDPOINTS.each do |endpoint|
22
- describe "##{endpoint}" do
7
+ let(:subject) { StaticRequest.new("api_key", "euw") }
8
+
9
+ {
10
+ "champion" => "champions",
11
+ "item" => "items",
12
+ "mastery" => "masteries",
13
+ "rune" => "runes",
14
+ "summoner_spell" => "summoner_spells"
15
+ }.each do |old_edpoint, new_endpoint|
16
+ describe "##{new_endpoint}" do
23
17
  it "returns a Proxy" do
24
- expect(request.send(endpoint).class).to eq(StaticRequest::Proxy)
18
+ expect(subject.send(new_endpoint).class).to eq(StaticRequest::Proxy)
25
19
  end
26
20
 
27
21
  describe "#get" do
28
- it "proxies get to StaticRequest with the correct endpoint" do
29
- expect(request).to receive(:get).with(endpoint, anything, anything)
22
+ let(:fixture_name) { "static-#{new_endpoint.dasherize}" }
30
23
 
31
- request.send(endpoint).get
24
+ it "proxies get to StaticRequest with the correct endpoint" do
25
+ expect(subject).to receive(:get).with(new_endpoint, anything, anything)
26
+ subject.send(new_endpoint).get
32
27
  end
33
28
 
34
- context "without_id" do
35
-
36
- let(:fixture_name) { endpoint == 'champion' ? 'static-champion' : endpoint.dasherize }
29
+ context "without an id" do
37
30
  let(:fixture) { load_fixture(fixture_name, StaticRequest.api_version) }
38
31
 
39
- subject { request.public_send(endpoint).get }
32
+ let(:result) { subject.public_send(new_endpoint).get }
40
33
 
41
- before(:each) { stub_request(request, fixture_name, "#{endpoint.dasherize}") }
34
+ before { stub_request(subject, fixture_name, "#{new_endpoint.dasherize}") }
42
35
 
43
- it "returns an Array" do
44
- expect(subject).to be_an(Array)
36
+ it "returns an Array of OpenStruct" do
37
+ expect(result).to be_a Array
38
+ expect(result.map(&:class).uniq).to eq([OpenStruct])
45
39
  end
46
40
 
47
- it "returns an Array of OpenStructs" do
48
- expect(subject.map(&:class).uniq).to eq([OpenStruct])
49
- end
50
-
51
- it "fetches #{endpoint} from the API" do
52
- expect(subject.size).to eq(fixture["data"].size)
41
+ it "fetches #{new_endpoint} from the API" do
42
+ expect(result.size).to eq(fixture["data"].size)
53
43
  end
54
44
  end
55
45
 
56
- context "with_id" do
57
- let(:id) { 1 }
58
-
59
- before(:each) { stub_request(request, "#{endpoint.dasherize}-by-id", "#{endpoint.dasherize}/#{id}") }
60
-
61
- subject { request.public_send(endpoint).get(id) }
62
-
46
+ context "with an id" do
63
47
  it "returns an OpenStruct" do
64
- expect(subject).to be_an(OpenStruct)
48
+ stub_request(subject, "#{fixture_name}-by-id", "#{new_endpoint.dasherize}/1")
49
+ expect(subject.public_send(new_endpoint).get 1).to be_a OpenStruct
65
50
  end
66
51
  end
67
52
  end
68
53
  end
69
54
  end
70
55
 
71
- describe "#realm" do
72
- subject { request.realm.get }
56
+ describe "#maps" do
57
+ let(:result) { subject.maps.get }
58
+
59
+ before(:each) { stub_request(subject, 'static-maps', 'maps') }
60
+
61
+ it "returns an Array of OpenStructs" do
62
+ expect(result).to be_a Array
63
+ expect(result.map(&:class).uniq).to eq [OpenStruct]
64
+ end
65
+ end
66
+
67
+ describe "#realms" do
68
+ let(:result) { subject.realms.get }
73
69
 
74
- before(:each) { stub_request(request, 'realm', 'realm') }
70
+ before(:each) { stub_request(subject, 'static-realms', 'realms') }
75
71
 
76
72
  it "returns an OpenStruct" do
77
- expect(subject).to be_an(OpenStruct)
73
+ expect(result).to be_a OpenStruct
78
74
  end
79
75
  end
80
76
 
81
77
  describe "#versions" do
82
- subject { request.versions.get }
78
+ let(:result) { subject.versions.get }
83
79
 
84
- before(:each) { stub_request(request, 'versions', 'versions') }
80
+ before(:each) { stub_request(subject, 'static-versions', 'versions') }
85
81
 
86
82
  it "returns an Array" do
87
- expect(subject).to be_an(Array)
83
+ expect(result).to be_an(Array)
88
84
  end
89
85
  end
90
86