taric 0.1.6 → 0.1.7

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: af5a3fbf7f3ce947a8d074935d86c42bcec230a0
4
- data.tar.gz: 123007565b2acd2dd52d31e41cb53e327242b840
3
+ metadata.gz: 29900a7fab3608cd9c692b69817f666747e39136
4
+ data.tar.gz: e2f22660390cb82bc490f51422bb517eef746e93
5
5
  SHA512:
6
- metadata.gz: a4b22562e2dbd547266f99e9512169b9641aec212d9da8815fb2ccc56464bbc032c251a8118cd07889f15f60027e30175b3948c9a952d52e972699b10e110700
7
- data.tar.gz: fb14c6ebda12d959f448a4346d9b36757a0000efd9a3f8bdf44b2b19bd33fd66d21cc19de1dfce49d990f17875da07bb6223ffbf54e255345b12b480b7ccbe02
6
+ metadata.gz: d128b14efc299f1fa07bb383fb32a4b6f0e4d56fa61b9a7a975a259c382aa9d0714d5035faca5797872beac100879b54d93d7f30c3c016813153b1ef4665984c
7
+ data.tar.gz: b409f0486bc7968488ab4368aefc315aa113682c919bc122bc7bf8bf8fca69691636c3803d486f44e6d13bb87e4ab8cc675b80b1b7ba4d86c849c9b11b90a9dc
data/README.md CHANGED
@@ -62,14 +62,14 @@ There are a couple of ways to set the API key:
62
62
 
63
63
  > "Functional and stylish."
64
64
 
65
- Once the key is set, you can use `Taric.client(:region)` to get a client instance for the specified region.
65
+ Once the key is set, you can use `Taric.client(region: region_code)` to get a client instance for the specified region.
66
66
 
67
67
  ```ruby
68
68
  # North America
69
- client = Taric.client(:na)
69
+ client = Taric.client(region: :na)
70
70
 
71
- # Korea
72
- client = Taric.client(:kr)
71
+ # Korea, using String arg
72
+ client = Taric.client(region: 'kr')
73
73
  ```
74
74
 
75
75
  ### Champion
data/lib/taric.rb CHANGED
@@ -9,14 +9,37 @@ module Taric
9
9
  class << self
10
10
  attr_accessor :configuration
11
11
 
12
- def client(region: :na, config: @configuration ||= Taric::Configuration.new)
13
- Taric::Client.new(api_key: config.api_key,
14
- region: region,
12
+ # Creates a [Taric::Client], the main interface to the LoL API. If the api_key is provided
13
+ # in .configure!, then only the region needs to be set. If .configure! is used, but a different
14
+ # api_key is provided, then the latter takes precedence.
15
+ #
16
+ # @see Taric::Client::REGION_ENDPOINT_INFO
17
+ # @param region [Symbol] region code, also accepts [String], default is :na
18
+ # @param api_key [String] rito API key
19
+ # @param config [Taric::Configuration] configuration options. If not provided, then defaults will be used.
20
+ #
21
+ # @return [Taric::Client]
22
+ #
23
+ # @example
24
+ # # With .configure! (preferred)
25
+ # Taric.configure! do |config|
26
+ # config.api_key = 'your-rito-api-key'
27
+ # end
28
+ #
29
+ # client = Taric.client(region: :na)
30
+ #
31
+ # # With arbitrary key.
32
+ # client = Taric.client(region: :na, api_key: 'your-rito-key')
33
+ def client(region: :na, api_key: nil, config: @configuration ||= Taric::Configuration.new)
34
+ Taric::Client.new(api_key: api_key || config.api_key,
35
+ region: region.is_a?(String) ? region.to_sym : region,
15
36
  requestor: config.requestor.(connection(config)),
16
37
  response_handler: config.response_handler)
17
38
  end
18
39
 
19
- # Sets global configuration.
40
+ # Sets global configuration. Should only be called once in a process (e.g. Rails initializer)
41
+ #
42
+ # @see Taric::Configuration
20
43
  #
21
44
  # @example
22
45
  # Taric.configure! do |config|
@@ -28,7 +51,7 @@ module Taric
28
51
  end
29
52
 
30
53
  # Resets global configuration.
31
- #
54
+ # @see Taric::Configuration
32
55
  def reset!
33
56
  @configuration = Taric::Configuration.new
34
57
  end
data/lib/taric/client.rb CHANGED
@@ -18,12 +18,18 @@ module Taric
18
18
  pbe: {region: 'pbe'.freeze, platform_id: 'PBE1', host: 'pbe.api.pvp.net'}
19
19
  }.freeze
20
20
 
21
+ REGION_ENDPOINT_STRING_KEYS = REGION_ENDPOINT_INFO.keys.map(&:to_s).freeze
22
+
21
23
  # @param api_key [String] rito api key
22
24
  # @param region [Symbol] region code
23
25
  # @param requestor [Proc] lambda that will accept a url and return a [Faraday::Response]
24
26
  # @param response_handler [Proc] lambda that accepts [Faraday::Response] and handles it
25
27
  #
26
28
  def initialize(api_key:, region:, requestor:, response_handler:)
29
+ raise ArgumentError, 'api_key cannot be nil' if api_key.nil?
30
+ raise ArgumentError, 'region cannot be nil' if region.nil?
31
+ raise ArgumentError, "#{region} is not a valid region, #{REGION_ENDPOINT_STRING_KEYS}" if REGION_ENDPOINT_INFO[region].nil?
32
+
27
33
  @api_key = api_key
28
34
  @region = region
29
35
  @requestor = requestor
@@ -11,7 +11,7 @@ module Taric
11
11
  }
12
12
 
13
13
  def initialize(options = {})
14
- @api_key = options.fetch(:api_key, ENV.fetch('RIOT_API_KEY'.freeze, 'KeyNotSetButUsingThisForTest'.freeze))
14
+ @api_key = options.fetch(:api_key, ENV.fetch('RIOT_API_KEY'.freeze, nil))
15
15
  @format = options.fetch(:format, :json)
16
16
  @user_agent = options.fetch(:user_agent, 'Taric Gem')
17
17
  @adapter = options.fetch(:adapter, :typhoeus)
@@ -1,4 +1,4 @@
1
- require 'faraday_middleware'
1
+ require 'faraday_middleware/parse_oj'
2
2
 
3
3
  module Taric
4
4
  module Connection
@@ -8,9 +8,7 @@ module Taric
8
8
  }.merge(config.connection_opts)
9
9
 
10
10
  Faraday::Connection.new(options) do |conn|
11
- #conn.use FaradayMiddleware::Mashify
12
- #conn.response :raise_error
13
- conn.response :json, :content_type => /\bjson$/
11
+ conn.response :oj, :content_type => /\bjson$/
14
12
  conn.adapter config.adapter
15
13
  end
16
14
  end
data/lib/taric/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Taric
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
data/taric.gemspec CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency 'typhoeus', "~> 0.3"
31
31
  spec.add_runtime_dependency 'memoist', '~> 0.11'
32
32
  spec.add_runtime_dependency('addressable', '~> 2.3')
33
+ spec.add_runtime_dependency('oj', '~> 2.12')
33
34
  spec.add_runtime_dependency('faraday_middleware', '~> 0.9')
34
- spec.add_runtime_dependency('hashie', '~> 3.4')
35
- spec.add_runtime_dependency('multi_json', '~> 1.1')
35
+ spec.add_runtime_dependency('faraday_middleware-parse_oj', '~> 0.3.0')
36
36
  end
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.1.6
4
+ version: 0.1.7
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-03-20 00:00:00.000000000 Z
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -143,47 +143,47 @@ dependencies:
143
143
  - !ruby/object:Gem::Version
144
144
  version: '2.3'
145
145
  - !ruby/object:Gem::Dependency
146
- name: faraday_middleware
146
+ name: oj
147
147
  requirement: !ruby/object:Gem::Requirement
148
148
  requirements:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: '0.9'
151
+ version: '2.12'
152
152
  type: :runtime
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: '0.9'
158
+ version: '2.12'
159
159
  - !ruby/object:Gem::Dependency
160
- name: hashie
160
+ name: faraday_middleware
161
161
  requirement: !ruby/object:Gem::Requirement
162
162
  requirements:
163
163
  - - "~>"
164
164
  - !ruby/object:Gem::Version
165
- version: '3.4'
165
+ version: '0.9'
166
166
  type: :runtime
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  requirements:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: '3.4'
172
+ version: '0.9'
173
173
  - !ruby/object:Gem::Dependency
174
- name: multi_json
174
+ name: faraday_middleware-parse_oj
175
175
  requirement: !ruby/object:Gem::Requirement
176
176
  requirements:
177
177
  - - "~>"
178
178
  - !ruby/object:Gem::Version
179
- version: '1.1'
179
+ version: 0.3.0
180
180
  type: :runtime
181
181
  prerelease: false
182
182
  version_requirements: !ruby/object:Gem::Requirement
183
183
  requirements:
184
184
  - - "~>"
185
185
  - !ruby/object:Gem::Version
186
- version: '1.1'
186
+ version: 0.3.0
187
187
  description: An outrageous Riot Games LoL API Client
188
188
  email:
189
189
  - dissonance@gmail.com