flexirest 1.10.3 → 1.10.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +35 -0
- data/CHANGELOG.md +24 -0
- data/README.md +2 -2
- data/docs/authentication.md +24 -0
- data/docs/caching.md +8 -0
- data/docs/raw-requests.md +1 -1
- data/lib/flexirest/configuration.rb +18 -0
- data/lib/flexirest/logger.rb +4 -4
- data/lib/flexirest/request.rb +29 -7
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/base_without_validation_spec.rb +2 -0
- data/spec/lib/request_spec.rb +106 -2
- metadata +3 -3
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e785cb379a1ed7536d5486bf5fc10c15a0afebbcc5fc3a88906d6b52aa19ed4
|
4
|
+
data.tar.gz: 7960a64126527e0d553551de83a9c4129880880b6f9d783eac6a7551695e5b87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69729e7916e4b08d10e2d8469c73e40a403302ff1d61fa1d922634e7be13727cf3785d8ed04481f4f1c28d5da0271499fad45e3b0d38bc1e926592d01cdb58ef
|
7
|
+
data.tar.gz: 2f2a0ecf6a6c54e25dea39d9340f049211d273c7e1c8a30f65daa091d35a281eb50678d4f26f849f7b65428fce06faf83737b7a67af810074aec522c92576698
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Build
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.5', '2.6', '2.7', '3.0']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
+
# uses: ruby/setup-ruby@v1
|
30
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- name: Run tests
|
35
|
+
run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.10.7
|
4
|
+
|
5
|
+
Bugfix:
|
6
|
+
|
7
|
+
- Flexirest didn't find the elements if the specified root wasn't found, e.g. in error conditions (thanks to Jolyon Pawlyn/@jpawlyn for the PR)
|
8
|
+
|
9
|
+
## 1.10.6
|
10
|
+
|
11
|
+
Bugfix:
|
12
|
+
|
13
|
+
- Flexirest was erroring if Rails.logger was defined but was nil (thanks to Alex Oxte for the PR)
|
14
|
+
|
15
|
+
## 1.10.5
|
16
|
+
|
17
|
+
Enhancement:
|
18
|
+
|
19
|
+
- Allow skipping of caching for single endpoints
|
20
|
+
|
21
|
+
## 1.10.4
|
22
|
+
|
23
|
+
Enhancement:
|
24
|
+
|
25
|
+
- Implement support for in-header Basic Auth (thanks to François Ferrandis for the PR)
|
26
|
+
|
3
27
|
## 1.10.3
|
4
28
|
|
5
29
|
Enhancement:
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Flexirest
|
2
2
|
|
3
3
|
> Access your REST APIs in a flexible way.
|
4
|
-
>
|
4
|
+
>
|
5
5
|
> Write your API classes in an ActiveRecord-style; like ActiveResource but Flexirest works where the resource naming doesn't follow Rails conventions, it has built-in caching and is much more flexible.
|
6
6
|
|
7
|
-
[![Build
|
7
|
+
[![Build](https://github.com/flexirest/flexirest/actions/workflows/build_test.yml/badge.svg)](https://github.com/flexirest/flexirest/actions/workflows/build.yml)
|
8
8
|
[![Coverage Status](https://coveralls.io/repos/github/flexirest/flexirest/badge.svg?branch=master)](https://coveralls.io/github/flexirest/flexirest?branch=master)
|
9
9
|
[![Code Climate](https://codeclimate.com/github/flexirest/flexirest.png)](https://codeclimate.com/github/flexirest/flexirest)
|
10
10
|
[![Gem Version](https://badge.fury.io/rb/flexirest.png)](http://badge.fury.io/rb/flexirest)
|
data/docs/authentication.md
CHANGED
@@ -40,6 +40,30 @@ Or if it's called from a class context:
|
|
40
40
|
Person.find(id: 1234)
|
41
41
|
```
|
42
42
|
|
43
|
+
### Basic authentication method
|
44
|
+
|
45
|
+
Flexirest provides two methods for HTTP Basic Auth. The default method is `:url`:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
class Person < Flexirest::Base
|
49
|
+
basic_auth_method :url
|
50
|
+
end
|
51
|
+
# Includes the credentials in the URL:
|
52
|
+
# https://my_username:my_password@example.com/
|
53
|
+
```
|
54
|
+
|
55
|
+
But you might want to keep the credentials out of your logs and use the `:header` method:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
class Person < Flexirest::Base
|
59
|
+
basic_auth_method :header
|
60
|
+
end
|
61
|
+
# Clean URL:
|
62
|
+
# https://example.com/
|
63
|
+
# with the base64 encoded credentials:
|
64
|
+
# Authorization: Basic YXBpOmViNjkzZWMtODI1MmMtZDYzMDEtMDJmZDAtZDBmYjctYzM0ODU=
|
65
|
+
```
|
66
|
+
|
43
67
|
## Api-Auth
|
44
68
|
|
45
69
|
Using the [Api-Auth](https://github.com/mgomes/api_auth) integration it is very easy to sign requests. Include the Api-Auth gem in your `Gemfile` and then add it to your application. Then simply configure Api-Auth one time in your app and all requests will be signed from then on.
|
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/docs/raw-requests.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# *Flexirest:* Raw requests
|
2
2
|
|
3
|
-
Sometimes you have
|
3
|
+
Sometimes you have a URL that you just want to force through, but have the response handled in the same way as normal objects or you want to have the callbacks run (say for authentication). The easiest way to do that is to call `_request` on the class:
|
4
4
|
|
5
5
|
```ruby
|
6
6
|
class Person < Flexirest::Base
|
@@ -135,6 +135,23 @@ module Flexirest
|
|
135
135
|
@@password = value
|
136
136
|
end
|
137
137
|
|
138
|
+
DEFAULT_BASIC_URL_METHOD = :url
|
139
|
+
|
140
|
+
def basic_auth_method(value = nil)
|
141
|
+
if value.nil? # Used as a getter method
|
142
|
+
if @basic_auth_method.nil? && superclass.respond_to?(:basic_auth_method)
|
143
|
+
superclass.basic_auth_method
|
144
|
+
else
|
145
|
+
@basic_auth_method || DEFAULT_BASIC_URL_METHOD
|
146
|
+
end
|
147
|
+
else # Used as a setter method
|
148
|
+
unless [:header, :url].include?(value)
|
149
|
+
raise %(Invalid basic_auth_method #{value.inspect}. Valid methods are :url (default) and :header.)
|
150
|
+
end
|
151
|
+
@basic_auth_method = value
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
138
155
|
def alias_type(value = nil)
|
139
156
|
@alias_type ||= nil
|
140
157
|
if value.nil?
|
@@ -311,6 +328,7 @@ module Flexirest
|
|
311
328
|
@adapter = Faraday.default_adapter
|
312
329
|
@api_auth_access_id = nil
|
313
330
|
@api_auth_secret_key = nil
|
331
|
+
@basic_auth_method = :url
|
314
332
|
end
|
315
333
|
|
316
334
|
private
|
data/lib/flexirest/logger.rb
CHANGED
@@ -17,7 +17,7 @@ module Flexirest
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.debug(message)
|
20
|
-
if defined?(Rails) && Rails.
|
20
|
+
if defined?(Rails) && Rails.logger.present?
|
21
21
|
Rails.logger.debug(message)
|
22
22
|
elsif @logfile
|
23
23
|
if @logfile.is_a?(String)
|
@@ -33,7 +33,7 @@ module Flexirest
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def self.info(message)
|
36
|
-
if defined?(Rails) && Rails.
|
36
|
+
if defined?(Rails) && Rails.logger.present?
|
37
37
|
Rails.logger.info(message)
|
38
38
|
elsif @logfile
|
39
39
|
if @logfile.is_a?(String)
|
@@ -49,7 +49,7 @@ module Flexirest
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def self.warn(message)
|
52
|
-
if defined?(Rails) && Rails.
|
52
|
+
if defined?(Rails) && Rails.logger.present?
|
53
53
|
Rails.logger.warn(message)
|
54
54
|
elsif @logfile
|
55
55
|
if @logfile.is_a?(String)
|
@@ -65,7 +65,7 @@ module Flexirest
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def self.error(message)
|
68
|
-
if defined?(Rails) && Rails.
|
68
|
+
if defined?(Rails) && Rails.logger.present?
|
69
69
|
Rails.logger.error(message)
|
70
70
|
elsif @logfile
|
71
71
|
if @logfile.is_a?(String)
|
data/lib/flexirest/request.rb
CHANGED
@@ -32,6 +32,10 @@ module Flexirest
|
|
32
32
|
!@object.respond_to?(:dirty?)
|
33
33
|
end
|
34
34
|
|
35
|
+
def model_class
|
36
|
+
object_is_class? ? @object : @object.class
|
37
|
+
end
|
38
|
+
|
35
39
|
def class_name
|
36
40
|
if object_is_class?
|
37
41
|
@object.name
|
@@ -124,6 +128,18 @@ module Flexirest
|
|
124
128
|
ret
|
125
129
|
end
|
126
130
|
|
131
|
+
def inject_basic_auth_in_url(url)
|
132
|
+
url.gsub!(%r{//(.)}, "//#{username}:#{password}@\\1") if !url[%r{//[^/]*:[^/]*@}]
|
133
|
+
end
|
134
|
+
|
135
|
+
def using_basic_auth?
|
136
|
+
!!username
|
137
|
+
end
|
138
|
+
|
139
|
+
def basic_auth_digest
|
140
|
+
Base64.strict_encode64("#{username}:#{password}")
|
141
|
+
end
|
142
|
+
|
127
143
|
def request_body_type
|
128
144
|
if @method[:options][:request_body_type]
|
129
145
|
@method[:options][:request_body_type]
|
@@ -296,7 +312,7 @@ module Flexirest
|
|
296
312
|
|
297
313
|
result = handle_response(response_env, cached)
|
298
314
|
@response_delegate.__setobj__(result)
|
299
|
-
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]
|
300
316
|
end
|
301
317
|
|
302
318
|
# If this was not a parallel request just return the original result
|
@@ -507,7 +523,7 @@ module Flexirest
|
|
507
523
|
|
508
524
|
def do_request(etag)
|
509
525
|
http_headers = {}
|
510
|
-
http_headers["If-None-Match"] = etag if etag
|
526
|
+
http_headers["If-None-Match"] = etag if etag && !@method[:options][:skip_caching]
|
511
527
|
http_headers["Accept"] = "application/hal+json, application/json;q=0.5"
|
512
528
|
headers.each do |key,value|
|
513
529
|
value = value.join(",") if value.is_a?(Array)
|
@@ -527,7 +543,9 @@ module Flexirest
|
|
527
543
|
else
|
528
544
|
_, @base_url, @url = parts
|
529
545
|
end
|
530
|
-
|
546
|
+
if using_basic_auth? && model_class.basic_auth_method == :url
|
547
|
+
inject_basic_auth_in_url(base_url)
|
548
|
+
end
|
531
549
|
connection = Flexirest::ConnectionManager.get_connection(base_url)
|
532
550
|
end
|
533
551
|
else
|
@@ -540,7 +558,9 @@ module Flexirest
|
|
540
558
|
else
|
541
559
|
base_url = parts[0]
|
542
560
|
end
|
543
|
-
|
561
|
+
if using_basic_auth? && model_class.basic_auth_method == :url
|
562
|
+
inject_basic_auth_in_url(base_url)
|
563
|
+
end
|
544
564
|
connection = Flexirest::ConnectionManager.get_connection(base_url)
|
545
565
|
end
|
546
566
|
if @method[:options][:direct]
|
@@ -566,6 +586,8 @@ module Flexirest
|
|
566
586
|
:api_auth_secret_key => api_auth_secret_key,
|
567
587
|
:api_auth_options => api_auth_options
|
568
588
|
}
|
589
|
+
elsif using_basic_auth? && model_class.basic_auth_method == :header
|
590
|
+
http_headers["Authorization"] = "Basic #{basic_auth_digest}"
|
569
591
|
end
|
570
592
|
if @method[:options][:timeout]
|
571
593
|
request_options[:timeout] = @method[:options][:timeout]
|
@@ -840,14 +862,14 @@ module Flexirest
|
|
840
862
|
|
841
863
|
if ignore_root
|
842
864
|
[ignore_root].flatten.each do |key|
|
843
|
-
body = body[key.to_s]
|
865
|
+
body = body[key.to_s] if body.has_key?(key.to_s)
|
844
866
|
end
|
845
867
|
end
|
846
868
|
elsif is_xml_response?
|
847
869
|
body = @response.body.blank? ? {} : Crack::XML.parse(@response.body)
|
848
870
|
if ignore_root
|
849
871
|
[ignore_root].flatten.each do |key|
|
850
|
-
body = body[key.to_s]
|
872
|
+
body = body[key.to_s] if body.has_key?(key.to_s)
|
851
873
|
end
|
852
874
|
elsif options[:ignore_xml_root]
|
853
875
|
Flexirest::Logger.warn("Using `ignore_xml_root` is deprecated, please switch to `ignore_root`")
|
@@ -868,7 +890,7 @@ module Flexirest
|
|
868
890
|
result = new_object(body, @overridden_name)
|
869
891
|
result._status = @response.status
|
870
892
|
result._headers = @response.response_headers
|
871
|
-
result._etag = @response.response_headers['ETag']
|
893
|
+
result._etag = @response.response_headers['ETag'] unless @method[:options][:skip_caching]
|
872
894
|
if !object_is_class? && options[:mutable] != false
|
873
895
|
@object._copy_from(result)
|
874
896
|
@object._clean!
|
data/lib/flexirest/version.rb
CHANGED
@@ -236,6 +236,8 @@ describe Flexirest::BaseWithoutValidation do
|
|
236
236
|
|
237
237
|
Flexirest::Base.base_url = "https://www.example.com/api/v2"
|
238
238
|
expect(OutsideBaseExample.base_url).to eq("https://www.example.com/api/v2")
|
239
|
+
ensure
|
240
|
+
Flexirest::Base.base_url = 'http://www.example.com'
|
239
241
|
end
|
240
242
|
|
241
243
|
it "should include the Mapping module" do
|
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
|
@@ -81,6 +82,26 @@ describe Flexirest::Request do
|
|
81
82
|
get :all, "/"
|
82
83
|
end
|
83
84
|
|
85
|
+
class AuthenticatedBasicHeaderExampleClient < Flexirest::Base
|
86
|
+
base_url "http://www.example.com"
|
87
|
+
username "john"
|
88
|
+
password "smith"
|
89
|
+
basic_auth_method :header
|
90
|
+
get :all, "/"
|
91
|
+
end
|
92
|
+
|
93
|
+
class AuthenticatedBasicHeaderExampleClientChildClass < AuthenticatedBasicHeaderExampleClient
|
94
|
+
get :child_method, "/"
|
95
|
+
end
|
96
|
+
|
97
|
+
class AuthenticatedBasicUrlExampleClient < Flexirest::Base
|
98
|
+
base_url "http://www.example.com"
|
99
|
+
username "john"
|
100
|
+
password "smith"
|
101
|
+
basic_auth_method :url
|
102
|
+
get :all, "/"
|
103
|
+
end
|
104
|
+
|
84
105
|
class AuthenticatedProcExampleClient < Flexirest::Base
|
85
106
|
base_url "http://www.example.com"
|
86
107
|
username Proc.new { |obj| obj ? "bill-#{obj.id}" : "bill" }
|
@@ -185,6 +206,16 @@ describe Flexirest::Request do
|
|
185
206
|
}
|
186
207
|
end
|
187
208
|
|
209
|
+
class IgnoredRootWithUnexpectedResponseExampleClient < ExampleClient
|
210
|
+
get :root, "/root", ignore_root: "feed", fake: %Q{
|
211
|
+
{
|
212
|
+
"error": {
|
213
|
+
"message": "Example Error"
|
214
|
+
}
|
215
|
+
}
|
216
|
+
}
|
217
|
+
end
|
218
|
+
|
188
219
|
class IgnoredMultiLevelRootExampleClient < ExampleClient
|
189
220
|
get :multi_level_root, "/multi-level-root", ignore_root: [:response, "data", "object"], fake: %Q{
|
190
221
|
{
|
@@ -314,13 +345,53 @@ describe Flexirest::Request do
|
|
314
345
|
expect(servers.uniq.count).to eq(2)
|
315
346
|
end
|
316
347
|
|
317
|
-
it "should
|
348
|
+
it "should use the URL method for Basic HTTP Auth when no basic_auth_method is set" do
|
349
|
+
mocked_response = ::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{}))
|
350
|
+
|
318
351
|
connection = double(Flexirest::Connection).as_null_object
|
319
352
|
expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://john:smith@www.example.com").and_return(connection)
|
320
|
-
expect(connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(
|
353
|
+
expect(connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(mocked_response)
|
321
354
|
AuthenticatedExampleClient.all
|
322
355
|
end
|
323
356
|
|
357
|
+
it "should use the headers method for Basic auth when basic_auth_method is set to :header" do
|
358
|
+
mocked_response = ::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{}))
|
359
|
+
headers_including_auth = hash_including({ "Authorization" => "Basic am9objpzbWl0aA==" })
|
360
|
+
|
361
|
+
connection = double(Flexirest::Connection).as_null_object
|
362
|
+
expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://www.example.com").and_return(connection)
|
363
|
+
expect(connection).to receive(:get).with("/", hash_including(headers: headers_including_auth)).and_return(mocked_response)
|
364
|
+
AuthenticatedBasicHeaderExampleClient.all
|
365
|
+
end
|
366
|
+
|
367
|
+
it "should raise an error if Basic HTTP method is not :header or :url" do
|
368
|
+
expect do
|
369
|
+
AuthenticatedExampleClient.class_eval do
|
370
|
+
basic_auth_method :some_invalid_value
|
371
|
+
end
|
372
|
+
end.to raise_error(RuntimeError, "Invalid basic_auth_method :some_invalid_value. Valid methods are :url (default) and :header.")
|
373
|
+
end
|
374
|
+
|
375
|
+
it "should use the setting set on the parent class" do
|
376
|
+
mocked_response = ::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{}))
|
377
|
+
headers_including_auth = hash_including({ "Authorization" => "Basic am9objpzbWl0aA==" })
|
378
|
+
|
379
|
+
connection = double(Flexirest::Connection).as_null_object
|
380
|
+
expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://www.example.com").and_return(connection)
|
381
|
+
expect(connection).to receive(:get).with("/", hash_including(headers: headers_including_auth)).and_return(mocked_response)
|
382
|
+
AuthenticatedBasicHeaderExampleClientChildClass.child_method
|
383
|
+
end
|
384
|
+
|
385
|
+
it "should use the URL method for Basic auth when basic_auth_method is set to :url (and not include Authorization header)" do
|
386
|
+
mocked_response = ::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{}))
|
387
|
+
headers_not_including_auth = hash_excluding("Authorization")
|
388
|
+
|
389
|
+
connection = double(Flexirest::Connection).as_null_object
|
390
|
+
expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://john:smith@www.example.com").and_return(connection)
|
391
|
+
expect(connection).to receive(:get).with("/", headers: headers_not_including_auth).and_return(mocked_response)
|
392
|
+
AuthenticatedBasicUrlExampleClient.all
|
393
|
+
end
|
394
|
+
|
324
395
|
it "should get an HTTP connection with basic authentication using procs when called in a class context" do
|
325
396
|
connection = double(Flexirest::Connection).as_null_object
|
326
397
|
expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://bill:jones@www.example.com").and_return(connection)
|
@@ -937,6 +1008,35 @@ describe Flexirest::Request do
|
|
937
1008
|
expect(object._etag).to eq("123456")
|
938
1009
|
end
|
939
1010
|
|
1011
|
+
it "shouldn't expose the etag header if skip_caching is enabled" do
|
1012
|
+
response = ::FaradayResponseMock.new(OpenStruct.new(body: "{}", response_headers: {"ETag" => "123456"}, status: 200))
|
1013
|
+
expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/uncached", an_instance_of(Hash)).and_return(response)
|
1014
|
+
object = ExampleClient.uncached
|
1015
|
+
expect(object._etag).to_not eq("123456")
|
1016
|
+
end
|
1017
|
+
|
1018
|
+
it "shouldn't send the etag header if skip_caching is enabled" do
|
1019
|
+
cached_response = Flexirest::CachedResponse.new(status:200, result:"", response_headers: {})
|
1020
|
+
cached_response.etag = "123456"
|
1021
|
+
expect(ExampleClient).to receive(:read_cached_response).and_return(cached_response)
|
1022
|
+
|
1023
|
+
response = ::FaradayResponseMock.new(OpenStruct.new(body: "{}", response_headers: {"ETag" => "123456"}, status: 200))
|
1024
|
+
expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/uncached", {
|
1025
|
+
api_auth: {
|
1026
|
+
api_auth_access_id: "id123",
|
1027
|
+
api_auth_options: {},
|
1028
|
+
api_auth_secret_key: "secret123"
|
1029
|
+
},
|
1030
|
+
headers: {
|
1031
|
+
"Accept"=>"application/hal+json, application/json;q=0.5",
|
1032
|
+
"Content-Type"=>"application/x-www-form-urlencoded; charset=utf-8"
|
1033
|
+
}
|
1034
|
+
}).and_return(response)
|
1035
|
+
|
1036
|
+
expect(ExampleClient).to_not receive(:write_cached_response)
|
1037
|
+
object = ExampleClient.uncached
|
1038
|
+
end
|
1039
|
+
|
940
1040
|
it "should expose all headers" do
|
941
1041
|
response = ::FaradayResponseMock.new(OpenStruct.new(body: "{}", response_headers: {"X-Test-Header" => "true"}, status: 200))
|
942
1042
|
expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/123", an_instance_of(Hash)).and_return(response)
|
@@ -1434,6 +1534,10 @@ describe Flexirest::Request do
|
|
1434
1534
|
expect(IgnoredRootExampleClient.root.title).to eq("Example Feed")
|
1435
1535
|
end
|
1436
1536
|
|
1537
|
+
it "should ignore an ignore_root parameter if the specified element is not in the response" do
|
1538
|
+
expect(IgnoredRootWithUnexpectedResponseExampleClient.root.error.message).to eq("Example Error")
|
1539
|
+
end
|
1540
|
+
|
1437
1541
|
it "should ignore a specified multi-level root element" do
|
1438
1542
|
expect(IgnoredMultiLevelRootExampleClient.multi_level_root.title).to eq("Example Multi Level Feed")
|
1439
1543
|
end
|
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.7
|
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-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -261,10 +261,10 @@ executables: []
|
|
261
261
|
extensions: []
|
262
262
|
extra_rdoc_files: []
|
263
263
|
files:
|
264
|
+
- ".github/workflows/build.yml"
|
264
265
|
- ".gitignore"
|
265
266
|
- ".rspec"
|
266
267
|
- ".simplecov"
|
267
|
-
- ".travis.yml"
|
268
268
|
- CHANGELOG.md
|
269
269
|
- Gemfile
|
270
270
|
- LICENSE.txt
|