ezclient 0.3.0 → 0.4.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 +4 -4
- data/.travis.yml +1 -0
- data/README.md +2 -22
- data/ezclient.gemspec +1 -1
- data/lib/ezclient/request.rb +50 -4
- data/lib/ezclient/version.rb +1 -1
- data/lib/ezclient.rb +3 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8095e9d89e1ba040935437e755e022ff458f09f16a99967a9def2059406a3448
|
4
|
+
data.tar.gz: 23ba78d9d72e9ce7dbbda36a66be93cb6a4d5f9948bc71d42f7cdbb0f52c36d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5eeec168072569e4bf30602b58315111bad499b91b242b5ac66ea28f59ed2e8214b2209d78e0eace3d36ede29676656a1a652a70fb2b4a03536a2a17001c69d8
|
7
|
+
data.tar.gz: 5407977b45b49797bc7eaf75f2b8458ec84be9c9cfca3d3c313dc71f6a0916c3908b76988b4e9d894bf2987dd2b24088d59fe092e0c3b4d1b411f316048bf4f2
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,35 +1,15 @@
|
|
1
1
|
# EzClient
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
EzClient is [HTTP gem](https://github.com/httprb/http) wrapper for easy persistent connections and more.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
7
|
Add this line to your application's Gemfile:
|
10
8
|
|
11
9
|
```ruby
|
12
|
-
gem
|
10
|
+
gem "ezclient"
|
13
11
|
```
|
14
12
|
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install ezclient
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
13
|
## Contributing
|
34
14
|
|
35
15
|
Bug reports and pull requests are welcome on GitHub at https://github.com/umbrellio/ezclient.
|
data/ezclient.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.email = ["tycooon@yandex.ru"]
|
12
12
|
|
13
13
|
spec.summary = "An HTTP gem wrapper for easy persistent connections and more."
|
14
|
-
spec.homepage = "https://github.
|
14
|
+
spec.homepage = "https://github.com/umbrellio/ezclient"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
|
data/lib/ezclient/request.rb
CHANGED
@@ -10,7 +10,7 @@ class EzClient::Request
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def perform
|
13
|
-
http_response =
|
13
|
+
http_response = perform_request
|
14
14
|
|
15
15
|
EzClient::Response.new(http_response).tap do |response|
|
16
16
|
on_complete.call(self, response, options[:metadata])
|
@@ -21,7 +21,7 @@ class EzClient::Request
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def api_auth!(*args)
|
24
|
-
|
24
|
+
raise "ApiAuth gem is not loaded" unless defined?(ApiAuth)
|
25
25
|
ApiAuth.sign!(http_request, *args)
|
26
26
|
self
|
27
27
|
end
|
@@ -41,8 +41,9 @@ class EzClient::Request
|
|
41
41
|
|
42
42
|
def http_client
|
43
43
|
@http_client ||= begin
|
44
|
-
client = options.fetch(:client)
|
45
|
-
client.timeout(timeout) if timeout
|
44
|
+
client = options.fetch(:client) # TODO: dup?
|
45
|
+
client = client.timeout(timeout) if timeout
|
46
|
+
client = client.basic_auth(basic_auth) if basic_auth
|
46
47
|
client
|
47
48
|
end
|
48
49
|
end
|
@@ -56,6 +57,31 @@ class EzClient::Request
|
|
56
57
|
options.select { |key| [:params, :form, :json, :body, :headers].include?(key) }
|
57
58
|
end
|
58
59
|
|
60
|
+
def perform_request
|
61
|
+
retries = 0
|
62
|
+
|
63
|
+
begin
|
64
|
+
retry_on_connection_error do
|
65
|
+
http_client.perform(http_request, http_client.default_options)
|
66
|
+
end
|
67
|
+
rescue *retried_exceptions
|
68
|
+
if retries < max_retries.to_i
|
69
|
+
retries += 1
|
70
|
+
retry
|
71
|
+
else
|
72
|
+
raise
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def retry_on_connection_error
|
78
|
+
# This may result in 2 requests reaching the server so I hope HTTP fixes it
|
79
|
+
# https://github.com/httprb/http/issues/459
|
80
|
+
yield
|
81
|
+
rescue HTTP::ConnectionError
|
82
|
+
yield
|
83
|
+
end
|
84
|
+
|
59
85
|
def timeout
|
60
86
|
options[:timeout]&.to_f
|
61
87
|
end
|
@@ -67,4 +93,24 @@ class EzClient::Request
|
|
67
93
|
def on_error
|
68
94
|
options[:on_error] || proc {}
|
69
95
|
end
|
96
|
+
|
97
|
+
def retried_exceptions
|
98
|
+
Array(options[:retry_exceptions])
|
99
|
+
end
|
100
|
+
|
101
|
+
def max_retries
|
102
|
+
options[:max_retries] || 1
|
103
|
+
end
|
104
|
+
|
105
|
+
def basic_auth
|
106
|
+
@basic_auth ||= begin
|
107
|
+
case options[:basic_auth]
|
108
|
+
when Array
|
109
|
+
user, password = options[:basic_auth]
|
110
|
+
{ user: user, pass: password }
|
111
|
+
when Hash
|
112
|
+
options[:basic_auth]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
70
116
|
end
|
data/lib/ezclient/version.rb
CHANGED
data/lib/ezclient.rb
CHANGED
@@ -32,11 +32,13 @@ class EzClient
|
|
32
32
|
clients[uri.origin] ||= HTTP.persistent(uri.origin, timeout: timeout)
|
33
33
|
end
|
34
34
|
|
35
|
-
def default_options
|
35
|
+
def default_options
|
36
36
|
{
|
37
37
|
on_complete: options[:on_complete],
|
38
38
|
on_error: options[:on_error],
|
39
39
|
timeout: options[:default_timeout],
|
40
|
+
retry_exceptions: options[:retry_exceptions],
|
41
|
+
max_retries: options[:max_retries],
|
40
42
|
}
|
41
43
|
end
|
42
44
|
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.4.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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -158,7 +158,7 @@ files:
|
|
158
158
|
- lib/ezclient/request.rb
|
159
159
|
- lib/ezclient/response.rb
|
160
160
|
- lib/ezclient/version.rb
|
161
|
-
homepage: https://github.
|
161
|
+
homepage: https://github.com/umbrellio/ezclient
|
162
162
|
licenses:
|
163
163
|
- MIT
|
164
164
|
metadata: {}
|