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.
- checksums.yaml +4 -4
- data/.editorconfig +16 -0
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/.rubocop.yml +1157 -0
- data/.travis.yml +1 -1
- data/lib/lol/champion_mastery_request.rb +29 -57
- data/lib/lol/champion_request.rb +19 -23
- data/lib/lol/client.rb +16 -21
- data/lib/lol/dynamic_model.rb +14 -5
- data/lib/lol/featured_game_list.rb +15 -0
- data/lib/lol/league_request.rb +28 -49
- data/lib/lol/lol_status_request.rb +9 -26
- data/lib/lol/masteries_request.rb +14 -0
- data/lib/lol/match_request.rb +51 -9
- data/lib/lol/request.rb +55 -21
- data/lib/lol/runes_request.rb +14 -0
- data/lib/lol/spectator_request.rb +24 -0
- data/lib/lol/static_request.rb +34 -23
- data/lib/lol/summoner_request.rb +22 -51
- data/lib/lol/tournament_request.rb +95 -0
- data/lib/lol/version.rb +1 -1
- data/ruby-lol.gemspec +1 -1
- data/spec/api_version_spec.rb +10 -9
- data/spec/fixtures/{v1.2 → v3}/get-champion-266.json +0 -0
- data/spec/fixtures/{v1.2/get-champion.json → v3/get-champion-all.json} +0 -0
- data/spec/fixtures/{v1.0/get-champion-mastery-champions.json → v3/get-champion-masteries.json} +0 -0
- data/spec/fixtures/{v1.0/get-champion-mastery-champion.json → v3/get-champion-mastery.json} +0 -0
- data/spec/fixtures/v3/get-current-game.json +1 -0
- data/spec/fixtures/v3/get-featured-games.json +1 -0
- data/spec/fixtures/v3/get-ids-by-tc.json +1 -0
- data/spec/fixtures/v3/get-league-challenger.json +1 -0
- data/spec/fixtures/v3/get-league-master.json +1 -0
- data/spec/fixtures/v3/get-league-positions.json +1 -0
- data/spec/fixtures/v3/get-league-summoner.json +1 -0
- data/spec/fixtures/v3/get-lol-status-shard.json +1 -0
- data/spec/fixtures/v3/get-masteries.json +1 -0
- data/spec/fixtures/v3/get-match-with-tc.json +1 -0
- data/spec/fixtures/v3/get-match.json +1 -0
- data/spec/fixtures/v3/get-matches-recent.json +1 -0
- data/spec/fixtures/v3/get-matches.json +1 -0
- data/spec/fixtures/v3/get-runes.json +1 -0
- data/spec/fixtures/v3/get-static-champions-by-id.json +1 -0
- data/spec/fixtures/v3/get-static-champions.json +1 -0
- data/spec/fixtures/v3/get-static-items-by-id.json +1 -0
- data/spec/fixtures/v3/get-static-items.json +1 -0
- data/spec/fixtures/v3/get-static-maps.json +1 -0
- data/spec/fixtures/v3/get-static-masteries-by-id.json +1 -0
- data/spec/fixtures/v3/get-static-masteries.json +1 -0
- data/spec/fixtures/v3/get-static-realms.json +1 -0
- data/spec/fixtures/v3/get-static-runes-by-id.json +1 -0
- data/spec/fixtures/v3/get-static-runes.json +1 -0
- data/spec/fixtures/v3/get-static-summoner-spells-by-id.json +1 -0
- data/spec/fixtures/v3/get-static-summoner-spells.json +1 -0
- data/spec/fixtures/v3/get-static-versions.json +1 -0
- data/spec/fixtures/v3/get-summoner-by-name.json +1 -0
- data/spec/fixtures/v3/get-summoner.json +1 -0
- data/spec/fixtures/v3/get-timeline.json +1 -0
- data/spec/fixtures/v3/get-tournament-code.json +1 -0
- data/spec/lol/champion_mastery_request_spec.rb +33 -133
- data/spec/lol/champion_request_spec.rb +17 -30
- data/spec/lol/client_spec.rb +12 -56
- data/spec/lol/league_request_spec.rb +29 -72
- data/spec/lol/lol_status_request_spec.rb +6 -34
- data/spec/lol/masteries_request_spec.rb +15 -0
- data/spec/lol/match_request_spec.rb +45 -10
- data/spec/lol/request_spec.rb +5 -5
- data/spec/lol/runes_request_spec.rb +15 -0
- data/spec/lol/spectator_request_spec.rb +23 -0
- data/spec/lol/static_request_spec.rb +44 -48
- data/spec/lol/summoner_request_spec.rb +20 -71
- data/spec/lol/tournament_request_spec.rb +36 -0
- metadata +92 -175
- data/lib/lol/champion.rb +0 -37
- data/lib/lol/champion_mastery.rb +0 -50
- data/lib/lol/champion_statistics_summary.rb +0 -25
- data/lib/lol/current_game_request.rb +0 -16
- data/lib/lol/featured_games_request.rb +0 -15
- data/lib/lol/game.rb +0 -85
- data/lib/lol/game_request.rb +0 -19
- data/lib/lol/league.rb +0 -32
- data/lib/lol/league_entry.rb +0 -74
- data/lib/lol/mastery.rb +0 -16
- data/lib/lol/mastery_page.rb +0 -28
- data/lib/lol/match_list_request.rb +0 -15
- data/lib/lol/match_summary.rb +0 -59
- data/lib/lol/mini_series.rb +0 -29
- data/lib/lol/model.rb +0 -28
- data/lib/lol/player.rb +0 -21
- data/lib/lol/player_statistic.rb +0 -46
- data/lib/lol/ranked_statistics_summary.rb +0 -35
- data/lib/lol/roster.rb +0 -23
- data/lib/lol/rune_page.rb +0 -28
- data/lib/lol/rune_slot.rb +0 -29
- data/lib/lol/stats_request.rb +0 -35
- data/lib/lol/summoner.rb +0 -36
- data/lib/lol/team.rb +0 -110
- data/lib/lol/team_member.rb +0 -33
- data/lib/lol/team_request.rb +0 -32
- data/lib/lol/team_statistic.rb +0 -53
- data/lib/lol/tournament_code.rb +0 -58
- data/lib/lol/tournament_provider_request.rb +0 -111
- data/spec/fixtures/v1.0/get-champion-mastery-top-champions-10.json +0 -121
- data/spec/fixtures/v1.0/get-champion-mastery-top-champions.json +0 -38
- data/spec/fixtures/v1.0/get-current-game.json +0 -1065
- data/spec/fixtures/v1.0/get-featured-games.json +0 -730
- data/spec/fixtures/v1.0/get-lol-status-shard-by-region.json +0 -39
- data/spec/fixtures/v1.0/get-lol-status-shards.json +0 -78
- data/spec/fixtures/v1.2/get-champion-by-id.json +0 -6
- data/spec/fixtures/v1.2/get-item-by-id.json +0 -6
- data/spec/fixtures/v1.2/get-item.json +0 -1563
- data/spec/fixtures/v1.2/get-mastery-by-id.json +0 -9
- data/spec/fixtures/v1.2/get-mastery.json +0 -389
- data/spec/fixtures/v1.2/get-realm.json +0 -1
- data/spec/fixtures/v1.2/get-rune-by-id.json +0 -26
- data/spec/fixtures/v1.2/get-rune.json +0 -2966
- data/spec/fixtures/v1.2/get-static-champion.json +0 -714
- data/spec/fixtures/v1.2/get-summoner-spell-by-id.json +0 -39
- data/spec/fixtures/v1.2/get-summoner-spell.json +0 -97
- data/spec/fixtures/v1.2/get-versions.json +0 -1
- data/spec/fixtures/v1.3/get-game.json +0 -1040
- data/spec/fixtures/v1.3/get-ranked_stats.json +0 -1
- data/spec/fixtures/v1.3/get-stats.json +0 -1
- data/spec/fixtures/v1.4/get-summoner-by-name.json +0 -1
- data/spec/fixtures/v1.4/get-summoner-masteries.json +0 -898
- data/spec/fixtures/v1.4/get-summoner-name.json +0 -1
- data/spec/fixtures/v1.4/get-summoner-runes.json +0 -2547
- data/spec/fixtures/v1.4/get-summoner.json +0 -1
- data/spec/fixtures/v2.2/get-match.json +0 -1
- data/spec/fixtures/v2.2/get-match_list.json +0 -1
- data/spec/fixtures/v2.4/get-by-summoner.json +0 -1
- data/spec/fixtures/v2.4/get-team.json +0 -1
- data/spec/fixtures/v2.5/get-league-by-team.json +0 -1
- data/spec/fixtures/v2.5/get-league-challenger.json +0 -1
- data/spec/fixtures/v2.5/get-league-entry-by-team.json +0 -1
- data/spec/fixtures/v2.5/get-league-entry.json +0 -1
- data/spec/fixtures/v2.5/get-league-master.json +0 -1
- data/spec/fixtures/v2.5/get-league.json +0 -1
- data/spec/lol/champion_mastery_spec.rb +0 -20
- data/spec/lol/champion_spec.rb +0 -19
- data/spec/lol/champion_statistics_summary_spec.rb +0 -38
- data/spec/lol/current_game_request_spec.rb +0 -47
- data/spec/lol/featured_games_request_spec.rb +0 -39
- data/spec/lol/game_request_spec.rb +0 -32
- data/spec/lol/game_spec.rb +0 -51
- data/spec/lol/league_entry_spec.rb +0 -51
- data/spec/lol/league_spec.rb +0 -31
- data/spec/lol/mastery_page_spec.rb +0 -29
- data/spec/lol/mastery_spec.rb +0 -17
- data/spec/lol/match_list_request_spec.rb +0 -39
- data/spec/lol/match_summary_spec.rb +0 -25
- data/spec/lol/mini_series_spec.rb +0 -25
- data/spec/lol/model_spec.rb +0 -13
- data/spec/lol/player_spec.rb +0 -19
- data/spec/lol/player_statistic_spec.rb +0 -44
- data/spec/lol/ranked_statistics_summary_spec.rb +0 -32
- data/spec/lol/roster_spec.rb +0 -24
- data/spec/lol/rune_page_spec.rb +0 -28
- data/spec/lol/rune_slot_spec.rb +0 -16
- data/spec/lol/stats_request_spec.rb +0 -93
- data/spec/lol/summoner_spec.rb +0 -20
- data/spec/lol/team_member_spec.rb +0 -27
- data/spec/lol/team_request_spec.rb +0 -47
- data/spec/lol/team_spec.rb +0 -54
- data/spec/lol/team_statistic_spec.rb +0 -20
- data/spec/lol/tournament_code_spec.rb +0 -20
- data/spec/lol/tournament_provider_request_spec.rb +0 -73
data/lib/lol/match_request.rb
CHANGED
|
@@ -1,16 +1,58 @@
|
|
|
1
1
|
module Lol
|
|
2
|
+
# Bindings for the Match API.
|
|
3
|
+
#
|
|
4
|
+
# See: https://developer.riotgames.com/api-methods/#match-v3
|
|
2
5
|
class MatchRequest < Request
|
|
3
|
-
#
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"v2.2"
|
|
6
|
+
# @!visibility private
|
|
7
|
+
def api_base_path
|
|
8
|
+
"/lol/match/#{self.class.api_version}"
|
|
7
9
|
end
|
|
8
10
|
|
|
9
|
-
#
|
|
10
|
-
# @param
|
|
11
|
-
# @
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
# Get match by match ID.
|
|
12
|
+
# @param [Integer] match_id Match ID
|
|
13
|
+
# @param [String] tournament_code Optional tournament code the match belongs to
|
|
14
|
+
# @return [DynamicModel] Match representation
|
|
15
|
+
def find match_id, tournament_code: nil
|
|
16
|
+
url = "matches/#{match_id}".tap do |u|
|
|
17
|
+
u << "/by-tournament-code/#{tournament_code}" if tournament_code
|
|
18
|
+
end
|
|
19
|
+
DynamicModel.new perform_request api_url url
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Get match timeline by match ID.
|
|
23
|
+
# @param [Integer] match_id Match ID
|
|
24
|
+
# @return [DynamicModel] Timeline represantion
|
|
25
|
+
def find_timeline match_id
|
|
26
|
+
DynamicModel.new perform_request api_url "timelines/by-match/#{match_id}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Get match IDs by tournament code.
|
|
30
|
+
# @param [String] tournament_code Tournament code
|
|
31
|
+
# @return [Array<Integer>] List of match IDs
|
|
32
|
+
def ids_by_tournament_code tournament_code
|
|
33
|
+
perform_request api_url "matches/by-tournament-code/#{tournament_code}/ids"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Get matchlist for ranked games played on given account ID and platform ID and filtered using given filter parameters, if any.
|
|
37
|
+
# @param [Integer] account_id Account ID
|
|
38
|
+
# @param [Hash] options the options to pass to the call
|
|
39
|
+
# @option options [Array<Integer>] queue Set of queue IDs for which to filtering matchlist.
|
|
40
|
+
# @option options [Integer] beginTime The begin time to use for filtering matchlist specified as epoch milliseconds.
|
|
41
|
+
# @option options [Integer] endTime The end time to use for filtering matchlist specified as epoch milliseconds.
|
|
42
|
+
# @option options [Integer] beginIndex The begin index to use for filtering matchlist.
|
|
43
|
+
# @option options [Integer] endIndex The end index to use for filtering matchlist.
|
|
44
|
+
# @option options [Array<Integer>] season Set of season IDs for which to filtering matchlist.
|
|
45
|
+
# @option options [Array<Integer>] champion Set of champion IDs for which to filtering matchlist.
|
|
46
|
+
# @return [DynamicModel] MatchList represantion
|
|
47
|
+
def all options={}, account_id:
|
|
48
|
+
DynamicModel.new perform_request api_url "matchlists/by-account/#{account_id}", options
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Get matchlist for last 20 matches played on given account ID and platform ID.
|
|
52
|
+
# @param [Integer] account_id Account ID
|
|
53
|
+
# @return [DynamicModel] MatchList represantion
|
|
54
|
+
def recent account_id:
|
|
55
|
+
DynamicModel.new perform_request api_url "matchlists/by-account/#{account_id}/recent"
|
|
14
56
|
end
|
|
15
57
|
end
|
|
16
58
|
end
|
data/lib/lol/request.rb
CHANGED
|
@@ -24,22 +24,71 @@ module Lol
|
|
|
24
24
|
# @return [Object] the cache_store
|
|
25
25
|
attr_reader :cache_store
|
|
26
26
|
|
|
27
|
-
#
|
|
28
|
-
# @return [String]
|
|
27
|
+
# Returns the supported API Version.
|
|
28
|
+
# @return [String] v3
|
|
29
29
|
def self.api_version
|
|
30
|
-
"
|
|
30
|
+
"v3"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.platforms
|
|
34
|
+
{
|
|
35
|
+
:br => 'br1',
|
|
36
|
+
:eune => 'eun1',
|
|
37
|
+
:euw => 'euw1',
|
|
38
|
+
:jp => 'jp1',
|
|
39
|
+
:kr => 'kr1',
|
|
40
|
+
:lan => 'la1',
|
|
41
|
+
:las => 'la2',
|
|
42
|
+
:na => 'na1',
|
|
43
|
+
:oce => 'oc1',
|
|
44
|
+
:ru => 'ru',
|
|
45
|
+
:tr => 'tr1',
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Initializes a new Request
|
|
50
|
+
# @param api_key [String] the Riot Games API key
|
|
51
|
+
# @param region [String] the region you want to use in API calls
|
|
52
|
+
# @param cache_store [Hash]
|
|
53
|
+
# @option cache_store [Redis] :redis Redis instance to use
|
|
54
|
+
# @option cache_store [Boolean] :cached should the request be cached
|
|
55
|
+
# @option cacche_store [Integer] :ttl ttl for cache keys
|
|
56
|
+
# @return [Request]
|
|
57
|
+
def initialize api_key, region, cache_store = {}
|
|
58
|
+
@cache_store = cache_store
|
|
59
|
+
raise InvalidCacheStore if cached? && !store.is_a?(Redis)
|
|
60
|
+
@api_key = api_key
|
|
61
|
+
@region = region
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def platform
|
|
65
|
+
self.class.platforms[region.to_sym]
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Returns the supported API Version.
|
|
69
|
+
# @return [String] v3
|
|
70
|
+
def api_version
|
|
71
|
+
self.class.api_version
|
|
31
72
|
end
|
|
32
73
|
|
|
33
74
|
# Returns a full url for an API call
|
|
34
75
|
# @param path [String] API path to call
|
|
35
76
|
# @return [String] full fledged url
|
|
36
77
|
def api_url path, params = {}
|
|
37
|
-
url =
|
|
78
|
+
url = File.join File.join(api_base_url, api_base_path), path
|
|
38
79
|
"#{url}?#{api_query_string params}"
|
|
39
80
|
end
|
|
40
81
|
|
|
82
|
+
# Returns the API base domain
|
|
83
|
+
# @return [String] path domain
|
|
41
84
|
def api_base_url
|
|
42
|
-
"https://#{
|
|
85
|
+
"https://#{platform}.api.riotgames.com"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Returns the API base path, which is everything between the domain and the request-specific path
|
|
89
|
+
# @return [String] API path
|
|
90
|
+
def api_base_path
|
|
91
|
+
"/lol/platform/#{api_version}"
|
|
43
92
|
end
|
|
44
93
|
|
|
45
94
|
def api_query_string params = {}
|
|
@@ -105,24 +154,9 @@ module Lol
|
|
|
105
154
|
cache_store[:cached]
|
|
106
155
|
end
|
|
107
156
|
|
|
108
|
-
# @return [
|
|
157
|
+
# @return [Integer] the ttl to apply to cached keys
|
|
109
158
|
def ttl
|
|
110
159
|
cache_store[:ttl]
|
|
111
160
|
end
|
|
112
|
-
|
|
113
|
-
# Initializes a new Request
|
|
114
|
-
# @param api_key [String] the Riot Games API key
|
|
115
|
-
# @param region [String] the region you want to use in API calls
|
|
116
|
-
# @param cache_store [Hash]
|
|
117
|
-
# @option cache_store [Redis] :redis Redis instance to use
|
|
118
|
-
# @option cache_store [Boolean] :cached should the request be cached
|
|
119
|
-
# @option cacche_store [Fixnum] :ttl ttl for cache keys
|
|
120
|
-
# @return [Request]
|
|
121
|
-
def initialize api_key, region, cache_store = {}
|
|
122
|
-
@cache_store = cache_store
|
|
123
|
-
raise InvalidCacheStore if cached? && !store.is_a?(Redis)
|
|
124
|
-
@api_key = api_key
|
|
125
|
-
@region = region
|
|
126
|
-
end
|
|
127
161
|
end
|
|
128
162
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Lol
|
|
2
|
+
# Bindings for the Runes API.
|
|
3
|
+
#
|
|
4
|
+
# See: https://developer.riotgames.com/api-methods/#runes-v3
|
|
5
|
+
class RunesRequest < Request
|
|
6
|
+
# Get rune pages for a given summoner ID
|
|
7
|
+
# @param [Integer] summoner_id Summoner ID
|
|
8
|
+
# @return [Array<DynamicModel>] Rune pages
|
|
9
|
+
def by_summoner_id summoner_id
|
|
10
|
+
result = perform_request api_url "runes/by-summoner/#{summoner_id}"
|
|
11
|
+
result["pages"].map { |p| DynamicModel.new p }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Lol
|
|
2
|
+
# Bindings for the Match API.
|
|
3
|
+
#
|
|
4
|
+
# See: https://developer.riotgames.com/api-methods/#match-v3
|
|
5
|
+
class SpectatorRequest < Request
|
|
6
|
+
# @!visibility private
|
|
7
|
+
def api_base_path
|
|
8
|
+
"/lol/spectator/#{self.class.api_version}"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Get current game information for the given summoner ID.
|
|
12
|
+
# @param [Integer] summoner_id Summoner ID
|
|
13
|
+
# @return [DynamicModel] Current game representation
|
|
14
|
+
def current_game summoner_id:
|
|
15
|
+
DynamicModel.new perform_request api_url "active-games/by-summoner/#{summoner_id}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Get list of featured games.
|
|
19
|
+
# @return [FeaturedGameList] list of featured games
|
|
20
|
+
def featured_games
|
|
21
|
+
FeaturedGameList.new perform_request api_url "featured-games"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
data/lib/lol/static_request.rb
CHANGED
|
@@ -1,57 +1,68 @@
|
|
|
1
1
|
module Lol
|
|
2
2
|
class StaticRequest < Request
|
|
3
|
-
|
|
3
|
+
# @!visibility private
|
|
4
|
+
def api_base_path
|
|
5
|
+
"/lol/static-data/#{self.class.api_version}"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
{
|
|
9
|
+
"champion" => "champions",
|
|
10
|
+
"item" => "items",
|
|
11
|
+
"mastery" => "masteries",
|
|
12
|
+
"rune" => "runes",
|
|
13
|
+
"summoner_spell" => "summoner_spells"
|
|
14
|
+
}.each do |old_endpoint, new_endpoint|
|
|
15
|
+
define_method new_endpoint do
|
|
16
|
+
Proxy.new self, new_endpoint
|
|
17
|
+
end
|
|
18
|
+
end
|
|
4
19
|
|
|
5
|
-
def
|
|
6
|
-
"
|
|
20
|
+
def language_strings params={}
|
|
21
|
+
perform_request(api_url "language-strings", params).to_hash["data"]
|
|
7
22
|
end
|
|
8
23
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
# @param path [String] API path to call
|
|
12
|
-
# @return [String] full fledged url
|
|
13
|
-
def api_url path, params = {}
|
|
14
|
-
super(path,params).gsub(/api\/lol/, "api/lol/static-data").gsub(/\/\/#{region}/, "//global")
|
|
24
|
+
def languages
|
|
25
|
+
perform_request api_url "languages"
|
|
15
26
|
end
|
|
16
27
|
|
|
17
|
-
|
|
18
|
-
|
|
28
|
+
def maps
|
|
29
|
+
Proxy.new self, "maps"
|
|
19
30
|
end
|
|
20
31
|
|
|
21
|
-
def
|
|
22
|
-
|
|
32
|
+
def profile_icons params={}
|
|
33
|
+
all "profile_icons", params
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def realms
|
|
37
|
+
Proxy.new self, "realms"
|
|
23
38
|
end
|
|
24
39
|
|
|
25
40
|
def versions
|
|
26
|
-
Proxy.new self,
|
|
41
|
+
Proxy.new self, "versions"
|
|
27
42
|
end
|
|
28
43
|
|
|
29
44
|
def get(endpoint, id=nil, params={})
|
|
30
|
-
return perform_request(api_url("versions"))
|
|
45
|
+
return perform_request(api_url("versions")) if endpoint == "versions"
|
|
31
46
|
id ? find(endpoint, id, params) : all(endpoint, params)
|
|
32
47
|
end
|
|
33
48
|
|
|
34
49
|
private
|
|
35
50
|
|
|
36
51
|
def find(endpoint, id, params={})
|
|
37
|
-
|
|
52
|
+
OpenStruct.new \
|
|
38
53
|
perform_request(api_url("#{endpoint.dasherize}/#{id}", params)).to_hash
|
|
39
54
|
end
|
|
40
55
|
|
|
41
56
|
def all(endpoint, params={})
|
|
42
|
-
if %w(
|
|
43
|
-
|
|
57
|
+
if %w(realms).include? endpoint
|
|
58
|
+
OpenStruct.new perform_request(api_url(endpoint.dasherize, params)).to_hash
|
|
44
59
|
else
|
|
45
60
|
perform_request(api_url(endpoint.dasherize, params))["data"].map do |id, values|
|
|
46
|
-
|
|
61
|
+
OpenStruct.new(values.merge(id: values["id"] || id))
|
|
47
62
|
end
|
|
48
63
|
end
|
|
49
64
|
end
|
|
50
65
|
|
|
51
|
-
def model_class(endpoint)
|
|
52
|
-
OpenStruct
|
|
53
|
-
end
|
|
54
|
-
|
|
55
66
|
class Proxy
|
|
56
67
|
def initialize(request, endpoint)
|
|
57
68
|
@request = request
|
data/lib/lol/summoner_request.rb
CHANGED
|
@@ -1,62 +1,33 @@
|
|
|
1
1
|
module Lol
|
|
2
|
+
# Bindings for the Summoner API.
|
|
3
|
+
#
|
|
4
|
+
# See: https://developer.riotgames.com/api-methods/#summoner-v3
|
|
2
5
|
class SummonerRequest < Request
|
|
3
|
-
#
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"v1.4"
|
|
6
|
+
# @!visibility private
|
|
7
|
+
def api_base_path
|
|
8
|
+
"/lol/summoner/#{self.class.api_version}"
|
|
7
9
|
end
|
|
8
10
|
|
|
9
|
-
#
|
|
10
|
-
# @param [
|
|
11
|
-
# @return [
|
|
12
|
-
def
|
|
13
|
-
|
|
14
|
-
perform_request(api_url("summoner/by-name/#{escaped_names.join(",")}")).map do |key, data|
|
|
15
|
-
Summoner.new data
|
|
16
|
-
end
|
|
11
|
+
# Get a summoner by summoner ID.
|
|
12
|
+
# @param [Integer] id Summoner ID
|
|
13
|
+
# @return [DynamicModel] Summoner representation
|
|
14
|
+
def find id
|
|
15
|
+
DynamicModel.new perform_request api_url "summoners/#{id}"
|
|
17
16
|
end
|
|
18
17
|
|
|
19
|
-
# Get
|
|
20
|
-
# @param [
|
|
21
|
-
# @return [
|
|
22
|
-
def name
|
|
23
|
-
|
|
18
|
+
# Get a summoner by summoner name.
|
|
19
|
+
# @param [String] name Summoner name
|
|
20
|
+
# @return [DynamicModel] Summoner representation
|
|
21
|
+
def find_by_name name
|
|
22
|
+
name = CGI.escape name.downcase.gsub(/\s/, '')
|
|
23
|
+
DynamicModel.new perform_request api_url "summoners/by-name/#{name}"
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
# Get a
|
|
27
|
-
# @param [
|
|
28
|
-
# @return [
|
|
29
|
-
def
|
|
30
|
-
perform_request
|
|
31
|
-
Summoner.new data
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# Get rune pages by summoner ID
|
|
36
|
-
# @param [Array] summoner_ids
|
|
37
|
-
# @return [Array] array of Lol::RunePage
|
|
38
|
-
def runes *summoner_ids
|
|
39
|
-
extract_pages RunePage, "runes", summoner_ids
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Get mastery pages by summoner ID
|
|
43
|
-
# @param [Array] summoner_ids
|
|
44
|
-
# @return [Array] array of Lol::MasteryPage
|
|
45
|
-
def masteries *summoner_ids
|
|
46
|
-
extract_pages MasteryPage, "masteries", summoner_ids
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
private
|
|
50
|
-
|
|
51
|
-
# Extract pages by summoner ID
|
|
52
|
-
# @param klass [Class] class used to instance objects in arrays
|
|
53
|
-
# @param page_type [String] path of the request
|
|
54
|
-
# @param *summoner_ids [Array] array of summoner_ids
|
|
55
|
-
def extract_pages klass, page_type, *summoner_ids
|
|
56
|
-
perform_request(api_url("summoner/#{summoner_ids.join(",")}/#{page_type}")).inject({}) do |ack, data|
|
|
57
|
-
ack[data.first] = data.last["pages"].map {|m| klass.new m}
|
|
58
|
-
ack
|
|
59
|
-
end
|
|
26
|
+
# Get a summoner by account ID.
|
|
27
|
+
# @param [Integer] account_id Account ID
|
|
28
|
+
# @return [DynamicModel] Summoner representation
|
|
29
|
+
def find_by_account_id account_id
|
|
30
|
+
DynamicModel.new perform_request api_url "summoners/by-account/#{account_id}"
|
|
60
31
|
end
|
|
61
32
|
end
|
|
62
33
|
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
module Lol
|
|
2
|
+
class TournamentRequest < Request
|
|
3
|
+
# @!visibility private
|
|
4
|
+
def api_base_path
|
|
5
|
+
"/lol/tournament/#{self.class.api_version}"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# @!visibility private
|
|
9
|
+
def api_base_url
|
|
10
|
+
"https://global.api.riotgames.com"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Creates a tournament provider and returns its ID.
|
|
14
|
+
# @param [String] url The provider's callback URL to which tournament game results in this region should be posted. The URL must be well-formed, use the http or https protocol, and use the default port for the protocol
|
|
15
|
+
# @return [Integer] Provider ID
|
|
16
|
+
def create_provider url:
|
|
17
|
+
body = {
|
|
18
|
+
"url" => url,
|
|
19
|
+
"region" => region.upcase
|
|
20
|
+
}
|
|
21
|
+
perform_request api_url("providers"), :post, body
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Creates a tournament and returns its ID.
|
|
25
|
+
# @param [Integer] provider_id The provider ID to specify the regional registered provider data to associate this tournament.
|
|
26
|
+
# @param [String] name Name of the tournament
|
|
27
|
+
# @return [Integer] Tournament ID
|
|
28
|
+
def create_tournament provider_id:, name: nil
|
|
29
|
+
body = {
|
|
30
|
+
"providerId" => provider_id,
|
|
31
|
+
"name" => name
|
|
32
|
+
}.compact
|
|
33
|
+
perform_request api_url("tournaments"), :post, body
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Create a tournament code for the given tournament.
|
|
37
|
+
# @param [Integer] count The number of codes to create (max 1000)
|
|
38
|
+
# @param [Integer] tournament_id The tournament ID
|
|
39
|
+
# @param [String] spectator_type The spectator type of the game. Valid values are NONE, LOBBYONLY, ALL.
|
|
40
|
+
# @param [Integer] team_size The team size of the game. Valid values are 1-5.
|
|
41
|
+
# @param [String] pick_type The pick type of the game. Valid values are BLIND_PICK, DRAFT_MODE, ALL_RANDOM, TOURNAMENT_DRAFT.
|
|
42
|
+
# @param [String] map_type The map type of the game. Valid values are SUMMONERS_RIFT, TWISTED_TREELINE, CRYSTAL_SCAR, and HOWLING_ABYSS.
|
|
43
|
+
# @param [Array<Integer>] allowed_participants List of participants in order to validate the players eligible to join the lobby.
|
|
44
|
+
# @param [String] metadata Optional string that may contain any data in any format, if specified at all. Used to denote any custom information about the game.
|
|
45
|
+
# @return [Array<String>] generated tournament codes
|
|
46
|
+
def create_codes tournament_id:, count: nil, allowed_participants: nil,
|
|
47
|
+
map_type: "SUMMONERS_RIFT", metadata: nil, team_size: 5,
|
|
48
|
+
pick_type: "TOURNAMENT_DRAFT", spectator_type: "ALL"
|
|
49
|
+
body = {
|
|
50
|
+
"allowedParticipants" => allowed_participants,
|
|
51
|
+
"mapType" => map_type,
|
|
52
|
+
"metadata" => metadata,
|
|
53
|
+
"pickType" => pick_type,
|
|
54
|
+
"spectatorType" => spectator_type,
|
|
55
|
+
"teamSize" => team_size
|
|
56
|
+
}.compact
|
|
57
|
+
uri_params = {
|
|
58
|
+
"tournamentId" => tournament_id,
|
|
59
|
+
"count" => count
|
|
60
|
+
}.compact
|
|
61
|
+
perform_request api_url("codes", uri_params), :post, body
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Update the pick type, map, spectator type, or allowed summoners for a code.
|
|
65
|
+
# @param [String] tournament_code The tournament code to update
|
|
66
|
+
# @param [Array<Integer>] allowed_participants List of participants in order to validate the players eligible to join the lobby.
|
|
67
|
+
# @param [String] map_type The map type of the game. Valid values are SUMMONERS_RIFT, TWISTED_TREELINE, CRYSTAL_SCAR, and HOWLING_ABYSS.
|
|
68
|
+
# @param [String] pick_type The pick type of the game. Valid values are BLIND_PICK, DRAFT_MODE, ALL_RANDOM, TOURNAMENT_DRAFT.
|
|
69
|
+
# @param [String] spectator_type The spectator type of the game. Valid values are NONE, LOBBYONLY, ALL.
|
|
70
|
+
def update_code tournament_code, allowed_participants: nil, map_type: nil, pick_type: nil, spectator_type: nil
|
|
71
|
+
body = {
|
|
72
|
+
"allowedParticipants" => allowed_participants,
|
|
73
|
+
"mapType" => map_type,
|
|
74
|
+
"pickType" => pick_type,
|
|
75
|
+
"spectatorType" => spectator_type
|
|
76
|
+
}.compact
|
|
77
|
+
perform_request api_url("codes/#{tournament_code}"), :put, body
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Returns the tournament code details
|
|
81
|
+
# @param [String] tournament_code the tournament code string
|
|
82
|
+
# @return [DynamicModel] A tournament code representation
|
|
83
|
+
def find_code tournament_code
|
|
84
|
+
DynamicModel.new perform_request api_url "codes/#{tournament_code}"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Gets a list of lobby events by tournament code
|
|
88
|
+
# @param [String] tournament_code the tournament code string
|
|
89
|
+
# @return [Array<DynamicModel>] List of lobby events
|
|
90
|
+
def all_lobby_events tournament_code:
|
|
91
|
+
result = perform_request api_url "lobby-events/by-code/#{tournament_code}"
|
|
92
|
+
result["eventList"].map { |e| DynamicModel.new e }
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|