ruby-lol 0.12.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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
- # Returns the supported API Version
4
- # @return [String] the supported api version
5
- def self.api_version
6
- "v2.2"
6
+ # @!visibility private
7
+ def api_base_path
8
+ "/lol/match/#{self.class.api_version}"
7
9
  end
8
10
 
9
- # Returns a match with the given id
10
- # @param match_id [Fixnum] Match ID
11
- # @return [Hash] match object
12
- def get match_id
13
- perform_request(api_url("match/#{match_id}"))
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
@@ -24,22 +24,71 @@ module Lol
24
24
  # @return [Object] the cache_store
25
25
  attr_reader :cache_store
26
26
 
27
- # Stub method. Each subclass should have its own api version
28
- # @return [String] api version
27
+ # Returns the supported API Version.
28
+ # @return [String] v3
29
29
  def self.api_version
30
- "v1.1"
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 = "#{api_base_url}/api/lol/#{region}/#{self.class.api_version}/#{path}"
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://#{region}.api.pvp.net"
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 [Fixnum] the ttl to apply to cached keys
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
@@ -1,57 +1,68 @@
1
1
  module Lol
2
2
  class StaticRequest < Request
3
- STANDARD_ENDPOINTS = %w(champion item mastery rune summoner_spell)
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 self.api_version
6
- "v1.2"
20
+ def language_strings params={}
21
+ perform_request(api_url "language-strings", params).to_hash["data"]
7
22
  end
8
23
 
9
- # Returns a full url for an API call
10
- # Overrides api_url from Request
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
- STANDARD_ENDPOINTS.each do |endpoint|
18
- define_method(endpoint) { Proxy.new self, endpoint }
28
+ def maps
29
+ Proxy.new self, "maps"
19
30
  end
20
31
 
21
- def realm
22
- Proxy.new self, 'realm'
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, 'versions'
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")).map {|x| x} if endpoint == "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
- model_class(endpoint).new \
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(realm).include? endpoint
43
- model_class(endpoint).new perform_request(api_url(endpoint.dasherize, params)).to_hash
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
- model_class(endpoint).new(values.merge(id: values["id"] || id))
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
@@ -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
- # Returns the supported API Version
4
- # @return [String] the supported api version
5
- def self.api_version
6
- "v1.4"
6
+ # @!visibility private
7
+ def api_base_path
8
+ "/lol/summoner/#{self.class.api_version}"
7
9
  end
8
10
 
9
- # Looks for a summoner name and returns the associated summoner
10
- # @param [Array] summoner names
11
- # @return [Array] matching summoners
12
- def by_name *names
13
- escaped_names = names.flatten.map { |name| CGI.escape name.downcase.gsub(/\s/, '') }
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 list of summoner names by summoner IDs
20
- # @param [Array] summoner_ids
21
- # @return [Hash] Hash in the form { "id" => "name" }
22
- def name *summoner_ids
23
- perform_request(api_url("summoner/#{summoner_ids.join(",")}/name"))
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 list of summoners by summoner ID
27
- # @param [Array] summoner_ids
28
- # @return [Array] matching summoners
29
- def get *summoner_ids
30
- perform_request(api_url("summoner/#{summoner_ids.join(",")}")).map do |key, data|
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