ezclient 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -0
- data/lib/ezclient/client.rb +14 -10
- data/lib/ezclient/request.rb +7 -2
- data/lib/ezclient/version.rb +1 -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: 0f04c94ba55e1fc20af6d67ffe3e5e811fcd03ede8a16bb5270a5eacd4aa7459
|
4
|
+
data.tar.gz: 67f275910008833ce3b7cc0ac3ebdba937555bb4ea64c3d71d4c4611f9f497d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73c1fe86f62d64d1e34ac69a8299513d451981c834f71099aa48bffabe13d65f123f33dcf9721e46ff0508c165302339337f487bb5899c1e5451bda6e41868e4
|
7
|
+
data.tar.gz: d222c99a6026a2b9e6b470068a7cff3819a3f41a5579a25e113888c15b42aed97fa27e31656e55f9208e452699b7ab222faafb55714ee2c12d5ec27464f6492f
|
data/README.md
CHANGED
@@ -11,6 +11,31 @@ gem "ezclient"
|
|
11
11
|
gem "http", github: "httprb/http"
|
12
12
|
```
|
13
13
|
|
14
|
+
## Usage
|
15
|
+
```ruby
|
16
|
+
client = EzClient.new(client_options)
|
17
|
+
client.perform!(:get, "https://example.com", params: { a: 1 })
|
18
|
+
# Performs a GET request to https://example.com/?a=1
|
19
|
+
```
|
20
|
+
|
21
|
+
Valid client options are:
|
22
|
+
- `api_auth` – arguments for `ApiAuth.sign!`
|
23
|
+
- `keep_alive` – timeout for persitent connection
|
24
|
+
- `max_retries` – max number of retries in case of errors
|
25
|
+
- `on_complete` – callback called on request completion
|
26
|
+
- `on_error` – callback called on request exception
|
27
|
+
- `retry_exceptions` – exception classes to retry
|
28
|
+
- `ssl_context` – ssl context for requests
|
29
|
+
- `timeout` – timeout for requests
|
30
|
+
|
31
|
+
Extra request options are:
|
32
|
+
- `params` – becomes `query` for GET and `form` for other requests
|
33
|
+
- `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
|
+
|
14
39
|
## Contributing
|
15
40
|
|
16
41
|
Bug reports and pull requests are welcome on GitHub at https://github.com/umbrellio/ezclient.
|
data/lib/ezclient/client.rb
CHANGED
@@ -7,7 +7,7 @@ class EzClient::Client
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def request(verb, url, **options)
|
10
|
-
options = { **default_options, **options }
|
10
|
+
options = { **default_options, **options } # TODO: raise on unknown options
|
11
11
|
|
12
12
|
keep_alive_timeout = options.delete(:keep_alive)
|
13
13
|
api_auth = options.delete(:api_auth)
|
@@ -41,14 +41,18 @@ class EzClient::Client
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def default_options
|
44
|
-
|
45
|
-
api_auth
|
46
|
-
keep_alive
|
47
|
-
max_retries
|
48
|
-
on_complete
|
49
|
-
on_error
|
50
|
-
retry_exceptions
|
51
|
-
|
52
|
-
|
44
|
+
keys = %i[
|
45
|
+
api_auth
|
46
|
+
keep_alive
|
47
|
+
max_retries
|
48
|
+
on_complete
|
49
|
+
on_error
|
50
|
+
retry_exceptions
|
51
|
+
ssl_context
|
52
|
+
timeout
|
53
|
+
]
|
54
|
+
|
55
|
+
# RUBY25: Hash#slice
|
56
|
+
options.select { |key| keys.include?(key) }
|
53
57
|
end
|
54
58
|
end
|
data/lib/ezclient/request.rb
CHANGED
@@ -64,15 +64,20 @@ class EzClient::Request
|
|
64
64
|
|
65
65
|
def http_options
|
66
66
|
# RUBY25: Hash#slice
|
67
|
-
options.select { |key| [:
|
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
|
68
72
|
end
|
69
73
|
|
70
74
|
def perform_request
|
71
75
|
retries = 0
|
76
|
+
request_options = http_client.default_options.merge(ssl_context: options[:ssl_context])
|
72
77
|
|
73
78
|
begin
|
74
79
|
retry_on_connection_error do
|
75
|
-
http_client.perform(http_request,
|
80
|
+
http_client.perform(http_request, request_options)
|
76
81
|
end
|
77
82
|
rescue *retried_exceptions
|
78
83
|
if retries < max_retries.to_i
|
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.7.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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -178,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
178
|
version: '0'
|
179
179
|
requirements: []
|
180
180
|
rubyforge_project:
|
181
|
-
rubygems_version: 2.7.
|
181
|
+
rubygems_version: 2.7.6
|
182
182
|
signing_key:
|
183
183
|
specification_version: 4
|
184
184
|
summary: An HTTP gem wrapper for easy persistent connections and more.
|