flexirest 1.10.4 → 1.10.5
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/docs/caching.md +8 -0
- data/lib/flexirest/request.rb +3 -3
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/request_spec.rb +30 -0
- 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: 10e663045de906cbfcd8e79800a795c440cb32b5f8e47e4b54b38aa85c450f15
|
4
|
+
data.tar.gz: c6b66793a525149f3fa1eec607c8a5cb8f3fa43fd5386b4e5a845b5e0d8359e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16bf500083c920340ff812d84d6cd6d6a7489783b229eb51822e4b994bba812226574c5831dc34bb1bcbe3c2a98e155ceaceb13c41270309b3573268ffced862
|
7
|
+
data.tar.gz: eff6f4b1699d63af2390b3c7ef970c301d2fc62cd2fda190b57f28132353c00f3a365567193cf9a2c98f5e97c5b7a1027fcf01197af34aa54f26dc57764319e6
|
data/docs/caching.md
CHANGED
@@ -14,6 +14,14 @@ class Person < Flexirest::Base
|
|
14
14
|
end
|
15
15
|
```
|
16
16
|
|
17
|
+
or per request endpoint with:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
class Person < Flexirest::Base
|
21
|
+
get :all, "/people", skip_caching: true
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
17
25
|
If Rails is defined, it will default to using Rails.cache as the cache store, if not, you'll need to configure one with a `ActiveSupport::Cache::Store` compatible object using:
|
18
26
|
|
19
27
|
```ruby
|
data/lib/flexirest/request.rb
CHANGED
@@ -312,7 +312,7 @@ module Flexirest
|
|
312
312
|
|
313
313
|
result = handle_response(response_env, cached)
|
314
314
|
@response_delegate.__setobj__(result)
|
315
|
-
original_object_class.write_cached_response(self, response_env, result)
|
315
|
+
original_object_class.write_cached_response(self, response_env, result) unless @method[:options][:skip_caching]
|
316
316
|
end
|
317
317
|
|
318
318
|
# If this was not a parallel request just return the original result
|
@@ -523,7 +523,7 @@ module Flexirest
|
|
523
523
|
|
524
524
|
def do_request(etag)
|
525
525
|
http_headers = {}
|
526
|
-
http_headers["If-None-Match"] = etag if etag
|
526
|
+
http_headers["If-None-Match"] = etag if etag && !@method[:options][:skip_caching]
|
527
527
|
http_headers["Accept"] = "application/hal+json, application/json;q=0.5"
|
528
528
|
headers.each do |key,value|
|
529
529
|
value = value.join(",") if value.is_a?(Array)
|
@@ -890,7 +890,7 @@ module Flexirest
|
|
890
890
|
result = new_object(body, @overridden_name)
|
891
891
|
result._status = @response.status
|
892
892
|
result._headers = @response.response_headers
|
893
|
-
result._etag = @response.response_headers['ETag']
|
893
|
+
result._etag = @response.response_headers['ETag'] unless @method[:options][:skip_caching]
|
894
894
|
if !object_is_class? && options[:mutable] != false
|
895
895
|
@object._copy_from(result)
|
896
896
|
@object._clean!
|
data/lib/flexirest/version.rb
CHANGED
data/spec/lib/request_spec.rb
CHANGED
@@ -41,6 +41,7 @@ describe Flexirest::Request do
|
|
41
41
|
get :find, "/:id", required: [:id]
|
42
42
|
get :find_cat, "/:id/cat"
|
43
43
|
get :fruits, "/fruits"
|
44
|
+
get :uncached, "/uncached", skip_caching: true
|
44
45
|
get :change, "/change"
|
45
46
|
get :plain, "/plain/:id", plain: true
|
46
47
|
post :create, "/create", rubify_names: true
|
@@ -997,6 +998,35 @@ describe Flexirest::Request do
|
|
997
998
|
expect(object._etag).to eq("123456")
|
998
999
|
end
|
999
1000
|
|
1001
|
+
it "shouldn't expose the etag header if skip_caching is enabled" do
|
1002
|
+
response = ::FaradayResponseMock.new(OpenStruct.new(body: "{}", response_headers: {"ETag" => "123456"}, status: 200))
|
1003
|
+
expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/uncached", an_instance_of(Hash)).and_return(response)
|
1004
|
+
object = ExampleClient.uncached
|
1005
|
+
expect(object._etag).to_not eq("123456")
|
1006
|
+
end
|
1007
|
+
|
1008
|
+
it "shouldn't send the etag header if skip_caching is enabled" do
|
1009
|
+
cached_response = Flexirest::CachedResponse.new(status:200, result:"", response_headers: {})
|
1010
|
+
cached_response.etag = "123456"
|
1011
|
+
expect(ExampleClient).to receive(:read_cached_response).and_return(cached_response)
|
1012
|
+
|
1013
|
+
response = ::FaradayResponseMock.new(OpenStruct.new(body: "{}", response_headers: {"ETag" => "123456"}, status: 200))
|
1014
|
+
expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/uncached", {
|
1015
|
+
api_auth: {
|
1016
|
+
api_auth_access_id: "id123",
|
1017
|
+
api_auth_options: {},
|
1018
|
+
api_auth_secret_key: "secret123"
|
1019
|
+
},
|
1020
|
+
headers: {
|
1021
|
+
"Accept"=>"application/hal+json, application/json;q=0.5",
|
1022
|
+
"Content-Type"=>"application/x-www-form-urlencoded; charset=utf-8"
|
1023
|
+
}
|
1024
|
+
}).and_return(response)
|
1025
|
+
|
1026
|
+
expect(ExampleClient).to_not receive(:write_cached_response)
|
1027
|
+
object = ExampleClient.uncached
|
1028
|
+
end
|
1029
|
+
|
1000
1030
|
it "should expose all headers" do
|
1001
1031
|
response = ::FaradayResponseMock.new(OpenStruct.new(body: "{}", response_headers: {"X-Test-Header" => "true"}, status: 200))
|
1002
1032
|
expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/123", an_instance_of(Hash)).and_return(response)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexirest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.10.
|
4
|
+
version: 1.10.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jeffries
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|