ezclient 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: a950272f16611080c183b2873c85c2b78d23d36c9d226d900b511f720b7647ba
4
- data.tar.gz: a52ca73d8ff2abc0de9d8811c608394d52f537275951f4cbad5d7d52ceee3710
3
+ metadata.gz: 2d81a3d064c7c1c1e2f07ddfa4e7d47ccb76cc9bb2d7f768f1b48e16276c9c35
4
+ data.tar.gz: def8245e39d85eca05f573c9b2b1e1d37971829c2bba90bfb9d8cb73ea44ef99
5
5
  SHA512:
6
- metadata.gz: d3e3bab868b24417979497778c55e08efaa861b155e45f174847749cebeff75b895a97b6e6d3a8c22fd04eb7cadedd92f4cb2cf5dee60378854f558e2678cc95
7
- data.tar.gz: 68fc9ff7949547044d9aaf28ed11ec7e0477e5cbdf533e0bcfd7efc0b1894232f1d19c8c5c60dbc22c0523f8bc601a2619b48ceb7d608dfea943783014f96ca3
6
+ metadata.gz: bef1ed2b0a0fcfa92cdaa4cf40414576afaa11acf0b87b4654749e5af98413d3c774be66350eaf45563d70f9e08d2c77759e184b89a1d1cb81d08c46d44aa28d
7
+ data.tar.gz: 07f2897cb918736f2a72469c01cb6188c69ebc4f60a22aaf65c83594cec341ed2016237cc9f9e2fc9f2ba06bc6cc9aa7db5ce38d2bfc9c84397f58b08a5fbe45
data/.travis.yml CHANGED
@@ -5,3 +5,10 @@ rvm:
5
5
  - 2.4.2
6
6
  - 2.5.0
7
7
  before_install: gem install bundler -v 1.16.1
8
+ env: SUITE="rspec"
9
+ matrix:
10
+ fast_finish: true
11
+ # Only run RuboCop on the latest Ruby
12
+ include:
13
+ - rvm: 2.5.0
14
+ env: SUITE="rubocop"
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class EzClient::Request
4
- DEFAULT_TIMEOUT = 15
5
-
6
4
  attr_accessor :verb, :url, :options
7
5
 
8
6
  def initialize(verb, url, options)
@@ -42,11 +40,11 @@ class EzClient::Request
42
40
  private
43
41
 
44
42
  def http_client
45
- options.fetch(:client).timeout(timeout)
46
- end
47
-
48
- def timeout
49
- options.fetch(:timeout, DEFAULT_TIMEOUT).to_f
43
+ @http_client ||= begin
44
+ client = options.fetch(:client)
45
+ client.timeout(timeout) if timeout
46
+ client
47
+ end
50
48
  end
51
49
 
52
50
  def http_request
@@ -54,7 +52,12 @@ class EzClient::Request
54
52
  end
55
53
 
56
54
  def http_options
57
- options.slice(:params, :form, :json, :body, :headers)
55
+ # RUBY25: Hash#slice
56
+ options.select { |key| [:params, :form, :json, :body, :headers].include?(key) }
57
+ end
58
+
59
+ def timeout
60
+ options[:timeout]
58
61
  end
59
62
 
60
63
  def on_complete
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class EzClient
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/ezclient.rb CHANGED
@@ -6,10 +6,9 @@ require "ezclient/request"
6
6
  require "ezclient/response"
7
7
 
8
8
  class EzClient
9
- def initialize(on_complete: nil, on_error: nil)
9
+ def initialize(options = {})
10
+ self.options = options
10
11
  self.clients = {}
11
- self.on_complete = on_complete
12
- self.on_error = on_error
13
12
  end
14
13
 
15
14
  def request(verb, url, **options)
@@ -21,15 +20,23 @@ class EzClient
21
20
  client = HTTP::Client.new
22
21
  end
23
22
 
24
- Request.new(verb, url, client: client, on_complete: on_complete, on_error: on_error, **options)
23
+ Request.new(verb, url, client: client, **default_options, **options)
25
24
  end
26
25
 
27
26
  private
28
27
 
29
- attr_accessor :clients, :on_complete, :on_error
28
+ attr_accessor :options, :clients
30
29
 
31
30
  def persistent_client_for(url, timeout: 600)
32
31
  uri = HTTP::URI.parse(url)
33
32
  clients[uri.origin] ||= HTTP.persistent(uri.origin, timeout: timeout)
34
33
  end
34
+
35
+ def default_options()
36
+ {
37
+ on_complete: options[:on_complete],
38
+ on_error: options[:on_error],
39
+ timeout: options[:default_timeout],
40
+ }
41
+ end
35
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Smirnov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-14 00:00:00.000000000 Z
11
+ date: 2018-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http