taric 0.1.2 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2256ea4d83d6f1dda589d852530b416ca8ef9f76
4
- data.tar.gz: e31ea5232da64b236e460d7dd1f5fcee9cf3ec69
3
+ metadata.gz: 4e7a47c9d9fcc0b6a342967bbcdce1d36df210e3
4
+ data.tar.gz: 05d90533b37c099998da7b6c9c49926a53049d48
5
5
  SHA512:
6
- metadata.gz: ee2de0222a67b484325cd4e41ac6e5caf734a851dbf9ed68056973a2970b7e7713581c8e928a1ec4f6a5f2bad345fce3e816c144ee011c02ecc525908fa424e8
7
- data.tar.gz: 1f82644f6372b738ac39b44d0b81c724bbfa5fa73e957de46ec411dd098361953f853b550bbc44dfaafa3dd2eb3112c25fe6f06faeab4feb594a4a85546e6897
6
+ metadata.gz: e15826735122a20bd4bc40aab70f0a6ab792742d11ccd125cea6ffef22be2f888b3b3803798f8cbc3e7f4fc4df24c64b5d62237aad3be7121d88effc054765b3
7
+ data.tar.gz: 0865f86f099767656b268235feb4cb6c045362114ae3e783c842666f9321f796647113eea68ba188f6ab948b9cc7b4e26143232c576700dae20d156791ba1432
data/lib/taric/client.rb CHANGED
@@ -4,6 +4,20 @@ module Taric
4
4
  class Client
5
5
  include Taric::Operation::API
6
6
 
7
+ REGION_ENDPOINT_INFO = {
8
+ br: {region: 'br'.freeze, platform_id: 'BR1'.freeze, host: 'br.api.pvp.net'},
9
+ eune: {region: 'eune'.freeze, platform_id: 'EUN1'.freeze, host: 'eune.api.pvp.net'},
10
+ euw: {region: 'euw'.freeze, platform_id: 'EUW1', host: 'euw.api.pvp.net'},
11
+ kr: {region: 'kr'.freeze, platform_id: 'KR', host: 'kr.api.pvp.net'},
12
+ lan: {region: 'lan'.freeze, platform_id: 'LA1', host: 'lan.api.pvp.net'},
13
+ las: {region: 'las'.freeze, platform_id: 'LA2', host: 'las.api.pvp.net'},
14
+ na: {region: 'na'.freeze, platform_id: 'NA1', host: 'na.api.pvp.net'},
15
+ oce: {region: 'oce'.freeze, platform_id: 'OC1', host: 'oce.api.pvp.net'},
16
+ tr: {region: 'tr'.freeze, platform_id: 'TR1', host: 'tr.api.pvp.net'},
17
+ ru: {region: 'ru'.freeze, platform_id: 'RU', host: 'ru.api.pvp.net'},
18
+ pbe: {region: 'pbe'.freeze, platform_id: 'PBE1', host: 'pbe.api.pvp.net'}
19
+ }.freeze
20
+
7
21
  def initialize(api_key, region, requestor, response_handler)
8
22
  @api_key = api_key
9
23
  @region = region
@@ -11,21 +25,40 @@ module Taric
11
25
  @response_handler = response_handler
12
26
  end
13
27
 
14
- def expand_template(operation, options = {})
15
- operation.expand(options.merge(self.class.operation_values(@api_key, @region)))
16
- end
17
-
18
- private
19
- def response_for(operation, options = {})
20
- RESPONSE.(expand_template(operation, options), @requestor, @response_handler)
21
- end
22
-
23
28
  class << self
24
29
  extend Memoist
25
- def operation_values(api_key, region)
26
- {api_key: api_key}.merge!(Taric::Operation::API::REGION_ENDPOINT_INFO[region]).freeze
30
+
31
+ # @note Memoized
32
+ #
33
+ # Sets up and returns hash of api key and region values.
34
+ #
35
+ # @params api_key [String] rito api key
36
+ # @params region [Symbol] key for region
37
+ # @return [Hash] of api_key and region info
38
+ def operation_values(api_key:, region:)
39
+ {api_key: api_key}.merge!(REGION_ENDPOINT_INFO[region])
40
+ end
41
+ memoize :operation_values
42
+
43
+ # Expands operation template with api_key, region, and option values.
44
+ #
45
+ # @param api_key [String] rito api key
46
+ # @param region [Symbol] key for region
47
+ # @param operation [Addressable::Template] URI template for operation
48
+ # @param options [Hash] optional, values for template
49
+ # @return [Addressable::URI] of expanded template
50
+ #
51
+ # @example
52
+ # Taric::Client.expand_template(api_key: 'ritokey', region: :na, operation: Taric::Operation::Champion::CHAMPIONS)
53
+ def expand_template(api_key:, region:, operation:, options: {})
54
+ operation.expand(options.merge(operation_values(api_key: api_key, region: region)))
27
55
  end
28
56
  end
29
57
 
58
+ private
59
+ def response_for(operation, options = {})
60
+ url = self.class.expand_template(api_key: @api_key, region: @region, operation: operation, options: options)
61
+ API_CALL.(url: url, requestor: @requestor, response_handler: @response_handler)
62
+ end
30
63
  end
31
64
  end
@@ -9,6 +9,7 @@ module Taric
9
9
 
10
10
  Faraday::Connection.new(options) do |conn|
11
11
  #conn.use FaradayMiddleware::Mashify
12
+ conn.response :raise_error
12
13
  conn.response :json, :content_type => /\bjson$/
13
14
  conn.adapter config.adapter
14
15
  end
@@ -22,21 +22,12 @@ module Taric
22
22
  include Taric::Operation::Stats
23
23
  include Taric::Operation::Summoner
24
24
 
25
- REGION_ENDPOINT_INFO = {
26
- br: {region: 'br'.freeze, platform_id: 'BR1'.freeze, host: 'br.api.pvp.net'},
27
- eune: {region: 'eune'.freeze, platform_id: 'EUN1'.freeze, host: 'eune.api.pvp.net'},
28
- euw: {region: 'euw'.freeze, platform_id: 'EUW1', host: 'euw.api.pvp.net'},
29
- kr: {region: 'kr'.freeze, platform_id: 'KR', host: 'kr.api.pvp.net'},
30
- lan: {region: 'lan'.freeze, platform_id: 'LA1', host: 'lan.api.pvp.net'},
31
- las: {region: 'las'.freeze, platform_id: 'LA2', host: 'las.api.pvp.net'},
32
- na: {region: 'na'.freeze, platform_id: 'NA1', host: 'na.api.pvp.net'},
33
- oce: {region: 'oce'.freeze, platform_id: 'OC1', host: 'oce.api.pvp.net'},
34
- tr: {region: 'tr'.freeze, platform_id: 'TR1', host: 'tr.api.pvp.net'},
35
- ru: {region: 'ru'.freeze, platform_id: 'RU', host: 'ru.api.pvp.net'},
36
- pbe: {region: 'pbe'.freeze, platform_id: 'PBE1', host: 'pbe.api.pvp.net'}
37
- }.freeze
38
-
39
- RESPONSE = -> url, requestor, response_handler {
25
+ # Template for requesting the url and processing the response.
26
+ #
27
+ # @param url String
28
+ # @param requestor Proc (lambda)
29
+ # @param response_handler Proc (lambda)
30
+ API_CALL = -> (url:, requestor:, response_handler:) {
40
31
  response_handler.(requestor.(url))
41
32
  }.curry
42
33
 
@@ -11,9 +11,9 @@ module Taric
11
11
  CHAMPIONS = Addressable::Template.new("#{CHAMPION_BASE_URL}{?api_key,freeToPlay}")
12
12
  CHAMPION_BY_ID = Addressable::Template.new("#{CHAMPION_BASE_URL}/{id}{?api_key}")
13
13
 
14
- # Returns [Hash] embedding an [Array] of champion data.
14
+ # Returns champion data.
15
15
  #
16
- # @see {https://developer.riotgames.com/api/methods#!/958/3290}
16
+ # @see https://developer.riotgames.com/api/methods#!/958/3290
17
17
  # @param free_to_play [Boolean] optional, nil returns all, true or false to filter if they're free to play or not
18
18
  # @return [Hash] embedding [Array] of champions keyed off of "champions"
19
19
  #
@@ -25,6 +25,14 @@ module Taric
25
25
  response_for CHAMPIONS, freeToPlay: free_to_play
26
26
  end
27
27
 
28
+ # Returns champion data by id.
29
+ #
30
+ # @see https://developer.riotgames.com/api/methods#!/958/3289
31
+ # @param id [Fixnum] id of champion
32
+ # @return [Hash] of champion data
33
+ #
34
+ # @example
35
+ # champion = client.champion(id: 266)
28
36
  def champion(id:)
29
37
  response_for CHAMPION_BY_ID, id: id
30
38
  end
@@ -3,9 +3,9 @@ module Taric
3
3
  module CurrentGame
4
4
  GAME_INFO = Addressable::Template.new 'https://{host}/observer-mode/rest/consumer/getSpectatorGameInfo/{platform_id}/{summonerId}{?api_key}'
5
5
 
6
- # Returns [Hash] of game data for summoner id
6
+ # Returns current game data for summoner id.
7
7
  #
8
- # @see {https://developer.riotgames.com/api/methods#!/956/3287}
8
+ # @see https://developer.riotgames.com/api/methods#!/956/3287
9
9
  # @param summoner_id [Fixnum] required, id of summoner
10
10
  # @return [Hash] of game data for summoner id
11
11
  #
@@ -3,9 +3,9 @@ module Taric
3
3
  module FeaturedGames
4
4
  FEATURED_GAMES = Addressable::Template.new 'https://{host}/observer-mode/rest/featured{?api_key}'
5
5
 
6
- # Returns [Hash] of featured games in [Array] keyed by 'gameList'
6
+ # Returns featured games.
7
7
  #
8
- # @see {https://developer.riotgames.com/api/methods#!/957/3288}
8
+ # @see https://developer.riotgames.com/api/methods#!/957/3288
9
9
  # @return [Hash] of featured games in [Array] keyed by 'gameList'
10
10
  #
11
11
  # @example
@@ -7,9 +7,9 @@ module Taric
7
7
  GAME_VERSION = 'v1.3'.freeze
8
8
  RECENT = Addressable::Template.new "#{BASE_URL_FN.(GAME_VERSION)}/game/by-summoner/{summonerId}/recent{?api_key}"
9
9
 
10
- # Returns [Hash] of recent game data for summoner id in an [Array] keyed by 'games'
10
+ # Returns recent game data for summoner id.
11
11
  #
12
- # @see {https://developer.riotgames.com/api/methods#!/959/3291}
12
+ # @see https://developer.riotgames.com/api/methods#!/959/3291
13
13
  # @param summoner_id [Fixnum] required, id of summoner
14
14
  # @return [Hash] of recent game data for summoner id
15
15
  #
@@ -6,7 +6,7 @@ module Taric
6
6
  VERSION = 'v1.2'
7
7
  BASE_STATIC_URL = "https://global.api.pvp.net/api/lol/static-data/{region}/#{VERSION}"
8
8
 
9
- STATIC_CHAMPIONS = Addressable::Template.new "#{BASE_STATIC_URL}/champion{?api_key}"
9
+ STATIC_CHAMPIONS = Addressable::Template.new "#{BASE_STATIC_URL}/champion{?api_key,dataById}"
10
10
  STATIC_CHAMPION = Addressable::Template.new "#{STATIC_CHAMPIONS}/{id}{?api_key}"
11
11
  STATIC_ITEMS = Addressable::Template.new "#{BASE_STATIC_URL}/item{?api_key}"
12
12
  STATIC_ITEM = Addressable::Template.new "#{STATIC_ITEMS}/{id}{?api_key}"
@@ -93,6 +93,56 @@ module Taric
93
93
  'vars'.freeze
94
94
  ].freeze
95
95
 
96
+ # locales mapped to languages
97
+ LOCALE = {
98
+ bg_BG: 'Bulgarian (Bulgaria)',
99
+ cs_CZ: 'Czech (Czech Republic)',
100
+ de_DE: 'German (Germany)',
101
+ el_GR: 'Greek (Greece)',
102
+ en_AU: 'English (Australia)',
103
+ en_GB: 'English (United Kingdom)',
104
+ en_PH: 'English (Republic of the Philippines)',
105
+ en_PL: 'English (Poland)',
106
+ en_SG: 'English (Singapore)',
107
+ en_US: 'English (United States)',
108
+ es_AR: 'Spanish (Argentina)',
109
+ es_ES: 'Spanish (Spain)',
110
+ es_MX: 'Spanish (Mexico)',
111
+ fr_FR: 'French (France)',
112
+ hu_HU: 'Hungarian (Hungary)',
113
+ id_ID: 'Indonesian (Indonesia)',
114
+ it_IT: 'Italian (Italy)',
115
+ ja_JP: 'Japanese (Japan)',
116
+ ko_KR: 'Korean (Korea)',
117
+ nl_NL: 'Dutch (Netherlands)',
118
+ ms_MY: 'Malay (Malaysia)',
119
+ pl_PL: 'Polish (Poland)',
120
+ pt_BR: 'Portuguese (Brazil)',
121
+ pt_PT: 'Portuguese (Portugal)',
122
+ ro_RO: 'Romanian (Romania)',
123
+ ru_RU: 'Russian (Russia)',
124
+ th_TH: 'Thai (Thailand)',
125
+ tr_TR: 'Turkish (Turkey)',
126
+ vn_VN: 'Vietnamese (Viet Nam)',
127
+ zh_CN: 'Chinese (China)',
128
+ zh_MY: 'Chinese (Malaysia)',
129
+ zh_TW: 'Chinese (Taiwan)'
130
+ }
131
+
132
+ LOCALE_KEYS = LOCALE.keys
133
+
134
+ # Static champion data
135
+ #
136
+ # @param data_by_id [Boolean] optional, if true, champion data keyed to IDs
137
+ # @param champ_data_option [String] optional, filter from [CHAMP_DATA_OPTIONS]
138
+ # @param locale [Symbol] optional, results will be in locale [LOCALE], or default for region if nil
139
+ # @param version [String] optional, enforces version of static data, or latest if nil
140
+ #
141
+ # @return [Hash] of static champion data
142
+ #
143
+ # @example
144
+ # champions = client.static_champions
145
+ # champions_mapped_by_id = client.static_champions(data_by_id: true)
96
146
  def static_champions(data_by_id: nil, champ_data_option: nil, locale: nil, version: nil)
97
147
  response_for STATIC_CHAMPIONS, {dataById: data_by_id, champData: champ_data_option, locale: locale, version: version}
98
148
  end
data/lib/taric/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Taric
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taric
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Yi
@@ -240,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
240
  version: '0'
241
241
  requirements: []
242
242
  rubyforge_project:
243
- rubygems_version: 2.4.6
243
+ rubygems_version: 2.4.3
244
244
  signing_key:
245
245
  specification_version: 4
246
246
  summary: An outrageous Riot Games LoL API Client