ezclient 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -0
- data/lib/ezclient/request.rb +11 -8
- data/lib/ezclient/version.rb +1 -1
- data/lib/ezclient.rb +12 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d81a3d064c7c1c1e2f07ddfa4e7d47ccb76cc9bb2d7f768f1b48e16276c9c35
|
4
|
+
data.tar.gz: def8245e39d85eca05f573c9b2b1e1d37971829c2bba90bfb9d8cb73ea44ef99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bef1ed2b0a0fcfa92cdaa4cf40414576afaa11acf0b87b4654749e5af98413d3c774be66350eaf45563d70f9e08d2c77759e184b89a1d1cb81d08c46d44aa28d
|
7
|
+
data.tar.gz: 07f2897cb918736f2a72469c01cb6188c69ebc4f60a22aaf65c83594cec341ed2016237cc9f9e2fc9f2ba06bc6cc9aa7db5ce38d2bfc9c84397f58b08a5fbe45
|
data/.travis.yml
CHANGED
data/lib/ezclient/request.rb
CHANGED
@@ -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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
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
|
data/lib/ezclient/version.rb
CHANGED
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(
|
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,
|
23
|
+
Request.new(verb, url, client: client, **default_options, **options)
|
25
24
|
end
|
26
25
|
|
27
26
|
private
|
28
27
|
|
29
|
-
attr_accessor :
|
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.
|
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-
|
11
|
+
date: 2018-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|