taric 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c0fdb566e176d431e051afd9ffecebc2ddcd13c
4
- data.tar.gz: 6212b36f3c1ad25fae66445b8b87157a817c5b55
3
+ metadata.gz: b7a9d60cdc1626c16ab351a1a52aadf2bf4d14f8
4
+ data.tar.gz: 8e1db1127f7368f24dac5ce9fd5fb150121b7d94
5
5
  SHA512:
6
- metadata.gz: 9861731d289437dae1d24db2b97e80116c09277c35e482ef5895228866e3010447499e6b85911ce53d6e920e246efc4de9460c0557d109af95da154602088cfb
7
- data.tar.gz: 9b4f75b171d2dcb125ca8d702615c7a8b8c47501d35e022a3962a4a03901fb6ab0459c748bbadc34a621dea81fd7dc9f85ae1ac33752d468b823947fb1b158aa
6
+ metadata.gz: d8ed16acc7ddb6402f0a63ef513f04a98ffadc1495b23cddb9e6febed8450b2220f951727796654b4969313aa0371e8c31c58688e6b65c1af58d9fe0f00cc2b3
7
+ data.tar.gz: c02e95331afd622485dc3560f0940c235291d541f02aacea4eec8af8074c4ddfd8dec4dab690f274c32f6172fcee332266a7efabaadba4cb06d28d97e5d1ef31
@@ -67,7 +67,7 @@ module Taric
67
67
  # @param region [Symbol] key for region
68
68
  # @param operation [Addressable::Template] URI template for operation
69
69
  # @param options [Hash] optional, values for template
70
- # @return [Addressable::URI] of expanded template
70
+ # @return [String] of expanded template
71
71
  #
72
72
  # @example
73
73
  # Taric::Client.expand_template(api_key: 'ritokey', region: :na, operation: Taric::Operation::Champion::CHAMPIONS)
@@ -78,9 +78,9 @@ module Taric
78
78
 
79
79
  private
80
80
  def response_for(operation, options = {})
81
- -> url {
82
- API_CALL.(url: url, requestor: @config.requestor.(@conn), response_handler: @config.response_handler)
83
- }.(self.class.expand_template(api_key: @api_key, region: @region, operation: operation, options: options))
81
+ -> (method, url, body, headers) {
82
+ API_CALL.(method, url, body, headers, @config.requestor.(@conn), @config.response_handler)
83
+ }.(operation.method, self.class.expand_template(api_key: @api_key, region: @region, operation: operation.template_url, options: options), operation.body, operation.headers)
84
84
  end
85
85
 
86
86
  class ParallelClient
@@ -101,13 +101,13 @@ module Taric
101
101
  -> responses {
102
102
  @operations.clear
103
103
  responses
104
- }.(API_CALL.(url: @operations, requestor: @parent.config.parallel_requestor.(@parent.conn), response_handler: @parent.config.parallel_response_handler))
104
+ }.(@parent.config.parallel_response_handler.(@parent.config.parallel_requestor.(@parent.conn, @operations)))
105
105
  end
106
106
 
107
107
  private
108
108
 
109
109
  def response_for(operation, options = {})
110
- @operations << @parent.class.expand_template(api_key: @parent.api_key, region: @parent.region, operation: operation, options: options)
110
+ @operations << {url: @parent.class.expand_template(api_key: @parent.api_key, region: @parent.region, operation: operation.template_url, options: options), method: operation.method, body: operation.body, headers: operation.headers}
111
111
  self
112
112
  end
113
113
 
@@ -2,16 +2,16 @@ module Taric
2
2
  class Configuration
3
3
  attr_accessor :api_key, :format, :user_agent, :connection_opts, :adapter, :region, :requestor, :response_handler, :parallel_requestor, :parallel_response_handler, :raw
4
4
 
5
- DEFAULT_REQUESTOR = -> connection, url {
6
- connection.get url
5
+ DEFAULT_REQUESTOR = -> (connection, method, url, body, headers) {
6
+ connection.send(method, url, body, headers)
7
7
  }.curry
8
8
 
9
9
  DEFAULT_RESPONSE_HANDLER = -> response {
10
10
  response
11
11
  }
12
12
 
13
- PARALLEL_REQUESTOR = -> connection, urls {
14
- urls.map{|url| connection.get url}
13
+ PARALLEL_REQUESTOR = -> connection, operations {
14
+ operations.map{|operation| connection.send(operation[:method], operation[:url], operation[:body], operation[:headers])}
15
15
  }.curry
16
16
 
17
17
  PARALLEL_RESPONSE_HANDLER = -> responses {
@@ -1,4 +1,5 @@
1
1
  require_relative 'champion'
2
+ require_relative 'champion_mastery'
2
3
  require_relative 'current_game'
3
4
  require_relative 'featured_games'
4
5
  require_relative 'game'
@@ -10,12 +11,14 @@ require_relative 'match_list'
10
11
  require_relative 'stats'
11
12
  require_relative 'summoner'
12
13
  require_relative 'team'
14
+ require_relative 'tournament'
13
15
 
14
16
  # Combines operations of LoL API.
15
17
  module Taric
16
18
  module Operation
17
19
  module API
18
20
  include Taric::Operation::Champion
21
+ include Taric::Operation::ChampionMastery
19
22
  include Taric::Operation::CurrentGame
20
23
  include Taric::Operation::FeaturedGames
21
24
  include Taric::Operation::Game
@@ -27,14 +30,15 @@ module Taric
27
30
  include Taric::Operation::Stats
28
31
  include Taric::Operation::Summoner
29
32
  include Taric::Operation::Team
33
+ include Taric::Operation::Tournament
30
34
 
31
35
  # Template for requesting the url and processing the response.
32
36
  #
33
37
  # @param url String
34
38
  # @param requestor Proc (lambda)
35
39
  # @param response_handler Proc (lambda)
36
- API_CALL = -> (url:, requestor:, response_handler:) {
37
- response_handler.(requestor.(url))
40
+ API_CALL = -> (method, url, body, headers, requestor, response_handler) {
41
+ response_handler.(requestor.(method, url, body, headers))
38
42
  }
39
43
 
40
44
  end
@@ -1,6 +1,7 @@
1
1
  module Taric
2
2
  module Operation
3
3
  module Base
4
+
4
5
  BASE_URL_FN = -> version {"https://{host}/api/lol/{region}/#{version}"}
5
6
 
6
7
  # Converts [Time] to [Fixnum], or returns argument.
@@ -1,5 +1,5 @@
1
1
  require_relative 'base'
2
- require 'addressable/template'
2
+ require_relative 'endpoint_template'
3
3
  module Taric
4
4
  module Operation
5
5
  module Champion
@@ -8,8 +8,8 @@ module Taric
8
8
  CHAMPION_VERSION = 'v1.2'.freeze
9
9
  CHAMPION_BASE_URL = "#{BASE_URL_FN.(CHAMPION_VERSION)}/champion"
10
10
 
11
- CHAMPIONS = Addressable::Template.new("#{CHAMPION_BASE_URL}{?api_key,freeToPlay}")
12
- CHAMPION_BY_ID = Addressable::Template.new("#{CHAMPION_BASE_URL}/{id}{?api_key}")
11
+ CHAMPIONS = EndpointTemplate.new(template_url: "#{CHAMPION_BASE_URL}{?api_key,freeToPlay}")
12
+ CHAMPION_BY_ID = EndpointTemplate.new(template_url: "#{CHAMPION_BASE_URL}/{id}{?api_key}")
13
13
 
14
14
  # Returns champion data.
15
15
  #
@@ -0,0 +1,30 @@
1
+ require_relative 'base'
2
+ module Taric
3
+ module Operation
4
+ module ChampionMastery
5
+ include Taric::Operation::Base
6
+
7
+ BASE_MASTERY_URL = "https://{host}/championmastery/location/{platform_id}/player"
8
+ MASTERY_BY_CHAMPION_ID = EndpointTemplate.new(template_url: "#{BASE_MASTERY_URL}/{summonerId}/champion/{championId}{?api_key}")
9
+ MASTERY_ALL_CHAMPIONS = EndpointTemplate.new(template_url: "#{BASE_MASTERY_URL}/{summonerId}/champions{?api_key}")
10
+ MASTERY_SCORE = EndpointTemplate.new(template_url: "#{BASE_MASTERY_URL}/{summonerId}/score{?api_key}")
11
+ MASTERY_TOP_CHAMPIONS = EndpointTemplate.new(template_url: "#{BASE_MASTERY_URL}/{summonerId}/topchampions{?api_key,count}")
12
+
13
+ def champion_mastery(summoner_id: , champion_id:)
14
+ response_for MASTERY_BY_CHAMPION_ID, {summonerId: summoner_id, championId: champion_id}
15
+ end
16
+
17
+ def champion_mastery_all(summoner_id: )
18
+ response_for MASTERY_ALL_CHAMPIONS, {summonerId: summoner_id}
19
+ end
20
+
21
+ def champion_mastery_score(summoner_id: )
22
+ response_for MASTERY_SCORE, {summonerId: summoner_id}
23
+ end
24
+
25
+ def top_champions(summoner_id: , count: 3)
26
+ response_for MASTERY_TOP_CHAMPIONS, {summonerId: summoner_id, count: count}
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,7 +1,8 @@
1
+ require_relative 'endpoint_template'
1
2
  module Taric
2
3
  module Operation
3
4
  module CurrentGame
4
- GAME_INFO = Addressable::Template.new 'https://{host}/observer-mode/rest/consumer/getSpectatorGameInfo/{platform_id}/{summonerId}{?api_key}'
5
+ GAME_INFO = EndpointTemplate.new(template_url: 'https://{host}/observer-mode/rest/consumer/getSpectatorGameInfo/{platform_id}/{summonerId}{?api_key}')
5
6
 
6
7
  # Returns current game data for summoner id.
7
8
  #
@@ -0,0 +1,15 @@
1
+ require 'addressable/template'
2
+
3
+ module Taric
4
+ module Operation
5
+ class EndpointTemplate
6
+ attr_accessor :template_url, :method, :body, :headers
7
+ def initialize(template_url:, method: :get, body: nil, headers: {})
8
+ @template_url = Addressable::Template.new(template_url)
9
+ @method = method
10
+ @body = body
11
+ @headers = headers
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,7 +1,8 @@
1
+ require_relative 'endpoint_template'
1
2
  module Taric
2
3
  module Operation
3
4
  module FeaturedGames
4
- FEATURED_GAMES = Addressable::Template.new 'https://{host}/observer-mode/rest/featured{?api_key}'
5
+ FEATURED_GAMES = EndpointTemplate.new(template_url:'https://{host}/observer-mode/rest/featured{?api_key}')
5
6
 
6
7
  # Returns featured games.
7
8
  #
@@ -1,11 +1,12 @@
1
1
  require_relative 'base'
2
+ require_relative 'endpoint_template'
2
3
  module Taric
3
4
  module Operation
4
5
  module Game
5
6
  include Taric::Operation::Base
6
7
 
7
8
  GAME_VERSION = 'v1.3'.freeze
8
- RECENT = Addressable::Template.new "#{BASE_URL_FN.(GAME_VERSION)}/game/by-summoner/{summonerId}/recent{?api_key}"
9
+ RECENT = EndpointTemplate.new(template_url:"#{BASE_URL_FN.(GAME_VERSION)}/game/by-summoner/{summonerId}/recent{?api_key}")
9
10
 
10
11
  # Returns recent game data for summoner id.
11
12
  #
@@ -1,5 +1,5 @@
1
1
  require_relative 'base'
2
- require 'addressable/template'
2
+ require_relative 'endpoint_template'
3
3
  module Taric
4
4
  module Operation
5
5
  module League
@@ -8,12 +8,12 @@ module Taric
8
8
  LEAGUE_VERSION = 'v2.5'
9
9
  BASE_LEAGUE_URL = "#{BASE_URL_FN.(LEAGUE_VERSION)}/league"
10
10
 
11
- LEAGUES_BY_SUMMONER_IDS = Addressable::Template.new "#{BASE_LEAGUE_URL}/by-summoner/{summonerIds}{?api_key}"
12
- ENTRIES_BY_SUMMONER_IDS = Addressable::Template.new "#{BASE_LEAGUE_URL}/by-summoner/{summonerIds}/entry{?api_key}"
13
- LEAGUES_BY_TEAM_IDS = Addressable::Template.new "#{BASE_LEAGUE_URL}/by-team/{teamIds}{?api_key}"
14
- ENTRIES_BY_TEAM_IDS = Addressable::Template.new "#{BASE_LEAGUE_URL}/by-team/{teamIds}/entry{?api_key}"
15
- CHALLENGER = Addressable::Template.new "#{BASE_LEAGUE_URL}/challenger{?api_key,type}"
16
- MASTER = Addressable::Template.new "#{BASE_LEAGUE_URL}/master{?api_key,type}"
11
+ LEAGUES_BY_SUMMONER_IDS = EndpointTemplate.new(template_url: "#{BASE_LEAGUE_URL}/by-summoner/{summonerIds}{?api_key}")
12
+ ENTRIES_BY_SUMMONER_IDS = EndpointTemplate.new(template_url: "#{BASE_LEAGUE_URL}/by-summoner/{summonerIds}/entry{?api_key}")
13
+ LEAGUES_BY_TEAM_IDS = EndpointTemplate.new(template_url: "#{BASE_LEAGUE_URL}/by-team/{teamIds}{?api_key}")
14
+ ENTRIES_BY_TEAM_IDS = EndpointTemplate.new(template_url: "#{BASE_LEAGUE_URL}/by-team/{teamIds}/entry{?api_key}")
15
+ CHALLENGER = EndpointTemplate.new(template_url: "#{BASE_LEAGUE_URL}/challenger{?api_key,type}")
16
+ MASTER = EndpointTemplate.new(template_url: "#{BASE_LEAGUE_URL}/master{?api_key,type}")
17
17
 
18
18
  CHALLENGER_QUEUE_TYPES = ['RANKED_SOLO_5x5'.freeze, 'RANKED_TEAM_3x3'.freeze, 'RANKED_TEAM_5x5'.freeze].freeze
19
19
  MASTER_QUEUE_TYPES = CHALLENGER_QUEUE_TYPES
@@ -1,4 +1,5 @@
1
1
  require_relative 'base'
2
+ require_relative 'endpoint_template'
2
3
  module Taric
3
4
  module Operation
4
5
  module LolStaticData
@@ -6,21 +7,21 @@ module Taric
6
7
  VERSION = 'v1.2'
7
8
  BASE_STATIC_URL = "https://global.api.pvp.net/api/lol/static-data/{region}/#{VERSION}"
8
9
 
9
- STATIC_CHAMPIONS = Addressable::Template.new "#{BASE_STATIC_URL}/champion{?api_key,dataById,champData,locale,version}"
10
- STATIC_CHAMPION = Addressable::Template.new "#{BASE_STATIC_URL}/champion/{id}{?api_key,locale,version}"
11
- STATIC_ITEMS = Addressable::Template.new "#{BASE_STATIC_URL}/item{?api_key,itemListData,locale,version}"
12
- STATIC_ITEM = Addressable::Template.new "#{BASE_STATIC_URL}/item/{id}{?api_key,itemData,locale,version}"
13
- STATIC_LANGUAGE_STRINGS = Addressable::Template.new "#{BASE_STATIC_URL}/language-strings{?api_key,locale,version}"
14
- STATIC_LANGUAGES = Addressable::Template.new "#{BASE_STATIC_URL}/languages{?api_key}"
15
- STATIC_MAP = Addressable::Template.new "#{BASE_STATIC_URL}/map{?api_key}"
16
- STATIC_MASTERIES = Addressable::Template.new "#{BASE_STATIC_URL}/mastery{?api_key,masteryListData,locale,version}"
17
- STATIC_MASTERY = Addressable::Template.new "#{BASE_STATIC_URL}/mastery/{id}{?api_key,masteryData,locale,version}"
18
- STATIC_REALM = Addressable::Template.new "#{BASE_STATIC_URL}/realm{?api_key}"
19
- STATIC_RUNES = Addressable::Template.new "#{BASE_STATIC_URL}/rune{?api_key,runeListData,locale,version}"
20
- STATIC_RUNE = Addressable::Template.new "#{BASE_STATIC_URL}/rune/{id}{?api_key,runeData,locale,version}"
21
- STATIC_SUMMONER_SPELLS = Addressable::Template.new "#{BASE_STATIC_URL}/summoner-spell{?api_key,spellData,locale,version}"
22
- STATIC_SUMMONER_SPELL = Addressable::Template.new "#{BASE_STATIC_URL}/summoner-spell/{id}{?api_key,spellData,locale,version}"
23
- STATIC_VERSIONS = Addressable::Template.new "#{BASE_STATIC_URL}/versions{?api_key}"
10
+ STATIC_CHAMPIONS = EndpointTemplate.new(template_url: "#{BASE_STATIC_URL}/champion{?api_key,dataById,champData,locale,version}")
11
+ STATIC_CHAMPION = EndpointTemplate.new(template_url: "#{BASE_STATIC_URL}/champion/{id}{?api_key,locale,version}")
12
+ STATIC_ITEMS = EndpointTemplate.new(template_url: "#{BASE_STATIC_URL}/item{?api_key,itemListData,locale,version}")
13
+ STATIC_ITEM = EndpointTemplate.new(template_url: "#{BASE_STATIC_URL}/item/{id}{?api_key,itemData,locale,version}")
14
+ STATIC_LANGUAGE_STRINGS = EndpointTemplate.new(template_url: "#{BASE_STATIC_URL}/language-strings{?api_key,locale,version}")
15
+ STATIC_LANGUAGES = EndpointTemplate.new(template_url: "#{BASE_STATIC_URL}/languages{?api_key}")
16
+ STATIC_MAP = EndpointTemplate.new(template_url: "#{BASE_STATIC_URL}/map{?api_key}")
17
+ STATIC_MASTERIES = EndpointTemplate.new(template_url: "#{BASE_STATIC_URL}/mastery{?api_key,masteryListData,locale,version}")
18
+ STATIC_MASTERY = EndpointTemplate.new(template_url: "#{BASE_STATIC_URL}/mastery/{id}{?api_key,masteryData,locale,version}")
19
+ STATIC_REALM = EndpointTemplate.new(template_url: "#{BASE_STATIC_URL}/realm{?api_key}")
20
+ STATIC_RUNES = EndpointTemplate.new(template_url: "#{BASE_STATIC_URL}/rune{?api_key,runeListData,locale,version}")
21
+ STATIC_RUNE = EndpointTemplate.new(template_url: "#{BASE_STATIC_URL}/rune/{id}{?api_key,runeData,locale,version}")
22
+ STATIC_SUMMONER_SPELLS = EndpointTemplate.new(template_url: "#{BASE_STATIC_URL}/summoner-spell{?api_key,spellData,locale,version}")
23
+ STATIC_SUMMONER_SPELL = EndpointTemplate.new(template_url: "#{BASE_STATIC_URL}/summoner-spell/{id}{?api_key,spellData,locale,version}")
24
+ STATIC_VERSIONS = EndpointTemplate.new(template_url: "#{BASE_STATIC_URL}/versions{?api_key}")
24
25
 
25
26
  CHAMP_DATA_OPTIONS = [
26
27
  'all'.freeze,
@@ -1,8 +1,9 @@
1
+ require_relative 'endpoint_template'
1
2
  module Taric
2
3
  module Operation
3
4
  module LolStatus
4
- SHARDS = Addressable::Template.new 'http://status.leagueoflegends.com/shards'
5
- SHARD = Addressable::Template.new 'http://status.leagueoflegends.com/shards/{region}'
5
+ SHARDS = EndpointTemplate.new(template_url: 'http://status.leagueoflegends.com/shards')
6
+ SHARD = EndpointTemplate.new(template_url: 'http://status.leagueoflegends.com/shards/{region}')
6
7
 
7
8
  # Region metadata.
8
9
  #
@@ -1,21 +1,41 @@
1
1
  require_relative 'base'
2
+ require_relative 'endpoint_template'
2
3
  module Taric
3
4
  module Operation
4
5
  module Match
5
6
  include Taric::Operation::Base
6
7
 
7
8
  MATCH_VERSION = 'v2.2'
8
- MATCH = Addressable::Template.new "#{BASE_URL_FN.(MATCH_VERSION)}/match/{matchId}{?api_key,includeTimeline}"
9
+ MATCH = EndpointTemplate.new(template_url: "#{BASE_URL_FN.(MATCH_VERSION)}/match/{matchId}{?api_key,includeTimeline}")
10
+ MATCH_IDS_BY_TOURNAMENT = EndpointTemplate.new(template_url: "#{BASE_URL_FN.(MATCH_VERSION)}/match/by-tournament/{tournamentCode}/ids{?api_key}")
11
+ MATCH_FOR_TOURNAMENT = EndpointTemplate.new(template_url: "#{BASE_URL_FN.(MATCH_VERSION)}/match/for-tournament/{matchId}{?api_key,tournamentCode,includeTimeline}")
9
12
 
10
13
  # Match data for id.
11
14
  #
12
15
  # @see https://developer.riotgames.com/api/methods#!/1027/3483
13
- # @param id [Fixnum] id of match
16
+ # @param match_id [Fixnum] id of match
14
17
  # @param include_timeline [Boolean] optional, true includes timestamps on events
15
18
  # @return match data for id.
16
- def match(id:, include_timeline: nil)
17
- response_for MATCH, {matchId: id, includeTimeline: include_timeline}
19
+ def match(match_id:, include_timeline: nil)
20
+ response_for MATCH, {matchId: match_id, includeTimeline: include_timeline}
18
21
  end
22
+
23
+ # Retrieve match IDs by tournament code.
24
+ # @param tournament_code [String] tournament code
25
+ # @return match ids by tournament code
26
+ def match_ids_by_tournament(tournament_code: )
27
+ response_for MATCH_IDS_BY_TOURNAMENT, tournamentCode: tournament_code
28
+ end
29
+
30
+ # Retrieve match by match ID and tournament code.
31
+ # @param match_id [Fixnum] id of match
32
+ # @param tournament_code [String] tournament code
33
+ # @param include_timeline [Boolean] optional, true includes timestamps on events
34
+ # @return match ids by tournament code
35
+ def match_for_tournament(match_id:, tournament_code:, include_timeline: false)
36
+ response_for MATCH_IDS_BY_TOURNAMENT, tournamentCode: tournament_code, matchId: match_id, includeTimeline: include_timeline
37
+ end
38
+
19
39
  end
20
40
  end
21
41
  end
@@ -1,11 +1,12 @@
1
1
  require_relative 'base'
2
+ require_relative 'endpoint_template'
2
3
  module Taric
3
4
  module Operation
4
5
  module MatchList
5
6
  include Taric::Operation::Base
6
7
 
7
8
  MATCH_LIST_VERSION = 'v2.2'.freeze
8
- MATCH_LIST = Addressable::Template.new "#{BASE_URL_FN.(MATCH_LIST_VERSION)}/matchlist/by-summoner/{summonerId}{?api_key,championIds,rankedQueues,seasons,beginTime,endTime,beginIndex,endIndex}"
9
+ MATCH_LIST = EndpointTemplate.new(template_url: "#{BASE_URL_FN.(MATCH_LIST_VERSION)}/matchlist/by-summoner/{summonerId}{?api_key,championIds,rankedQueues,seasons,beginTime,endTime,beginIndex,endIndex}")
9
10
 
10
11
  # Returns match list for summoner.
11
12
  #
@@ -1,4 +1,5 @@
1
1
  require_relative 'base'
2
+ require_relative 'endpoint_template'
2
3
  module Taric
3
4
  module Operation
4
5
  module Stats
@@ -6,8 +7,8 @@ module Taric
6
7
 
7
8
  STATS_VERSION = 'v1.3'.freeze
8
9
  BASE_STATS_URL = "#{BASE_URL_FN.(STATS_VERSION)}/stats/by-summoner/{summonerId}"
9
- RANKED = Addressable::Template.new "#{BASE_STATS_URL}/ranked{?api_key,season}"
10
- SUMMARY = Addressable::Template.new "#{BASE_STATS_URL}/summary{?api_key,season}"
10
+ RANKED = EndpointTemplate.new(template_url: "#{BASE_STATS_URL}/ranked{?api_key,season}")
11
+ SUMMARY = EndpointTemplate.new(template_url: "#{BASE_STATS_URL}/summary{?api_key,season}")
11
12
 
12
13
  # Ranked stats for summoner.
13
14
  #
@@ -1,4 +1,5 @@
1
1
  require_relative 'base'
2
+ require_relative 'endpoint_template'
2
3
  module Taric
3
4
  module Operation
4
5
  module Summoner
@@ -8,11 +9,11 @@ module Taric
8
9
  BASE_SUMMONER_URL = "#{BASE_URL_FN.(VERSION)}/summoner"
9
10
  BASE_SUMMONERS_BY_IDS = "#{BASE_SUMMONER_URL}/{summonerIds}"
10
11
 
11
- SUMMONERS_BY_NAMES = Addressable::Template.new "#{BASE_SUMMONER_URL}/by-name/{summonerNames}{?api_key}"
12
- SUMMONERS_BY_IDS = Addressable::Template.new "#{BASE_SUMMONERS_BY_IDS}{?api_key}"
13
- MASTERIES = Addressable::Template.new "#{BASE_SUMMONERS_BY_IDS}/masteries{?api_key}"
14
- NAMES = Addressable::Template.new "#{BASE_SUMMONERS_BY_IDS}/name{?api_key}"
15
- RUNES = Addressable::Template.new "#{BASE_SUMMONERS_BY_IDS}/runes{?api_key}"
12
+ SUMMONERS_BY_NAMES = EndpointTemplate.new(template_url: "#{BASE_SUMMONER_URL}/by-name/{summonerNames}{?api_key}")
13
+ SUMMONERS_BY_IDS = EndpointTemplate.new(template_url: "#{BASE_SUMMONERS_BY_IDS}{?api_key}")
14
+ MASTERIES = EndpointTemplate.new(template_url: "#{BASE_SUMMONERS_BY_IDS}/masteries{?api_key}")
15
+ NAMES = EndpointTemplate.new(template_url: "#{BASE_SUMMONERS_BY_IDS}/name{?api_key}")
16
+ RUNES = EndpointTemplate.new(template_url: "#{BASE_SUMMONERS_BY_IDS}/runes{?api_key}")
16
17
 
17
18
  # Returns [Hash] of summoner data hashes keyed by summoner name
18
19
  #
@@ -1,4 +1,5 @@
1
1
  require_relative 'base'
2
+ require_relative 'endpoint_template'
2
3
  module Taric
3
4
  module Operation
4
5
  module Team
@@ -7,8 +8,8 @@ module Taric
7
8
  TEAM_VERSION = 'v2.4'.freeze
8
9
  BASE_TEAM_URL = "#{BASE_URL_FN.(TEAM_VERSION)}/team"
9
10
 
10
- TEAMS_BY_SUMMONER_IDS = Addressable::Template.new "#{BASE_TEAM_URL}/by-summoner/{summonerIds}"
11
- TEAMS_BY_TEAM_IDS = Addressable::Template.new "#{BASE_TEAM_URL}/{teamIds}"
11
+ TEAMS_BY_SUMMONER_IDS = EndpointTemplate.new(template_url: "#{BASE_TEAM_URL}/by-summoner/{summonerIds}")
12
+ TEAMS_BY_TEAM_IDS = EndpointTemplate.new(template_url: "#{BASE_TEAM_URL}/{teamIds}")
12
13
 
13
14
  # Teams by summoner ids.
14
15
  #
@@ -0,0 +1,53 @@
1
+ require_relative 'base'
2
+ require_relative 'endpoint_template'
3
+ require 'oj'
4
+ module Taric
5
+ module Operation
6
+ module Tournament
7
+ include Taric::Operation::Base
8
+
9
+ TOURNAMENT_VERSION = 'v1'.freeze
10
+ PROVIDER_URL = "https://global.api.pvp.net/tournament/public/#{TOURNAMENT_VERSION}/provider".freeze
11
+ TOURNAMENT_URL = "https://global.api.pvp.net/tournament/public/#{TOURNAMENT_VERSION}/tournament".freeze
12
+ CODE_URL = "https://global.api.pvp.net/tournament/public/#{TOURNAMENT_VERSION}/code{?tournamentId,count}".freeze
13
+ TOURNAMENT_BY_CODE_URL = "https://global.api.pvp.net/tournament/public/#{TOURNAMENT_VERSION}/code/{tournamentCode}".freeze
14
+ LOBBY_EVENTS_BY_CODE_URL = "https://global.api.pvp.net/tournament/public/#{TOURNAMENT_VERSION}/lobby/events/by-code/{tournamentCode}".freeze
15
+
16
+
17
+ # Creates a tournament provider and returns its ID.
18
+ #
19
+ def create_provider(region:, url: )
20
+ response_for EndpointTemplate.new(template_url: PROVIDER_URL, method: :post, headers: {"X-Riot-Token" => @api_key, "Content-Type" => 'application/json'}, body: "{\"region\": \"#{region}\", \"url\": \"#{url}\"}")
21
+ end
22
+
23
+ # Creates a tournament and returns its ID.
24
+ #
25
+ def create_tournament(name: '', provider_id: )
26
+ response_for EndpointTemplate.new(template_url: TOURNAMENT_URL, method: :post, headers: {"X-Riot-Token" => @api_key, "Content-Type" => 'application/json'}, body: "{\"name\": \"#{name}\", \"providerId\": #{provider_id}}")
27
+ end
28
+
29
+ def create_tournament_codes(tournament_id: , count:, allowed_summoner_ids: [], map_type:, metadata: nil, pick_type:, spectator_type:, team_size: )
30
+ body = {'mapType'.freeze => map_type, 'teamSize'.freeze => team_size, 'pickType'.freeze => pick_type, 'spectatorType'.freeze => spectator_type}
31
+ body.merge!('metadata'.freeze => metadata) unless metadata.nil?
32
+ body.merge!('allowed_summoner_ids'.freeze => {'participants'.freeze => allowed_summoner_ids}) unless allowed_summoner_ids.empty?
33
+ response_for(EndpointTemplate.new(template_url: CODE_URL, method: :post, headers: {'X-Riot-Token'.freeze => @api_key, 'Content-Type'.freeze => 'application/json'.freeze},
34
+ body: Oj.dump(body)), tournamentId: tournament_id, count: count)
35
+ end
36
+
37
+ def tournament_by_code(tournament_code: )
38
+ response_for EndpointTemplate.new(template_url: TOURNAMENT_BY_CODE_URL, headers: {'X-Riot-Token'.freeze => @api_key, 'Content-Type'.freeze => 'application/json'.freeze}), tournamentCode: tournament_code
39
+ end
40
+
41
+ # Update the pick type, map, spectator type, or allowed summoners for a code
42
+ def update_tournament(tournament_code:, allowed_participants: nil, spectator_type: nil, pick_type: nil, map_type: nil)
43
+ body = {'spectatorType'.freeze => spectator_type, 'pickType'.freeze => pick_type, 'mapType'.freeze => map_type, 'allowedParticipants'.freeze => allowed_participants}.select!{ |_, v| !v.nil? }
44
+ response_for EndpointTemplate.new(template_url: TOURNAMENT_BY_CODE_URL, headers: {'X-Riot-Token'.freeze => @api_key, 'Content-Type'.freeze => 'application/json'.freeze},
45
+ body: Oj.dump(body), method: :put), tournamentCode: tournament_code
46
+ end
47
+
48
+ def lobby_events_by_code(tournament_code: )
49
+ response_for EndpointTemplate.new(template_url: LOBBY_EVENTS_BY_CODE_URL, headers: {'X-Riot-Token'.freeze => @api_key, 'Content-Type'.freeze => 'application/json'.freeze}), tournamentCode: tournament_code
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module Taric
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -0,0 +1 @@
1
+ edf4d7d3-0c8e-4cf0-907a-6fd40eae8dbf
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taric
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Yi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-15 00:00:00.000000000 Z
11
+ date: 2016-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -196,7 +196,9 @@ files:
196
196
  - lib/taric/operation/api.rb
197
197
  - lib/taric/operation/base.rb
198
198
  - lib/taric/operation/champion.rb
199
+ - lib/taric/operation/champion_mastery.rb
199
200
  - lib/taric/operation/current_game.rb
201
+ - lib/taric/operation/endpoint_template.rb
200
202
  - lib/taric/operation/featured_games.rb
201
203
  - lib/taric/operation/game.rb
202
204
  - lib/taric/operation/league.rb
@@ -207,7 +209,9 @@ files:
207
209
  - lib/taric/operation/stats.rb
208
210
  - lib/taric/operation/summoner.rb
209
211
  - lib/taric/operation/team.rb
212
+ - lib/taric/operation/tournament.rb
210
213
  - lib/taric/version.rb
214
+ - riot.txt
211
215
  - taric.gemspec
212
216
  homepage: http://github.com/josephyi/taric
213
217
  licenses: