ezclient 0.6.1 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 364e89134c8a1b2d916bf1eed66ef13d5e1bb54bfe6bcbb5e031e3452ba0cb8c
4
- data.tar.gz: 5e7c6c004ec2601a2c0ee1ff0a413d12d2e8de8561ede3c34bf34c660d8ca6f6
3
+ metadata.gz: 0f04c94ba55e1fc20af6d67ffe3e5e811fcd03ede8a16bb5270a5eacd4aa7459
4
+ data.tar.gz: 67f275910008833ce3b7cc0ac3ebdba937555bb4ea64c3d71d4c4611f9f497d1
5
5
  SHA512:
6
- metadata.gz: dbcae1b6a8470fe15f2312c118d08729fe121b7a681c5db2fa8b99bc2fca23cf008f2c133c35788829a87d6f54490dbbce940c0c8f79860cee56d998a518c46c
7
- data.tar.gz: bae8bfc733d1e567175fb60203e9901d9d13ecc689a264fcdf1441bcdc2596d113b5a18f0d5c68e977aaab0089b15ea43afffffb8cf1f4d145621cd234e480c8
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.
@@ -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: options[:api_auth],
46
- keep_alive: options[:keep_alive],
47
- max_retries: options[:max_retries],
48
- on_complete: options[:on_complete],
49
- on_error: options[:on_error],
50
- retry_exceptions: options[:retry_exceptions],
51
- timeout: options[:default_timeout],
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
@@ -64,15 +64,20 @@ class EzClient::Request
64
64
 
65
65
  def http_options
66
66
  # RUBY25: Hash#slice
67
- options.select { |key| [:params, :form, :json, :body, :headers].include?(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, http_client.default_options)
80
+ http_client.perform(http_request, request_options)
76
81
  end
77
82
  rescue *retried_exceptions
78
83
  if retries < max_retries.to_i
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EzClient
4
- VERSION = "0.6.1"
4
+ VERSION = "0.7.0"
5
5
  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.6.1
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-16 00:00:00.000000000 Z
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.4
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.