riot_api 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/CHANGELOG.md +5 -0
  4. data/README.md +3 -2
  5. data/lib/riot_api/api.rb +5 -3
  6. data/lib/riot_api/middleware/custom_logger.rb +70 -0
  7. data/lib/riot_api/model.rb +8 -0
  8. data/lib/riot_api/model/champion.rb +17 -0
  9. data/lib/riot_api/model/champion_stat.rb +13 -0
  10. data/lib/riot_api/model/game.rb +22 -0
  11. data/lib/riot_api/model/league.rb +13 -0
  12. data/lib/riot_api/model/league_entry.rb +21 -0
  13. data/lib/riot_api/model/mastery_page.rb +11 -0
  14. data/lib/riot_api/model/match.rb +17 -0
  15. data/lib/riot_api/model/member.rb +10 -0
  16. data/lib/riot_api/model/player.rb +9 -0
  17. data/lib/riot_api/model/player_stat_summary.rb +12 -0
  18. data/lib/riot_api/model/roster.rb +10 -0
  19. data/lib/riot_api/model/rune.rb +10 -0
  20. data/lib/riot_api/model/rune_page.rb +12 -0
  21. data/lib/riot_api/model/rune_slot.rb +10 -0
  22. data/lib/riot_api/model/statistic.rb +12 -0
  23. data/lib/riot_api/model/talent.rb +9 -0
  24. data/lib/riot_api/model/team.rb +26 -0
  25. data/lib/riot_api/model/team_id.rb +7 -0
  26. data/lib/riot_api/model/team_stat_detail.rb +13 -0
  27. data/lib/riot_api/model/team_stat_summary.rb +11 -0
  28. data/lib/riot_api/resource/base.rb +10 -0
  29. data/lib/riot_api/resource/champions.rb +4 -2
  30. data/lib/riot_api/resource/game.rb +8 -2
  31. data/lib/riot_api/resource/league.rb +6 -2
  32. data/lib/riot_api/resource/stats.rb +15 -3
  33. data/lib/riot_api/resource/summoner.rb +23 -7
  34. data/lib/riot_api/resource/team.rb +8 -2
  35. data/lib/riot_api/version.rb +1 -1
  36. data/spec/api_spec.rb +111 -54
  37. data/spec/model/champion_spec.rb +14 -0
  38. data/spec/model/champion_stat_spec.rb +18 -0
  39. data/spec/model/game_spec.rb +18 -0
  40. data/spec/model/league_entry_spec.rb +13 -0
  41. data/spec/model/league_spec.rb +17 -0
  42. data/spec/model/mastery_page_spec.rb +16 -0
  43. data/spec/model/match_spec.rb +13 -0
  44. data/spec/model/member_spec.rb +13 -0
  45. data/spec/model/player_stat_summary_spec.rb +20 -0
  46. data/spec/model/roster_spec.rb +15 -0
  47. data/spec/model/rune_page_spec.rb +16 -0
  48. data/spec/model/rune_slot_spec.rb +15 -0
  49. data/spec/model/rune_spec.rb +17 -0
  50. data/spec/model/statistic_spec.rb +17 -0
  51. data/spec/model/talent_spec.rb +16 -0
  52. data/spec/model/team_id_spec.rb +13 -0
  53. data/spec/model/team_spec.rb +44 -0
  54. data/spec/model/team_stat_detail_spec.rb +20 -0
  55. data/spec/model/team_stat_summary_stat.rb +27 -0
  56. data/spec/spec_helper.rb +11 -0
  57. data/spec/vcr/cassettes/RiotApi_API/_league/_by_summoner/{should_return_leagues_data_for_summoner.yml → should_return_league_object_for_summoner.yml} +0 -0
  58. data/spec/vcr/cassettes/RiotApi_API/_new/should_output_to_stdout_with_debug_parameter.yml +41 -0
  59. data/spec/vcr/cassettes/RiotApi_API/_new/should_raise_an_error_if_the_raise_error_status_flag_is_enabled.yml +55 -0
  60. data/spec/vcr/cassettes/RiotApi_API/_summoner/_id/should_return_information_from_the_summoner_id.yml +9 -15
  61. data/spec/vcr/cassettes/RiotApi_API/_summoner/_name/should_return_information_from_the_summoner_name.yml +9 -15
  62. metadata +72 -43
@@ -0,0 +1,11 @@
1
+ require 'riot_api/model/team_id'
2
+ require 'riot_api/model/team_stat_detail'
3
+
4
+ module RiotApi
5
+ module Model
6
+ class TeamStatSummary < Base
7
+ attribute :team_id, RiotApi::Model::TeamId
8
+ attribute :team_stat_details, Array[RiotApi::Model::TeamStatDetail]
9
+ end
10
+ end
11
+ end
@@ -6,6 +6,16 @@ module RiotApi
6
6
  @region = region
7
7
  end
8
8
 
9
+ def get(path, options={})
10
+ @connection.get(full_path(path), options).body
11
+ end
12
+
13
+ private
14
+
15
+ def full_path(path)
16
+ "#{endpoint_precursor}/#{path}"
17
+ end
18
+
9
19
  def endpoint_precursor
10
20
  "lol/#{@region}/v1.1"
11
21
  end
@@ -3,7 +3,9 @@ module RiotApi
3
3
  class Champions < Base
4
4
 
5
5
  def list(free=false)
6
- @connection.get(base_path, { :freeToPlay => free }).body.champions
6
+ get(base_path, { :freeToPlay => free }).champions.map do |champion|
7
+ RiotApi::Model::Champion.new(champion)
8
+ end
7
9
  end
8
10
 
9
11
  def free
@@ -13,7 +15,7 @@ module RiotApi
13
15
  private
14
16
 
15
17
  def base_path
16
- "#{endpoint_precursor}/champion"
18
+ "champion"
17
19
  end
18
20
  end
19
21
  end
@@ -3,17 +3,23 @@ module RiotApi
3
3
  class Game < Base
4
4
 
5
5
  def recent(summoner_id)
6
- @connection.get(recent_path(summoner_id)).body.games
6
+ get(recent_path(summoner_id)).games.map do |game|
7
+ build_game game
8
+ end
7
9
  end
8
10
 
9
11
  private
10
12
 
13
+ def build_game(data)
14
+ RiotApi::Model::Game.new data
15
+ end
16
+
11
17
  def recent_path(summoner_id)
12
18
  "#{base_path(summoner_id)}/recent"
13
19
  end
14
20
 
15
21
  def base_path(summoner_id)
16
- "#{endpoint_precursor}/game/by-summoner/#{summoner_id}"
22
+ "game/by-summoner/#{summoner_id}"
17
23
  end
18
24
 
19
25
  end
@@ -3,17 +3,21 @@ module RiotApi
3
3
  class League < BaseV21
4
4
 
5
5
  def by_summoner(summoner_id)
6
- @connection.get(by_summoner_path(summoner_id)).body[summoner_id.to_s]
6
+ build_league get(by_summoner_path(summoner_id))[summoner_id.to_s]
7
7
  end
8
8
 
9
9
  private
10
10
 
11
+ def build_league(data)
12
+ RiotApi::Model::League.new data
13
+ end
14
+
11
15
  def by_summoner_path(summoner_id)
12
16
  "#{base_path}/by-summoner/#{summoner_id}"
13
17
  end
14
18
 
15
19
  def base_path
16
- "#{endpoint_precursor}/league"
20
+ "league"
17
21
  end
18
22
 
19
23
  end
@@ -3,17 +3,29 @@ module RiotApi
3
3
  class Stats < Base
4
4
 
5
5
  def ranked(id, opts = {})
6
- @connection.get("#{base_path(id)}/ranked", opts).body
6
+ get("#{base_path(id)}/ranked", opts).champions.map do |champion|
7
+ build_champion_stat(champion)
8
+ end
7
9
  end
8
10
 
9
11
  def summary(id, opts = {})
10
- @connection.get("#{base_path(id)}/summary", opts).body
12
+ get("#{base_path(id)}/summary", opts).player_stat_summaries.map do |summaries|
13
+ build_player_stat_summary(summaries)
14
+ end
11
15
  end
12
16
 
13
17
  private
14
18
 
19
+ def build_champion_stat(data)
20
+ RiotApi::Model::ChampionStat.new data
21
+ end
22
+
23
+ def build_player_stat_summary(data)
24
+ RiotApi::Model::PlayerStatSummary.new data
25
+ end
26
+
15
27
  def base_path(id)
16
- "#{endpoint_precursor}/stats/by-summoner/#{id}"
28
+ "stats/by-summoner/#{id}"
17
29
  end
18
30
  end
19
31
  end
@@ -3,32 +3,48 @@ module RiotApi
3
3
  class Summoner < Base
4
4
 
5
5
  def name(name, opts = {})
6
- RiotApi::Model::Summoner.new @connection.get("#{base_path}/by-name/#{name}/").body
6
+ build_summoner get("#{base_path}/by-name/#{name}")
7
7
  end
8
8
 
9
9
  def id(id, opts = {})
10
- RiotApi::Model::Summoner.new @connection.get("#{base_path}/#{id}/").body
10
+ build_summoner get("#{base_path}/#{id}")
11
11
  end
12
12
 
13
13
  def masteries(id)
14
- @connection.get("#{base_path}/#{id}/masteries").body
14
+ get("#{base_path}/#{id}/masteries").pages.map do |page|
15
+ build_mastery_page page
16
+ end
15
17
  end
16
18
 
17
19
  def names(*ids)
18
20
  ids = ids.compact.join(',')
19
- @connection.get("#{base_path}/#{ids}/name").body.summoners.map do |summoner|
20
- RiotApi::Model::Summoner.new summoner
21
+ get("#{base_path}/#{ids}/name").summoners.map do |summoner|
22
+ build_summoner summoner
21
23
  end
22
24
  end
23
25
 
24
26
  def runes(id)
25
- @connection.get("#{base_path}/#{id}/runes").body
27
+ get("#{base_path}/#{id}/runes").pages.map do |page|
28
+ build_rune_page page
29
+ end
26
30
  end
27
31
 
28
32
  private
29
33
 
34
+ def build_mastery_page(data)
35
+ RiotApi::Model::MasteryPage.new data
36
+ end
37
+
38
+ def build_rune_page(data)
39
+ RiotApi::Model::RunePage.new data
40
+ end
41
+
42
+ def build_summoner(data)
43
+ RiotApi::Model::Summoner.new data
44
+ end
45
+
30
46
  def base_path
31
- "#{endpoint_precursor}/summoner/"
47
+ "summoner"
32
48
  end
33
49
 
34
50
  end
@@ -3,17 +3,23 @@ module RiotApi
3
3
  class Team < BaseV21
4
4
 
5
5
  def by_summoner(summoner_id)
6
- @connection.get(by_summoner_path(summoner_id)).body
6
+ get(by_summoner_path(summoner_id)).map do |team|
7
+ build_team(team)
8
+ end
7
9
  end
8
10
 
9
11
  private
10
12
 
13
+ def build_team(data)
14
+ RiotApi::Model::Team.new data
15
+ end
16
+
11
17
  def by_summoner_path(summoner_id)
12
18
  "#{base_path}/by-summoner/#{summoner_id}"
13
19
  end
14
20
 
15
21
  def base_path
16
- "#{endpoint_precursor}/team"
22
+ "team"
17
23
  end
18
24
 
19
25
  end
@@ -1,3 +1,3 @@
1
1
  module RiotApi
2
- VERSION = '0.0.4'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -17,6 +17,20 @@ describe RiotApi::API, :vcr do
17
17
  it 'should raise an error when given an invalid region' do
18
18
  expect{ client = RiotApi::API.new :api_key => api_key, :region => 'YYZ'}.to raise_error(ArgumentError, "Invalid Region (Valid regions: 'eune','br','tr','na','euw')")
19
19
  end
20
+
21
+ it 'should output to stdout with debug parameter' do
22
+ client = RiotApi::API.new :api_key => api_key, :region => 'euw', :debug => true
23
+
24
+ printed = capture_stdout do
25
+ client.summoner.name 'BestLuxEUW'
26
+ end
27
+ expect(printed).to include 'Started GET request to: http://prod.api.pvp.net/api/lol/euw/v1.1/summoner/by-name/BestLuxEUW?api_key=[API-KEY]'
28
+ end
29
+
30
+ it 'should raise an error if the raise error status flag is enabled' do
31
+ client = RiotApi::API.new :api_key => api_key, :region => 'euw', :raise_status_errors => true
32
+ expect{ client.summoner.name 'fakemcfakename' }.to raise_error(Faraday::Error::ResourceNotFound, "the server responded with status 404")
33
+ end
20
34
  end
21
35
 
22
36
  describe 'ssl settings' do
@@ -62,13 +76,15 @@ describe RiotApi::API, :vcr do
62
76
  describe '#masteries' do
63
77
  let(:summoner_id) { '19531813' }
64
78
 
65
- let(:response) {
66
- subject.summoner.masteries summoner_id
67
- }
79
+ let(:pages) { subject.summoner.masteries summoner_id }
80
+ let(:page) { pages.first }
81
+ let(:talents) { page.talents }
82
+ let(:talent) { talents.first }
68
83
 
69
84
  it 'should return a list of mastery pages containing lists of talents' do
70
- response.pages.count.should be > 0
71
- response.pages.first.talents.count.should be > 0
85
+ page.class.should == RiotApi::Model::MasteryPage
86
+ talent.class.should == RiotApi::Model::Talent
87
+ talent.name.should_not be_nil
72
88
  end
73
89
  end
74
90
 
@@ -89,13 +105,16 @@ describe RiotApi::API, :vcr do
89
105
  describe '#runes' do
90
106
  let(:summoner_id) { '19531813' }
91
107
 
92
- let(:response) {
93
- subject.summoner.runes summoner_id
94
- }
108
+ let(:pages) { subject.summoner.runes summoner_id }
109
+ let(:page) { pages.first }
110
+ let(:slot) { page.slots.first }
111
+ let(:rune) { slot.rune }
95
112
 
96
113
  it 'should return a list of rune pages containing lists of talents' do
97
- response.pages.count.should be > 0
98
- response.pages.first.slots.count.should be > 0
114
+ page.class.should == RiotApi::Model::RunePage
115
+ slot.class.should == RiotApi::Model::RuneSlot
116
+ rune.class.should == RiotApi::Model::Rune
117
+ rune.id.should_not be_nil
99
118
  end
100
119
  end
101
120
 
@@ -108,24 +127,32 @@ describe RiotApi::API, :vcr do
108
127
  describe '#ranked' do
109
128
 
110
129
  describe 'omitting season' do
111
- let(:response) {
112
- subject.stats.ranked summoner_id
113
- }
130
+ let(:champion_stats) { subject.stats.ranked summoner_id }
131
+ let(:champion_stat) { champion_stats.first }
132
+ let(:stats) { champion_stat.stats }
133
+ let(:stat) { stats.first }
114
134
 
115
135
  it 'should return ranked information from the summoner id' do
116
- response.summonerId.should eql(19531813)
117
- response.champions.first.first.should eql ["id", 111]
136
+ champion_stats.class.should == Array
137
+ champion_stat.class.should == RiotApi::Model::ChampionStat
138
+ stats.class.should == Array
139
+ stat.class.should == RiotApi::Model::Statistic
140
+ champion_stat.id.should == 111
118
141
  end
119
142
  end
120
143
 
121
144
  describe 'specifying season' do
122
- let(:response) {
123
- subject.stats.ranked summoner_id, :season => "SEASON3"
124
- }
145
+ let(:champion_stats) { subject.stats.ranked summoner_id, :season => "SEASON3" }
146
+ let(:champion_stat) { champion_stats.first }
147
+ let(:stats) { champion_stat.stats }
148
+ let(:stat) { stats.first }
125
149
 
126
150
  it 'should return ranked information from the summoner id for the specified season' do
127
- response.summonerId.should eql(19531813)
128
- response.champions.first.first.should eql ["id", 111]
151
+ champion_stats.class.should == Array
152
+ champion_stat.class.should == RiotApi::Model::ChampionStat
153
+ stats.class.should == Array
154
+ stat.class.should == RiotApi::Model::Statistic
155
+ champion_stat.id.should == 111
129
156
  end
130
157
  end
131
158
  end
@@ -133,24 +160,32 @@ describe RiotApi::API, :vcr do
133
160
  describe '#summary' do
134
161
 
135
162
  describe 'omitting season' do
136
- let(:response) {
137
- subject.stats.summary summoner_id
138
- }
163
+ let(:player_stat_summaries) { subject.stats.summary summoner_id }
164
+ let(:player_stat_summary) { player_stat_summaries.first }
165
+ let(:aggregated_stats) { player_stat_summary.aggregated_stats }
166
+ let(:aggregated_stat) { aggregated_stats.first }
139
167
 
140
168
  it 'should return summary information from the summoner id' do
141
- response.summonerId.should eql(19531813)
142
- response.playerStatSummaries.first.should include 'aggregated_stats'
169
+ player_stat_summaries.class.should == Array
170
+ player_stat_summary.class.should == RiotApi::Model::PlayerStatSummary
171
+ aggregated_stats.class.should == Array
172
+ aggregated_stat.class.should == RiotApi::Model::Statistic
173
+ player_stat_summary.losses.should == 0
143
174
  end
144
175
  end
145
176
 
146
177
  describe 'specifying season' do
147
- let(:response) {
148
- subject.stats.summary summoner_id, :season => "SEASON3"
149
- }
178
+ let(:player_stat_summaries) { subject.stats.summary summoner_id, :season => "SEASON3" }
179
+ let(:player_stat_summary) { player_stat_summaries.first }
180
+ let(:aggregated_stats) { player_stat_summary.aggregated_stats }
181
+ let(:aggregated_stat) { aggregated_stats.first }
150
182
 
151
183
  it 'should return summary information from the summoner id for the specified season' do
152
- response.summonerId.should eql(19531813)
153
- response.playerStatSummaries.first.should include 'aggregated_stats'
184
+ player_stat_summaries.class.should == Array
185
+ player_stat_summary.class.should == RiotApi::Model::PlayerStatSummary
186
+ aggregated_stats.class.should == Array
187
+ aggregated_stat.class.should == RiotApi::Model::Statistic
188
+ player_stat_summary.losses.should == 0
154
189
  end
155
190
  end
156
191
  end
@@ -161,26 +196,26 @@ describe RiotApi::API, :vcr do
161
196
  let(:current_champion_count) { 116 }
162
197
 
163
198
  describe '#list' do
164
- let(:response) {
199
+ let(:champions) {
165
200
  subject.champions.list
166
201
  }
167
202
 
168
203
  it 'should return a list of all champions' do
169
- response.count.should be >= current_champion_count
170
- response.first.respond_to?(:name).should be_true
204
+ champions.count.should be >= current_champion_count
205
+ champions.first.respond_to?(:name).should be_true
171
206
  end
172
207
  end
173
208
 
174
209
  describe '#free' do
175
- let(:response) {
210
+ let(:champions) {
176
211
  subject.champions.free
177
212
  }
178
213
 
179
214
  it 'should return a list of all free champions' do
180
- response.count.should be < current_champion_count
181
- response.count.should be > 0
182
- response.first.respond_to?(:name).should be_true
183
- response.first.free_to_play.should be_true
215
+ champions.should_not be_empty
216
+ champions.count.should be < current_champion_count
217
+ champions.first.respond_to?(:name).should be_true
218
+ champions.first.free_to_play.should be_true
184
219
  end
185
220
  end
186
221
 
@@ -191,13 +226,14 @@ describe RiotApi::API, :vcr do
191
226
 
192
227
  # Ranked command requires user has played ranked
193
228
  describe '#recent' do
194
- let(:response) {
195
- subject.game.recent summoner_id
196
- }
229
+ let(:games) { subject.game.recent summoner_id }
230
+ let(:game) { games.first }
197
231
 
198
232
  it 'should return a list of recent games played' do
199
- response.count.should > 0
200
- response.first.respond_to?(:champion_id).should be_true
233
+ game.class.should == RiotApi::Model::Game
234
+ game.champion_id.should_not be_nil
235
+ game.fellow_players.first.class.should == RiotApi::Model::Player
236
+ game.statistics.first.class.should == RiotApi::Model::Statistic
201
237
  end
202
238
  end
203
239
  end
@@ -206,13 +242,13 @@ describe RiotApi::API, :vcr do
206
242
  let(:summoner_id) { '19531813' }
207
243
 
208
244
  describe '#by_summoner' do
209
- let(:response) {
210
- subject.league.by_summoner summoner_id
211
- }
245
+ let(:league) { subject.league.by_summoner summoner_id }
212
246
 
213
- it 'should return leagues data for summoner' do
214
- response["entries"].count.should > 0
215
- response.tier.should == 'CHALLENGER'
247
+ it 'should return league object for summoner' do
248
+ league.class.should == RiotApi::Model::League
249
+ league.tier.should == 'CHALLENGER'
250
+ league.entries.count.should > 0
251
+ league.entries.first.class.should == RiotApi::Model::LeagueEntry
216
252
  end
217
253
  end
218
254
  end
@@ -222,13 +258,34 @@ describe RiotApi::API, :vcr do
222
258
  let(:summoner_id) { '19531813' }
223
259
 
224
260
  describe '#by_summoner' do
225
- let(:response) {
226
- subject.team.by_summoner summoner_id
227
- }
261
+ let(:teams) { subject.team.by_summoner summoner_id }
262
+ let(:team) { teams.first }
263
+
264
+ let(:match_history) { team.match_history }
265
+ let(:match) { match_history.first }
266
+
267
+ let(:roster) { team.roster }
268
+ let(:member_list) { roster.member_list }
269
+ let(:member) { member_list.first }
270
+
271
+ let(:team_stat_summary) { team.team_stat_summary }
272
+ let(:team_stat_details) { team_stat_summary.team_stat_details }
273
+ let(:team_stat_detail) { team_stat_details.first }
274
+
275
+ let(:team_id) { team.team_id }
228
276
 
229
277
  it 'should return team data for summoner' do
230
- response.count.should > 0
231
- response.first.first.should == ["timestamp", 1387051307170]
278
+ teams.should_not be_empty
279
+ team.class.should == RiotApi::Model::Team
280
+
281
+ match.assists.should_not be_nil
282
+
283
+ roster.owner_id.should_not be_nil
284
+ member.player_id.should_not be_nil
285
+
286
+ team_stat_summary.team_id.should_not be_nil
287
+ team_stat_detail.wins.should_not be_nil
288
+ team_stat_detail.team_id.should_not be_nil
232
289
  end
233
290
  end
234
291
  end