wrappi 0.2.0 → 0.2.1
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/README.md +21 -14
- data/lib/wrappi/endpoint.rb +3 -2
- data/lib/wrappi/executer/cacher.rb +5 -1
- 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: '08d106729153dd903d35de0503fb9534c2ed44b2c1ecce9dbb466a7bb7b50681'
|
4
|
+
data.tar.gz: b46480380433093b90d10c1f35121ef342439acd0a7379dbdb2037feee254828
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa76a8e7296b86b92960609923faff2187e2f368574e71ce054538facd2e999138d6c744b7f2f6e98b7688360ec2973952c590c7171237a70b5cf94cd994f964
|
7
|
+
data.tar.gz: 4dcc8da672cc92e2fc7dbe013752acad62a2c5f9eb8fdafc39ffe22ead09d9a3ff9a638b770907d9ff595dbc6d36c3467fe9714368d186126e61584f74b2d44e
|
data/README.md
CHANGED
@@ -71,20 +71,21 @@ user.body # => {"login"=>"arturictus", "id"=>1930175, ...}
|
|
71
71
|
|
72
72
|
#### Endpoint
|
73
73
|
|
74
|
-
| Name | Type
|
75
|
-
|
76
|
-
| client | Wrappi::Client
|
77
|
-
| path | String
|
78
|
-
| verb | Symbol
|
79
|
-
| default_params | Hash
|
80
|
-
| headers | block
|
81
|
-
| basic_auth | Hash
|
82
|
-
| follow_redirects | Boolean
|
83
|
-
| body_type | Symbol, one of: :json,:form,:body
|
84
|
-
| cache | Boolean
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
74
|
+
| Name | Type | Default | Required |
|
75
|
+
|------------------|------------------------------------------|-------------------------|----------|
|
76
|
+
| client | Wrappi::Client | | * |
|
77
|
+
| path | String | | * |
|
78
|
+
| verb | Symbol | :get | * |
|
79
|
+
| default_params | Hash || block -> Hash | {} | |
|
80
|
+
| headers | Hash || block -> Hash | proc { client.headers } | |
|
81
|
+
| basic_auth | Hash (keys: user, pass) || block -> Hash | | |
|
82
|
+
| follow_redirects | Boolean || block -> Boolean | true | |
|
83
|
+
| body_type | Symbol, one of: :json,:form,:body | :json | |
|
84
|
+
| cache | Boolean || block -> Boolean | false | |
|
85
|
+
| cache_options | Hash || block -> Hash | {} | |
|
86
|
+
| retry_if | block | | |
|
87
|
+
| retry_options | Hash || block -> Hash | {} | |
|
88
|
+
| around_request | block | | |
|
88
89
|
|
89
90
|
### Client
|
90
91
|
|
@@ -249,6 +250,12 @@ It holds the common configuration for all the endpoints (`Wrappi::Endpoint`).
|
|
249
250
|
- __cache:__ Cache the request if successful.
|
250
251
|
|
251
252
|
default: `false`
|
253
|
+
- __cache_options:__ Options for the `cache` to receive on `write`
|
254
|
+
```ruby
|
255
|
+
cache_options expires_in: 12, another_opt: true
|
256
|
+
```
|
257
|
+
|
258
|
+
default: `{}`
|
252
259
|
- __retry_if:__ Block to evaluate if request has to be retried. In the block are
|
253
260
|
yielded `Response` and `Endpoint` instances. If the block returns `true` the request will be retried.
|
254
261
|
```ruby
|
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
|
default_config: {
|
8
8
|
verb: :get,
|
9
9
|
client: proc { raise 'client not set' }, # TODO: add proper error
|
@@ -12,7 +12,8 @@ module Wrappi
|
|
12
12
|
headers: proc { client.headers },
|
13
13
|
follow_redirects: true,
|
14
14
|
body_type: :json,
|
15
|
-
cache: false
|
15
|
+
cache: false,
|
16
|
+
cache_options: {}
|
16
17
|
}
|
17
18
|
)
|
18
19
|
attr_reader :input_params, :options
|
@@ -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) if response.success?
|
13
|
+
cache.write(cache_key, response.to_h, cache_options) if response.success?
|
14
14
|
response
|
15
15
|
end
|
16
16
|
|
@@ -27,6 +27,10 @@ module Wrappi
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
def cache_options
|
31
|
+
endpoint.cache_options
|
32
|
+
end
|
33
|
+
|
30
34
|
def cache
|
31
35
|
endpoint.client.cache
|
32
36
|
end
|
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.1
|
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-01-
|
11
|
+
date: 2019-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|