flexirest 1.10.4 → 1.10.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a072753fe6a84d8f13ae90d26cdff777e78fc129d4555b5188ae0c0be35ad78
4
- data.tar.gz: 7e6ecfe247cc9f021a3e35f9cf4d3b28a6743694b53a2ca32c0ea988a2113276
3
+ metadata.gz: 10e663045de906cbfcd8e79800a795c440cb32b5f8e47e4b54b38aa85c450f15
4
+ data.tar.gz: c6b66793a525149f3fa1eec607c8a5cb8f3fa43fd5386b4e5a845b5e0d8359e3
5
5
  SHA512:
6
- metadata.gz: 561fdb72c84a9bd3d0a353f46d4761179df66f3e45967bec4b4b620c6f818dca0058388b5f83c2d2455da1f21fa90a72ec0f73ab056fbf086dab522cc8f48fd7
7
- data.tar.gz: 95d6f2852392a23c82a5ae0e157a9ad1bc391c4846e79946eab75236c1c3b409c8193a3550e42b9e19676b94a3cccda28e6f0ddf438e47b3e77de9c66669006a
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
@@ -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!
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.10.4"
2
+ VERSION = "1.10.5"
3
3
  end
@@ -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
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-03-16 00:00:00.000000000 Z
11
+ date: 2021-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler