ezclient 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ezclient/request.rb +20 -16
- data/lib/ezclient/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff7928f4cebba35f4a10b26e6cbc70610b1af5f09f15dfc681d59d8ba0f21bc6
|
4
|
+
data.tar.gz: 60e1dfd78d106d2b1267d6758164618833209723b321c967cc6590405a2fb9c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c2d79e6882e9f9217b6b8e931cf4d9c153ac8e4ffb7190d738ca6d62dbc38f25ec05ecb7bdb884920933c6657762b32374a67769a7d99f7aa83e6fef449d0d6
|
7
|
+
data.tar.gz: eef52af42332607114392d2c6585abac380b73adca74a1e7da35f6d3f247c7cfed4bd7ea5dbdacbfdec4a090063a71d8bf54dfe0839f5293cf9a0fe500b42520
|
data/lib/ezclient/request.rb
CHANGED
@@ -47,37 +47,41 @@ class EzClient::Request
|
|
47
47
|
http_request.headers.to_h
|
48
48
|
end
|
49
49
|
|
50
|
+
def http_options
|
51
|
+
@http_options ||= http_client.default_options.merge(ssl_context: options[:ssl_context])
|
52
|
+
end
|
53
|
+
|
50
54
|
private
|
51
55
|
|
56
|
+
def http_request
|
57
|
+
@http_request ||= begin
|
58
|
+
# RUBY25: Hash#slice
|
59
|
+
opts = options.select { |key| [:json, :body, :headers].include?(key) }
|
60
|
+
opts[verb == "GET" ? :params : :form] = options[:params]
|
61
|
+
opts[:params] = options[:query] if options[:query]
|
62
|
+
opts[:form] = options[:form] if options[:form]
|
63
|
+
|
64
|
+
http_client.build_request(verb, url, opts)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
52
68
|
def http_client
|
69
|
+
# Only used to build proper HTTP::Request and HTTP::Options instances
|
53
70
|
@http_client ||= begin
|
54
|
-
client = options
|
71
|
+
client = options[:client].dup
|
55
72
|
client = client.timeout(timeout) if timeout
|
56
73
|
client = client.basic_auth(basic_auth) if basic_auth
|
57
74
|
client
|
58
75
|
end
|
59
76
|
end
|
60
77
|
|
61
|
-
def http_request
|
62
|
-
@http_request ||= http_client.build_request(verb, url, http_options)
|
63
|
-
end
|
64
|
-
|
65
|
-
def http_options
|
66
|
-
# RUBY25: Hash#slice
|
67
|
-
opts = options.select { |key| [:json, :body, :headers].include?(key) }
|
68
|
-
opts[verb == "GET" ? :params : :form] = options[:params]
|
69
|
-
opts[:params] = options[:query] if options[:query]
|
70
|
-
opts[:form] = options[:form] if options[:form]
|
71
|
-
opts
|
72
|
-
end
|
73
|
-
|
74
78
|
def perform_request
|
75
79
|
retries = 0
|
76
|
-
request_options = http_client.default_options.merge(ssl_context: options[:ssl_context])
|
77
80
|
|
78
81
|
begin
|
79
82
|
retry_on_connection_error do
|
80
|
-
|
83
|
+
client = options.fetch(:client) # Use original client so that connection can be reused
|
84
|
+
client.perform(http_request, http_options)
|
81
85
|
end
|
82
86
|
rescue *retried_exceptions
|
83
87
|
if retries < max_retries.to_i
|
data/lib/ezclient/version.rb
CHANGED