ezclient 0.10.0 → 0.11.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 +4 -5
- data/README.md +98 -19
- data/lib/ezclient/check_options.rb +4 -2
- data/lib/ezclient/version.rb +1 -1
- 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: 6d9f110bfae1ffb37a3ed9bdeb162487717a243178175822b9e0152df2533288
|
4
|
+
data.tar.gz: 7f1380b423969a1101648fa5017f3e70c3ffbff774156068337fb839cab5854d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2bf1f8d239320d4bc4b8a57b0d23208ec3700922eb4b2fe00cac386efb69ecc0961da46695697f2b9fc3aaa642f3f8fe47992f9cfa545a4aa971db4253b69d4
|
7
|
+
data.tar.gz: 49fb747c452aff9168492439f94324f911e8389ead521037f54e9480971394aeeca8ef90867542e8ee448ec6289c896be2bcd22b2a33ab0f332916b8eb795d8c
|
data/.travis.yml
CHANGED
@@ -3,9 +3,9 @@ language: ruby
|
|
3
3
|
sudo: false
|
4
4
|
|
5
5
|
rvm:
|
6
|
-
- 2.3
|
7
|
-
- 2.4
|
8
|
-
- 2.5
|
6
|
+
- 2.3
|
7
|
+
- 2.4
|
8
|
+
- 2.5
|
9
9
|
- ruby-head
|
10
10
|
|
11
11
|
before_install: gem install bundler
|
@@ -18,10 +18,9 @@ matrix:
|
|
18
18
|
fast_finish: true
|
19
19
|
# Only run RuboCop on the latest Ruby
|
20
20
|
include:
|
21
|
-
- rvm: 2.5
|
21
|
+
- rvm: 2.5
|
22
22
|
env: SUITE="rubocop"
|
23
23
|
allow_failures:
|
24
24
|
- rvm: ruby-head
|
25
|
-
- rvm: jruby-head
|
26
25
|
|
27
26
|
cache: bundler
|
data/README.md
CHANGED
@@ -1,45 +1,124 @@
|
|
1
|
-
# EzClient
|
2
|
-
|
1
|
+
# EzClient [![Gem Version](https://badge.fury.io/rb/ezclient.svg)](https://badge.fury.io/rb/ezclient) [![Build Status](https://travis-ci.org/umbrellio/ezclient.svg?branch=master)](https://travis-ci.org/umbrellio/ezclient) [![Coverage Status](https://coveralls.io/repos/github/umbrellio/ezclient/badge.svg?branch=master)](https://coveralls.io/github/umbrellio/ezclient?branch=master)
|
3
2
|
EzClient is [HTTP gem](https://github.com/httprb/http) wrapper for easy persistent connections and more.
|
4
3
|
|
5
4
|
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
5
|
+
Add this lines to your application's Gemfile:
|
8
6
|
|
9
7
|
```ruby
|
10
8
|
gem "ezclient"
|
11
|
-
gem "http", github: "httprb/http"
|
9
|
+
gem "http", github: "httprb/http" # version 3 is not supported for now
|
12
10
|
```
|
13
11
|
|
14
12
|
## Usage
|
15
13
|
```ruby
|
16
|
-
|
17
|
-
|
14
|
+
url = "http://example.com"
|
15
|
+
|
16
|
+
client_options = { timeout: 10 }
|
17
|
+
client = EzClient.new(client_options) # => EzClient::Client object
|
18
|
+
|
19
|
+
request_options = { params: { a: 1 } }
|
20
|
+
request = client.request(:get, url, request_options) # => EzClient::Request object
|
21
|
+
|
18
22
|
# Performs a GET request to https://example.com/?a=1
|
23
|
+
response = request.perform # => EzClient::Response object
|
24
|
+
|
25
|
+
# Same request but will raise EzClient::ResponseStatusError in case of 4xx or 5xx response code
|
26
|
+
response = request.perform!
|
27
|
+
|
28
|
+
# Alternatively, you can just do:
|
29
|
+
response = client.perform!(:get, url, request_options) # => EzClient::Response object
|
19
30
|
```
|
20
31
|
|
21
32
|
Valid client options are:
|
22
33
|
- `api_auth` – arguments for `ApiAuth.sign!`
|
23
|
-
- `
|
24
|
-
- `
|
34
|
+
- `basic_auth` – arguments for basic authentication (either a hash with `:user` and `:pass` keys or a two-element array)
|
35
|
+
- `headers` – a hash of headers for requests
|
36
|
+
- `keep_alive` – timeout for persistent connection in seconds
|
37
|
+
- `max_retries` – maximum number of retries in case `retry_exceptions` option is provided
|
25
38
|
- `on_complete` – callback called on request completion
|
26
39
|
- `on_error` – callback called on request exception
|
27
|
-
- `
|
28
|
-
- `
|
29
|
-
- `
|
40
|
+
- `on_retry` – callback called on request retry
|
41
|
+
- `retry_exceptions` – an array of exception classes to retry
|
42
|
+
- `ssl_context` – ssl context for requests (an `OpenSSL::SSL::SSLContext` instance)
|
43
|
+
- `timeout` – timeout for requests in seconds
|
44
|
+
|
45
|
+
All these options are passed to each request made by this client but can be overriden on per-request basis.
|
30
46
|
|
31
|
-
Extra request options are:
|
47
|
+
Extra per-request only options are:
|
48
|
+
- `body` – raw request body
|
49
|
+
- `form` – hash for urlencoded body
|
50
|
+
- `json` – data for json (also adds `application/json` content-type header)
|
51
|
+
- `metadata` – metadata for request (passed in callbacks)
|
32
52
|
- `params` – becomes `query` for GET and `form` for other requests
|
33
53
|
- `query` – hash for uri query
|
34
|
-
- `form` – hash for urlencoded body
|
35
|
-
- `body` – raw body
|
36
|
-
- `json` – data for json
|
37
|
-
- `headers` – headers for request
|
38
54
|
|
39
|
-
##
|
55
|
+
## Persistent connections
|
56
|
+
If you provide `keep_alive` option to the client or particular request, the connection will be stored in the client and then
|
57
|
+
reused for all following requests to the same origin within specified amount of time.
|
58
|
+
|
59
|
+
Note that, as of now, EzClient will
|
60
|
+
automatically retry the request on any `HTTP::ConnectionError` exception in this case which may possibly result in two requests
|
61
|
+
received by a server (see https://github.com/httprb/http/issues/459).
|
62
|
+
|
63
|
+
## Callbacks and retrying
|
64
|
+
You can provide `on_complete`, `on_error` and `on_retry` callbacks like this:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
on_complete = -> (request, response, metadata) { ... }
|
68
|
+
on_error = -> (request, error, metadata) { ... }
|
69
|
+
on_retry = -> (request, error, metadata) { ... }
|
40
70
|
|
71
|
+
client = EzClient.new(
|
72
|
+
on_complete: on_complete,
|
73
|
+
on_error: on_error,
|
74
|
+
on_retry: on_retry,
|
75
|
+
retry_exceptions: [StandardError],
|
76
|
+
max_retries: 2,
|
77
|
+
)
|
78
|
+
|
79
|
+
response = client.perform!(:get, url, metadata: :hello)
|
80
|
+
```
|
81
|
+
|
82
|
+
The arguments passed into callbacks are:
|
83
|
+
- `request` – an `EzClient::Request` instance
|
84
|
+
- `response` – an `EzClient::Response` instance
|
85
|
+
- `error` – an exception instance
|
86
|
+
- `metadata` - the `metadata` option passed into a request
|
87
|
+
|
88
|
+
## Request object
|
89
|
+
```ruby
|
90
|
+
request = client.request(:post, "http://example.com", json: { a: 1 }, timeout: 15)
|
91
|
+
|
92
|
+
request.verb # => "POST"
|
93
|
+
request.url # => "http://example.com"
|
94
|
+
request.body # => '{"a": 1}'
|
95
|
+
request.headers # => { "Content-Type" => "application/json; charset=UTF-8", ... }
|
96
|
+
```
|
97
|
+
|
98
|
+
## Response object
|
99
|
+
```ruby
|
100
|
+
response = request.perform(...)
|
101
|
+
|
102
|
+
response.body # => String
|
103
|
+
response.headers # => Hash
|
104
|
+
response.code # => Integer
|
105
|
+
|
106
|
+
response.ok? # Returns if request was 2xx status
|
107
|
+
response.redirect? # Returns if request was 3xx status
|
108
|
+
response.client_error? # Returns if request was 4xx status
|
109
|
+
response.server_error? # Returns if request was 5xx status
|
110
|
+
response.error? # Returns if request was 4xx or 5xx status
|
111
|
+
```
|
112
|
+
|
113
|
+
## Contributing
|
41
114
|
Bug reports and pull requests are welcome on GitHub at https://github.com/umbrellio/ezclient.
|
42
115
|
|
43
116
|
## License
|
117
|
+
Released under MIT License.
|
118
|
+
|
119
|
+
## Authors
|
120
|
+
Created by Yuri Smirnov.
|
44
121
|
|
45
|
-
|
122
|
+
<a href="https://github.com/umbrellio/">
|
123
|
+
<img style="float: left;" src="https://umbrellio.github.io/Umbrellio/supported_by_umbrellio.svg" alt="Supported by Umbrellio" width="439" height="72">
|
124
|
+
</a>
|
@@ -2,8 +2,10 @@
|
|
2
2
|
|
3
3
|
module EzClient::CheckOptions
|
4
4
|
def self.call(options, allowed_keys)
|
5
|
-
|
6
|
-
|
5
|
+
unknown_keys = options.keys - allowed_keys
|
6
|
+
|
7
|
+
if unknown_keys.any?
|
8
|
+
raise ArgumentError, "Unrecognized options: #{unknown_keys.map(&:inspect).join(", ")}"
|
7
9
|
end
|
8
10
|
|
9
11
|
options
|
data/lib/ezclient/version.rb
CHANGED
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.11.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-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|