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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 244907ad87d770e992be773f840eedaa08e370cc1b08f66981e13f45b12c4e30
4
- data.tar.gz: 5024e8339f63640f24008f221288f3ee79805b8e80ac9d54980967390188ad66
3
+ metadata.gz: '08d106729153dd903d35de0503fb9534c2ed44b2c1ecce9dbb466a7bb7b50681'
4
+ data.tar.gz: b46480380433093b90d10c1f35121ef342439acd0a7379dbdb2037feee254828
5
5
  SHA512:
6
- metadata.gz: 2a655cb94421b1e9901ed275ca23a243ecce04e6afb97f24c34ff726f081bad2e8170657064c8a309f0271da46982a451759cc1be61212a52b62e2d284718651
7
- data.tar.gz: 1cc627f259122b2c75ed6f239bb31676e8cb9a4e42c34fd23a5968f6a5373b4128da6cddc3fec52c5cec08c9e9f5e2bb0532aba540010004ee4b95e2265214f6
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 | Default | Required |
75
- |------------------|-----------------------------------|-------------------------|----------|
76
- | client | Wrappi::Client | | * |
77
- | path | String | | * |
78
- | verb | Symbol | :get | * |
79
- | default_params | Hash | {} | |
80
- | headers | block | proc { client.headers } | |
81
- | basic_auth | Hash, keys: user, pass | | |
82
- | follow_redirects | Boolean | true | |
83
- | body_type | Symbol, one of: :json,:form,:body | :json | |
84
- | cache | Boolean | false | |
85
- | retry_if | block | | |
86
- | retry_options | block | | |
87
- | around_request | block | | |
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Wrappi
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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.0
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-28 00:00:00.000000000 Z
11
+ date: 2019-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler