flexirest 1.10.4 → 1.10.8
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/caching.md +8 -0
- data/lib/flexirest/logger.rb +4 -4
- data/lib/flexirest/request.rb +6 -6
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/base_without_validation_spec.rb +2 -0
- data/spec/lib/request_spec.rb +45 -1
- 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: 1b83cde99ff35cebe79fea42a56376731df479a41668d080adc68ff5be4a24dc
|
4
|
+
data.tar.gz: 9170fdcf1afaa4d94d55d13b67c406ef470d3793ea9c7738416cd55b4fdc8107
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70e59dcfcfc93ce1af97961756bc92c6f53f3d438afea748c918cad5b00583afda7678de691a8ce0bf7f2e45619d73adba2b3c5be4a80c29fd80550fccb9e62b
|
7
|
+
data.tar.gz: 953064ac2ad371bc5d793291ceef862092983a34489b6e5780b7f4d84a4d568e4520b50df41ebd8f9663412a80feeeac1562767ff879eedae235576284fc3771
|
@@ -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.8
|
4
|
+
|
5
|
+
Bugfix:
|
6
|
+
|
7
|
+
- Flexirest didn't set DELETE params in the URL if send_request_body was false
|
8
|
+
|
9
|
+
## 1.10.7
|
10
|
+
|
11
|
+
Bugfix:
|
12
|
+
|
13
|
+
- 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)
|
14
|
+
|
15
|
+
## 1.10.6
|
16
|
+
|
17
|
+
Bugfix:
|
18
|
+
|
19
|
+
- Flexirest was erroring if Rails.logger was defined but was nil (thanks to Alex Oxte for the PR)
|
20
|
+
|
21
|
+
## 1.10.5
|
22
|
+
|
23
|
+
Enhancement:
|
24
|
+
|
25
|
+
- Allow skipping of caching for single endpoints
|
26
|
+
|
3
27
|
## 1.10.4
|
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/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/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
@@ -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
|
@@ -347,7 +347,7 @@ module Flexirest
|
|
347
347
|
if @explicit_parameters
|
348
348
|
params = @explicit_parameters
|
349
349
|
end
|
350
|
-
if http_method == :get
|
350
|
+
if http_method == :get || (http_method == :delete && !@method[:options][:send_delete_body] && proxy != :json_api)
|
351
351
|
@get_params = default_params.merge(params || {})
|
352
352
|
@post_params = nil
|
353
353
|
elsif http_method == :delete && @method[:options][:send_delete_body]
|
@@ -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)
|
@@ -862,14 +862,14 @@ module Flexirest
|
|
862
862
|
|
863
863
|
if ignore_root
|
864
864
|
[ignore_root].flatten.each do |key|
|
865
|
-
body = body[key.to_s]
|
865
|
+
body = body[key.to_s] if body.has_key?(key.to_s)
|
866
866
|
end
|
867
867
|
end
|
868
868
|
elsif is_xml_response?
|
869
869
|
body = @response.body.blank? ? {} : Crack::XML.parse(@response.body)
|
870
870
|
if ignore_root
|
871
871
|
[ignore_root].flatten.each do |key|
|
872
|
-
body = body[key.to_s]
|
872
|
+
body = body[key.to_s] if body.has_key?(key.to_s)
|
873
873
|
end
|
874
874
|
elsif options[:ignore_xml_root]
|
875
875
|
Flexirest::Logger.warn("Using `ignore_xml_root` is deprecated, please switch to `ignore_root`")
|
@@ -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
@@ -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
|
@@ -205,6 +206,16 @@ describe Flexirest::Request do
|
|
205
206
|
}
|
206
207
|
end
|
207
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
|
+
|
208
219
|
class IgnoredMultiLevelRootExampleClient < ExampleClient
|
209
220
|
get :multi_level_root, "/multi-level-root", ignore_root: [:response, "data", "object"], fake: %Q{
|
210
221
|
{
|
@@ -425,7 +436,7 @@ describe Flexirest::Request do
|
|
425
436
|
end
|
426
437
|
|
427
438
|
it "should get an HTTP connection when called and call delete without a body if send_delete_body is not specified" do
|
428
|
-
expect_any_instance_of(Flexirest::Connection).to receive(:delete).with("/remove/1", "", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
|
439
|
+
expect_any_instance_of(Flexirest::Connection).to receive(:delete).with("/remove/1?something=else", "", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
|
429
440
|
ExampleClient.remove(id:1, something: "else")
|
430
441
|
end
|
431
442
|
|
@@ -997,6 +1008,35 @@ describe Flexirest::Request do
|
|
997
1008
|
expect(object._etag).to eq("123456")
|
998
1009
|
end
|
999
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
|
+
|
1000
1040
|
it "should expose all headers" do
|
1001
1041
|
response = ::FaradayResponseMock.new(OpenStruct.new(body: "{}", response_headers: {"X-Test-Header" => "true"}, status: 200))
|
1002
1042
|
expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/123", an_instance_of(Hash)).and_return(response)
|
@@ -1494,6 +1534,10 @@ describe Flexirest::Request do
|
|
1494
1534
|
expect(IgnoredRootExampleClient.root.title).to eq("Example Feed")
|
1495
1535
|
end
|
1496
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
|
+
|
1497
1541
|
it "should ignore a specified multi-level root element" do
|
1498
1542
|
expect(IgnoredMultiLevelRootExampleClient.multi_level_root.title).to eq("Example Multi Level Feed")
|
1499
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.8
|
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-10-01 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
|