riot_api 0.0.4 → 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/CHANGELOG.md +5 -0
- data/README.md +3 -2
- data/lib/riot_api/api.rb +5 -3
- data/lib/riot_api/middleware/custom_logger.rb +70 -0
- data/lib/riot_api/model.rb +8 -0
- data/lib/riot_api/model/champion.rb +17 -0
- data/lib/riot_api/model/champion_stat.rb +13 -0
- data/lib/riot_api/model/game.rb +22 -0
- data/lib/riot_api/model/league.rb +13 -0
- data/lib/riot_api/model/league_entry.rb +21 -0
- data/lib/riot_api/model/mastery_page.rb +11 -0
- data/lib/riot_api/model/match.rb +17 -0
- data/lib/riot_api/model/member.rb +10 -0
- data/lib/riot_api/model/player.rb +9 -0
- data/lib/riot_api/model/player_stat_summary.rb +12 -0
- data/lib/riot_api/model/roster.rb +10 -0
- data/lib/riot_api/model/rune.rb +10 -0
- data/lib/riot_api/model/rune_page.rb +12 -0
- data/lib/riot_api/model/rune_slot.rb +10 -0
- data/lib/riot_api/model/statistic.rb +12 -0
- data/lib/riot_api/model/talent.rb +9 -0
- data/lib/riot_api/model/team.rb +26 -0
- data/lib/riot_api/model/team_id.rb +7 -0
- data/lib/riot_api/model/team_stat_detail.rb +13 -0
- data/lib/riot_api/model/team_stat_summary.rb +11 -0
- data/lib/riot_api/resource/base.rb +10 -0
- data/lib/riot_api/resource/champions.rb +4 -2
- data/lib/riot_api/resource/game.rb +8 -2
- data/lib/riot_api/resource/league.rb +6 -2
- data/lib/riot_api/resource/stats.rb +15 -3
- data/lib/riot_api/resource/summoner.rb +23 -7
- data/lib/riot_api/resource/team.rb +8 -2
- data/lib/riot_api/version.rb +1 -1
- data/spec/api_spec.rb +111 -54
- data/spec/model/champion_spec.rb +14 -0
- data/spec/model/champion_stat_spec.rb +18 -0
- data/spec/model/game_spec.rb +18 -0
- data/spec/model/league_entry_spec.rb +13 -0
- data/spec/model/league_spec.rb +17 -0
- data/spec/model/mastery_page_spec.rb +16 -0
- data/spec/model/match_spec.rb +13 -0
- data/spec/model/member_spec.rb +13 -0
- data/spec/model/player_stat_summary_spec.rb +20 -0
- data/spec/model/roster_spec.rb +15 -0
- data/spec/model/rune_page_spec.rb +16 -0
- data/spec/model/rune_slot_spec.rb +15 -0
- data/spec/model/rune_spec.rb +17 -0
- data/spec/model/statistic_spec.rb +17 -0
- data/spec/model/talent_spec.rb +16 -0
- data/spec/model/team_id_spec.rb +13 -0
- data/spec/model/team_spec.rb +44 -0
- data/spec/model/team_stat_detail_spec.rb +20 -0
- data/spec/model/team_stat_summary_stat.rb +27 -0
- data/spec/spec_helper.rb +11 -0
- 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
- data/spec/vcr/cassettes/RiotApi_API/_new/should_output_to_stdout_with_debug_parameter.yml +41 -0
- data/spec/vcr/cassettes/RiotApi_API/_new/should_raise_an_error_if_the_raise_error_status_flag_is_enabled.yml +55 -0
- data/spec/vcr/cassettes/RiotApi_API/_summoner/_id/should_return_information_from_the_summoner_id.yml +9 -15
- data/spec/vcr/cassettes/RiotApi_API/_summoner/_name/should_return_information_from_the_summoner_name.yml +9 -15
- 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
|
-
|
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
|
-
"
|
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
|
-
|
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
|
-
"
|
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
|
-
|
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
|
-
"
|
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
|
-
|
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
|
-
|
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
|
-
"
|
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
|
-
|
6
|
+
build_summoner get("#{base_path}/by-name/#{name}")
|
7
7
|
end
|
8
8
|
|
9
9
|
def id(id, opts = {})
|
10
|
-
|
10
|
+
build_summoner get("#{base_path}/#{id}")
|
11
11
|
end
|
12
12
|
|
13
13
|
def masteries(id)
|
14
|
-
|
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
|
-
|
20
|
-
|
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
|
-
|
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
|
-
"
|
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
|
-
|
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
|
-
"
|
22
|
+
"team"
|
17
23
|
end
|
18
24
|
|
19
25
|
end
|
data/lib/riot_api/version.rb
CHANGED
data/spec/api_spec.rb
CHANGED
@@ -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(:
|
66
|
-
|
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
|
-
|
71
|
-
|
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(:
|
93
|
-
|
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
|
-
|
98
|
-
|
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(:
|
112
|
-
|
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
|
-
|
117
|
-
|
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(:
|
123
|
-
|
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
|
-
|
128
|
-
|
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(:
|
137
|
-
|
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
|
-
|
142
|
-
|
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(:
|
148
|
-
|
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
|
-
|
153
|
-
|
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(:
|
199
|
+
let(:champions) {
|
165
200
|
subject.champions.list
|
166
201
|
}
|
167
202
|
|
168
203
|
it 'should return a list of all champions' do
|
169
|
-
|
170
|
-
|
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(:
|
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
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
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(:
|
195
|
-
|
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
|
-
|
200
|
-
|
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(:
|
210
|
-
subject.league.by_summoner summoner_id
|
211
|
-
}
|
245
|
+
let(:league) { subject.league.by_summoner summoner_id }
|
212
246
|
|
213
|
-
it 'should return
|
214
|
-
|
215
|
-
|
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(:
|
226
|
-
|
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
|
-
|
231
|
-
|
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
|