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,4 +1,4 @@
1
- rvm: 2.2.5
1
+ rvm: 2.4
2
2
  services: redis-server
3
3
  addons:
4
4
  code_climate:
@@ -1,68 +1,40 @@
1
1
  module Lol
2
+ # Bindings for the Champion Mastery API.
3
+ #
4
+ # See: https://developer.riotgames.com/api-methods/#champion-mastery-v3
2
5
  class ChampionMasteryRequest < Request
3
- # Returns the supported API Version. ChampionMastery end point is not
4
- # versioned, so just return v1.0 anyway
5
- # @return [String] v1.0 (ChampionMastery end point is not versioned)
6
- def self.api_version
7
- 'v1.0'
6
+ # @!visibility private
7
+ def api_base_path
8
+ "/lol/champion-mastery/#{api_version}"
8
9
  end
9
10
 
10
- # Retrieve champion mastery information for a specific champion
11
- # @param [FixNum] player_id id of player
12
- # @param [FixNum] champion_id id of champion
13
- # @return [ChampionMastery] champion mastery information
14
- def champion player_id, champion_id
15
- url = "player/#{player_id}/champion/#{champion_id}"
16
- result = perform_request(api_url(url))
17
-
18
- ChampionMastery.new(result)
19
- end
20
-
21
- # Retrieve champion mastery information for all champion
22
- # @param [FixNum] player_id id of player
23
- # @return [Array] array of champion mastery information
24
- def champions player_id
25
- url = "player/#{player_id}/champions"
26
- result = perform_request(api_url(url))
27
- result.map { |c| ChampionMastery.new(c) }
28
- end
29
-
30
- # Get a player's total champion mastery score, which is sum of individual champion mastery levels
31
- # @param [FixNum] player_id id of player
32
- # @return [FixNum] Players mastery score
33
- def score player_id
34
- url = "player/#{player_id}/score"
35
- perform_request(api_url(url)).to_i
36
- end
37
-
38
- # Get specified number of top champion mastery entries sorted by number of champion points descending
39
- # @param [FixNum] player_id id of player
40
- # @option options [Fixnum] :count the number of mastery scores to get. Defaults to 3
41
- # @return [Array] array of champion mastery information, sorted by number of champion points descending
42
- def top_champions player_id, options = {}
43
- if options.keys.select { |k| k.to_sym != :count }.any?
44
- raise ArgumentError, 'Only :count is allowed as extra parameter'
45
- end
46
- url = "player/#{player_id}/topchampions"
47
- url = api_url(url, options)
48
- result = perform_request(url)
49
- result.map { |c| ChampionMastery.new(c) }
11
+ # Get a player's total champion mastery score, which is the sum of individual champion mastery levels
12
+ #
13
+ # See: https://developer.riotgames.com/api-methods/#champion-mastery-v3/GET_getDynamicModelScore
14
+ # @param [Integer] summoner_id Summoner ID associated with the player
15
+ # @return [Integer] Player's total champion master score
16
+ def total_score summoner_id:
17
+ perform_request api_url "scores/by-summoner/#{summoner_id}"
50
18
  end
51
19
 
52
- # Returns a full url for an API call
53
- # @param path [String] API path to call
54
- # @return [String] full fledged url
55
- def api_url path, params = {}
56
- url = "#{api_base_url}/championmastery/location/#{region_to_platform(region)}/#{path}"
57
- "#{url}?#{api_query_string params}"
20
+ # Get all champion mastery entries sorted by number of champion points descending
21
+ #
22
+ # See: https://developer.riotgames.com/api-methods/#champion-mastery-v3/GET_getAllChampionMasteries
23
+ # @param [Integer] summoner_id Summoner ID associated with the player
24
+ # @return [Array<Lol::DynamicModel>] Champion Masteries
25
+ def all summoner_id:
26
+ result = perform_request api_url "champion-masteries/by-summoner/#{summoner_id}"
27
+ result.map { |c| DynamicModel.new c }
58
28
  end
59
29
 
60
- private
61
-
62
- #A hash mapping a region to the platform, since the ChampionMastery endpoint uses a platform and not a region
63
- def region_to_platform(region)
64
- { br: 'BR1', eune: 'EUN1', euw: 'EUW1', jp: 'JP1', kr: 'KR1', lan: 'LA1', las: 'LA2',
65
- na: 'NA1', oce: 'OC1', ru: 'RU', tr: 'TR1' }[region.to_sym]
30
+ # Get a champion mastery by player ID and champion ID
31
+ #
32
+ # See: https://developer.riotgames.com/api-methods/#champion-mastery-v3/GET_getDynamicModel
33
+ # @param [Integer] summoner_id Summoner ID associated with the player
34
+ # @return [Lol::DynamicModel] Champion Mastery
35
+ def find champion_id, summoner_id:
36
+ result = perform_request api_url "champion-masteries/by-summoner/#{summoner_id}/by-champion/#{champion_id}"
37
+ DynamicModel.new result
66
38
  end
67
39
  end
68
40
  end
@@ -1,30 +1,26 @@
1
1
  module Lol
2
+ # Bindings for the Champion API.
3
+ #
4
+ # See: https://developer.riotgames.com/api-methods/#champion-v3
2
5
  class ChampionRequest < Request
3
- # Returns the supported API Version
4
- # @return [String] the supported api version
5
- def self.api_version
6
- "v1.2"
7
- end
8
-
9
6
  # Retrieve all champions
10
- # @param [Hash] options the options to pass to the call
11
- # @option options [Fixnum] :id the champion to get. If nil gets all champions
12
- # @option options [Boolean] :free_to_play filters for free to play champions
13
- # @return [Array] an array of champions
14
- def get options = {}
15
-
16
- champion_id = options.delete :id
17
- free_to_play = options.delete(:free_to_play) ? true : false
18
-
19
- url = champion_id ? "champion/#{champion_id}" : "champion"
20
- result = perform_request(api_url(url, "freeToPlay" => free_to_play))
21
-
22
- if champion_id
23
- Champion.new(result)
24
- else
25
- result["champions"].map {|c| Champion.new(c)}
26
- end
7
+ #
8
+ # See: https://developer.riotgames.com/api-methods/#champion-v3/GET_getChampions
9
+ # @param free_to_play [Boolean] filter param to retrieve only free to play champions
10
+ # @return [Array<Lol::DynamicModel>] an array of champions
11
+ def all free_to_play: false
12
+ result = perform_request api_url("champions", "freeToPlay" => free_to_play)
13
+ result["champions"].map { |c| DynamicModel.new c }
27
14
  end
28
15
 
16
+ # Retrieve champion by ID
17
+ #
18
+ # See: https://developer.riotgames.com/api-methods/#champion-v3/GET_getChampionsById
19
+ # @param id [Integer] id of the champion to get
20
+ # @return [Lol::DynamicModel] the found champion
21
+ def find id
22
+ result = perform_request api_url "champions/#{id}"
23
+ DynamicModel.new result
24
+ end
29
25
  end
30
26
  end
@@ -10,7 +10,7 @@ module Lol
10
10
  attr_reader :api_key
11
11
 
12
12
  # @!attribute [r] ttl
13
- # @return [Fixnum] the ttl on cached requests
13
+ # @return [Integer] the ttl on cached requests
14
14
  attr_reader :ttl
15
15
 
16
16
  # @return [ChampionRequest]
@@ -23,34 +23,29 @@ module Lol
23
23
  @champion_mastery_request ||= ChampionMasteryRequest.new(api_key, region, cache_store)
24
24
  end
25
25
 
26
- # @return [GameRequest]
27
- def game
28
- @game_request ||= GameRequest.new(api_key, region, cache_store)
29
- end
30
-
31
26
  # @return [MatchRequest]
32
27
  def match
33
28
  @match_request ||= MatchRequest.new(api_key, region, cache_store)
34
29
  end
35
30
 
36
- # @return [MatchListRequest]
37
- def match_list
38
- @match_history_request ||= MatchListRequest.new(api_key, region, cache_store)
31
+ # @return [LeagueRequest]
32
+ def league
33
+ @league_request ||= LeagueRequest.new(api_key, region, cache_store)
39
34
  end
40
35
 
41
- # @return [StatsRequest]
42
- def stats
43
- @stats_request ||= StatsRequest.new(api_key, region, cache_store)
36
+ # @return [RunesRequest]
37
+ def runes
38
+ @runes_request ||= RunesRequest.new(api_key, region, cache_store)
44
39
  end
45
40
 
46
- # @return [LeagueRequest]
47
- def league
48
- @league_request ||= LeagueRequest.new(api_key, region, cache_store)
41
+ # @return [MasteriesRequest]
42
+ def masteries
43
+ @masteries_request ||= MasteriesRequest.new(api_key, region, cache_store)
49
44
  end
50
45
 
51
- # @return [TeamRequest]
52
- def team
53
- @team_request ||= TeamRequest.new(api_key, region, cache_store)
46
+ # @return [SpectatorRequest]
47
+ def spectator
48
+ @spectator_request ||= SpectatorRequest.new(api_key, region, cache_store)
54
49
  end
55
50
 
56
51
  # @return [SummonerRequest]
@@ -65,7 +60,7 @@ module Lol
65
60
 
66
61
  # @return [LolStatusRequest]
67
62
  def lol_status
68
- @lol_status ||= LolStatusRequest.new(region, cache_store)
63
+ @lol_status ||= LolStatusRequest.new(api_key, region, cache_store)
69
64
  end
70
65
 
71
66
  # @return [CurrentGameRequest]
@@ -80,7 +75,7 @@ module Lol
80
75
 
81
76
  # @return [TournamentProviderRequest]
82
77
  def tournament
83
- @tournament ||= TournamentProviderRequest.new(api_key, region, cache_store)
78
+ @tournament ||= TournamentRequest.new(api_key, region, cache_store)
84
79
  end
85
80
 
86
81
  # Initializes a Lol::Client
@@ -88,7 +83,7 @@ module Lol
88
83
  # @param options [Hash]
89
84
  # @option options [String] :region ("EUW") The region on which the requests will be made
90
85
  # @option options [String] :redis the redis url to use for caching
91
- # @option options [Fixnum] :ttl (900) the cache ttl
86
+ # @option options [Integer] :ttl (900) the cache ttl
92
87
  # @return [Lol::Client]
93
88
  def initialize api_key, options = {}
94
89
  @api_key = api_key
@@ -6,8 +6,11 @@ module Lol
6
6
  # - nested generation ({a: {}}) results in DynamicModel(a: DynamicModel)
7
7
  # - parsing of date/time when property name ends with _at or _date and the value is a number
8
8
  class DynamicModel < OpenStruct
9
+ attr_reader :raw
10
+
9
11
  def initialize(hash={})
10
12
  raise ArgumentError, 'An hash is required as parameter' unless hash.is_a? Hash
13
+ @raw = hash
11
14
  @table = {}
12
15
  @hash_table = {}
13
16
 
@@ -26,6 +29,12 @@ module Lol
26
29
  @table.as_json
27
30
  end
28
31
 
32
+ protected
33
+
34
+ def class_for_property property
35
+ self.class
36
+ end
37
+
29
38
  private
30
39
 
31
40
  def date_key? key
@@ -33,10 +42,10 @@ module Lol
33
42
  end
34
43
 
35
44
  def set_property key, v
36
- if date_key?(key) && v.is_a?(Fixnum)
45
+ if date_key?(key) && v.is_a?(Integer)
37
46
  @table[key.to_sym] = @hash_table[key.to_sym] = value_to_date v
38
47
  else
39
- @table[key.to_sym] = convert_object v
48
+ @table[key.to_sym] = convert_object v, property: key.to_sym
40
49
  @hash_table[key.to_sym] = v
41
50
  end
42
51
  end
@@ -45,11 +54,11 @@ module Lol
45
54
  Time.at(v / 1000)
46
55
  end
47
56
 
48
- def convert_object obj
57
+ def convert_object obj, property:
49
58
  if obj.is_a? Hash
50
- self.class.new obj
59
+ class_for_property(property).new obj
51
60
  elsif obj.respond_to?(:map)
52
- obj.map { |o| convert_object o }
61
+ obj.map { |o| convert_object o, property: property }
53
62
  else
54
63
  obj
55
64
  end
@@ -0,0 +1,15 @@
1
+ module Lol
2
+ # List of featured games
3
+ #
4
+ # Each contained featured game is represented through {DynamicModel}
5
+ class FeaturedGameList < Array
6
+ # The suggested interval to wait before requesting FeaturedGames again
7
+ # @return [Integer]
8
+ attr_reader :client_refresh_interval
9
+
10
+ def initialize data
11
+ @client_refresh_interval = data['clientRefreshInterval']
12
+ super data['gameList'].map { |g| DynamicModel.new g }
13
+ end
14
+ end
15
+ end
@@ -1,62 +1,41 @@
1
1
  module Lol
2
+ # Bindings for the League API.
3
+ #
4
+ # See: https://developer.riotgames.com/api-methods/#league-v3
2
5
  class LeagueRequest < Request
3
- # Returns the supported API Version
4
- # @return [String] the supported api version
5
- def self.api_version
6
- "v2.5"
6
+ # @!visibility private
7
+ def api_base_path
8
+ "/lol/league/#{api_version}"
7
9
  end
8
10
 
9
- # Retrieves leagues data for summoner, including leagues for all of summoner's teams
10
- # @param [Array<String>]
11
- # @return Hash{String => Array<League>}
12
- def get(*summoner_ids)
13
- perform_league_request("league/by-summoner/#{summoner_ids.join(",")}")
11
+ # Get the challenger league for a given queue
12
+ # @param [String] queue Queue identifier. See the list of game constants (developer.riotgames.com/game-constants.html) for the available queue identifiers
13
+ # @return [DynamicModel] Challenger league
14
+ def find_challenger queue: 'RANKED_SOLO_5x5'
15
+ DynamicModel.new perform_request api_url "challengerleagues/by-queue/#{queue}"
14
16
  end
15
17
 
16
- # Retrieves leagues entry data for summoner, including league entries for all of summoner's teams
17
- # @param [Array<String>]
18
- # @return Hash{String => Array<League>}
19
- # TODO: Change name to entries?
20
- def get_entries(*summoner_ids)
21
- perform_league_request("league/by-summoner/#{summoner_ids.join(',')}/entry")
18
+ # Get the master league for a given queue
19
+ # @param [String] queue Queue identifier. See the list of game constants (developer.riotgames.com/game-constants.html) for the available queue identifiers
20
+ # @return [DynamicModel] lMaster league
21
+ def find_master queue: 'RANKED_SOLO_5x5'
22
+ DynamicModel.new perform_request api_url "masterleagues/by-queue/#{queue}"
22
23
  end
23
24
 
24
- # Retrieves leagues data for team
25
- # @param [Array<String>]
26
- # @return Hash{String => Array<League>}
27
- def by_team(*team_ids)
28
- perform_league_request("league/by-team/#{team_ids.join(',')}")
25
+ # Get leagues in all queues for a given summoner ID
26
+ # @param [Integer] summoner_id Summoner ID associated with the player
27
+ # @return [Array<DynamicModel>] List of leagues summoner is participating in
28
+ def summoner_leagues summoner_id:
29
+ result = perform_request api_url "leagues/by-summoner/#{summoner_id}"
30
+ result.map { |c| DynamicModel.new c }
29
31
  end
30
32
 
31
- # Retrieves leagues entry data for team
32
- # @param [Array<String>]
33
- # @return Hash{String => Array<League>}
34
- # TODO: Change name to?
35
- def entries_by_team(*team_ids)
36
- perform_league_request("league/by-team/#{team_ids.join(',')}/entry")
33
+ # Get league positions in all queues for a given summoner ID
34
+ # @param [Integer] summoner_id Summoner ID associated with the player
35
+ # @return [Array<DynamicModel>] list of league positions
36
+ def summoner_positions summoner_id:
37
+ result = perform_request api_url "positions/by-summoner/#{summoner_id}"
38
+ result.map { |c| DynamicModel.new c }
37
39
  end
38
-
39
- # Retrieves challenger tier leagues
40
- # @param [String] game queue type
41
- # @return [League]
42
- def challenger(game_queue_type="RANKED_SOLO_5x5")
43
- league_json = perform_request(api_url('league/challenger', { :type => game_queue_type }))
44
- League.new(league_json)
45
- end
46
-
47
- def master(game_queue_type="RANKED_SOLO_5x5")
48
- league_json = perform_request(api_url('league/master', { :type => game_queue_type }))
49
- League.new(league_json)
50
- end
51
-
52
- private
53
-
54
- def perform_league_request(partial_url)
55
- url = api_url(partial_url)
56
- perform_request(url).each_with_object({}) do |(summoner_id, leagues), entries_hash|
57
- entries_hash[summoner_id] = leagues.map(&League.method(:new))
58
- end
59
- end
60
-
61
40
  end
62
41
  end
@@ -1,34 +1,17 @@
1
1
  module Lol
2
+ # Bindings for the Status API.
3
+ #
4
+ # See: https://developer.riotgames.com/api-methods/#lol-status-v3
2
5
  class LolStatusRequest < Request
3
-
4
- def self.api_version
5
- "v1.0"
6
- end
7
-
8
- def initialize region = nil, cache_store = {}
9
- super nil, region, cache_store
6
+ # @!visibility private
7
+ def api_base_path
8
+ "/lol/status/#{self.class.api_version}"
10
9
  end
11
10
 
12
- # Returns a list of each shard status
13
- # This special call works against all regions
14
- # @return [Array] an array of DynamicModel representing the response
15
- def shards
16
- perform_request(api_url('shards')).map do |shard_data|
17
- DynamicModel.new shard_data
18
- end
19
- end
20
-
21
- # Returns a detailed status of the current shard
11
+ # Get League of Legends status for the given shard
22
12
  # @return [DynamicModel]
23
- def current_shard
24
- shard_data = perform_request(api_url('shards', region))
25
- DynamicModel.new shard_data
26
- end
27
-
28
- def api_url path, params = {}
29
- "http://status.leagueoflegends.com/#{path}".tap do |url|
30
- url << "/#{params}" unless params.empty?
31
- end
13
+ def shard_data
14
+ DynamicModel.new perform_request api_url "shard-data"
32
15
  end
33
16
  end
34
17
  end
@@ -0,0 +1,14 @@
1
+ module Lol
2
+ # Bindings for the Masteries API.
3
+ #
4
+ # See: https://developer.riotgames.com/api-methods/#masteries-v3
5
+ class MasteriesRequest < Request
6
+ # Get mastery pages for a given summoner ID
7
+ # @param [Integer] summoner_id Summoner ID
8
+ # @return [Array<DynamicModel>] Mastery pages
9
+ def by_summoner_id summoner_id
10
+ result = perform_request api_url "masteries/by-summoner/#{summoner_id}"
11
+ result["pages"].map { |p| DynamicModel.new p }
12
+ end
13
+ end
14
+ end