wrappi 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -6
- data/lib/wrappi/endpoint.rb +9 -2
- data/lib/wrappi/executer/cacher.rb +3 -3
- data/lib/wrappi/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: 6b03e938b92d159fc98e69873c1c1ca4a5a26ddd9c44867109311421100d981b
|
4
|
+
data.tar.gz: e6aa982e2956cbaef78d4e25db2a341ada0d28a4cdbce08bf5e5d661ffa9be29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edd52700c58b67a461c8d7652ebd01d4d471feff4e6bbba873c0cba9e4b6f485b4b55b2e1638f5ed5ea9ead082248bdb8ff8f542e76411d62a9831fd22fb62fe
|
7
|
+
data.tar.gz: 396cd19b742ad2d2df71629afb01ab5796607dd999606701e9bb36830cd4b17fe3d636692350ae916953c610de5ca5f15782879e7ea5ace9910f79195231af89
|
data/README.md
CHANGED
@@ -266,7 +266,7 @@ end
|
|
266
266
|
| follow_redirects | Boolean `or` block -> Boolean | true | |
|
267
267
|
| body_type | Symbol, one of: :json,:form,:body | :json | |
|
268
268
|
| cache | Boolean `or` block -> Boolean | proc { options[:cache] }| |
|
269
|
-
| cache_options |
|
269
|
+
| cache_options | block -> Hash | | |
|
270
270
|
| retry_if | block | | |
|
271
271
|
| retry_options | Hash `or` block -> Hash | | |
|
272
272
|
| around_request | block | | |
|
@@ -484,16 +484,17 @@ It holds the common configuration for all the endpoints (`Wrappi::Endpoint`).
|
|
484
484
|
default: `proc { options[:cache] }`
|
485
485
|
- __cache_options:__ Options for the `cache` to receive on `write`
|
486
486
|
```ruby
|
487
|
-
cache_options
|
487
|
+
cache_options do
|
488
|
+
{ expires_in: 12, another_opt: true }
|
489
|
+
end
|
488
490
|
```
|
489
491
|
|
490
492
|
default: `{}`
|
491
493
|
- __retry_if:__ Block to evaluate if request has to be retried. In the block are
|
492
|
-
yielded `Response`
|
494
|
+
yielded `Response` instance. If the block returns `true` the request will be retried.
|
493
495
|
```ruby
|
494
|
-
retry_if do |response
|
495
|
-
|
496
|
-
response.error? # => true or false
|
496
|
+
retry_if do |response|
|
497
|
+
response.status != 200 # => true or false
|
497
498
|
end
|
498
499
|
```
|
499
500
|
|
data/lib/wrappi/endpoint.rb
CHANGED
@@ -3,7 +3,7 @@ module Wrappi
|
|
3
3
|
class Endpoint < Miller.base(
|
4
4
|
:verb, :client, :path, :default_params,
|
5
5
|
:headers, :follow_redirects, :basic_auth,
|
6
|
-
:body_type, :retry_options, :cache,
|
6
|
+
:body_type, :retry_options, :cache, #:cache_options,
|
7
7
|
:async_callback,
|
8
8
|
default_config: {
|
9
9
|
verb: :get,
|
@@ -14,7 +14,7 @@ module Wrappi
|
|
14
14
|
follow_redirects: true,
|
15
15
|
body_type: :json,
|
16
16
|
cache: proc { options[:cache] },
|
17
|
-
cache_options: {},
|
17
|
+
# cache_options: {},
|
18
18
|
async_callback: proc {},
|
19
19
|
basic_auth: proc { client.basic_auth }
|
20
20
|
}
|
@@ -73,6 +73,10 @@ module Wrappi
|
|
73
73
|
@retry_if = block
|
74
74
|
end
|
75
75
|
|
76
|
+
def self.cache_options(&block)
|
77
|
+
@cache_options = block
|
78
|
+
end
|
79
|
+
|
76
80
|
def perform_async_callback(async_options = {})
|
77
81
|
instance_exec(async_options, &async_callback)
|
78
82
|
end
|
@@ -89,6 +93,9 @@ module Wrappi
|
|
89
93
|
def retry_if
|
90
94
|
self.class.instance_variable_get(:@retry_if)
|
91
95
|
end
|
96
|
+
def cache_options
|
97
|
+
self.class.instance_variable_get(:@cache_options)
|
98
|
+
end
|
92
99
|
|
93
100
|
private
|
94
101
|
|
@@ -10,7 +10,7 @@ module Wrappi
|
|
10
10
|
cached = cache.read(cache_key)
|
11
11
|
return CachedResponse.new(cached) if cached
|
12
12
|
response = yield
|
13
|
-
cache.write(cache_key, response.to_h, cache_options) if response.success?
|
13
|
+
cache.write(cache_key, response.to_h, cache_options(response)) if response.success?
|
14
14
|
response
|
15
15
|
end
|
16
16
|
|
@@ -27,8 +27,8 @@ module Wrappi
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def cache_options
|
31
|
-
endpoint.cache_options
|
30
|
+
def cache_options(response)
|
31
|
+
endpoint.cache_options ? endpoint.cache_options.call(response) : {}
|
32
32
|
end
|
33
33
|
|
34
34
|
def cache
|
data/lib/wrappi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wrappi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artur Pañach
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04
|
11
|
+
date: 2019-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|