flexirest 1.10.5 → 1.10.9

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: 10e663045de906cbfcd8e79800a795c440cb32b5f8e47e4b54b38aa85c450f15
4
- data.tar.gz: c6b66793a525149f3fa1eec607c8a5cb8f3fa43fd5386b4e5a845b5e0d8359e3
3
+ metadata.gz: '010099426a7d7332a404d79bb7efa98c7c236b3ccf6124c2c300e276b1d5192a'
4
+ data.tar.gz: 15c9b6e809ac7c0dc0fd3f254efb9f8f69ca4255b5e4e888907fab252efadfd4
5
5
  SHA512:
6
- metadata.gz: 16bf500083c920340ff812d84d6cd6d6a7489783b229eb51822e4b994bba812226574c5831dc34bb1bcbe3c2a98e155ceaceb13c41270309b3573268ffced862
7
- data.tar.gz: eff6f4b1699d63af2390b3c7ef970c301d2fc62cd2fda190b57f28132353c00f3a365567193cf9a2c98f5e97c5b7a1027fcf01197af34aa54f26dc57764319e6
6
+ metadata.gz: c540558e844d25850a99b56e1a85ef919832ebc3496d26689d80080a39e2e635ff2df2a53b234740cf79c7119c0fb8ff91296e0e119e1eaf06525d72d8f1fdf6
7
+ data.tar.gz: 887afa323b740f966bd4c481066d7109fab4212d3b940b5c2c4603675d7f3f6f423bd54e8401bb1ed09e21f4856a5ebab1d96c05fbe57864663da9b32051ee7a
@@ -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,37 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.10.9
4
+
5
+ Bugfix:
6
+
7
+ - Correctly handle a 204 response to not wipe an instance's attributes (thanks to @couchbelag for the issue)
8
+ - Add an option to handle a 200 response with an empty body to not wipe an instance's attributes (thanks to @couchbelag for the issue)
9
+ - Fixed a couple of typos in error messages (thanks to Sampat Badhe/@sampatbadhe for the PR)
10
+
11
+ ## 1.10.8
12
+
13
+ Bugfix:
14
+
15
+ - Flexirest didn't set DELETE params in the URL if send_request_body was false
16
+
17
+ ## 1.10.7
18
+
19
+ Bugfix:
20
+
21
+ - 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)
22
+
23
+ ## 1.10.6
24
+
25
+ Bugfix:
26
+
27
+ - Flexirest was erroring if Rails.logger was defined but was nil (thanks to Alex Oxte for the PR)
28
+
29
+ ## 1.10.5
30
+
31
+ Enhancement:
32
+
33
+ - Allow skipping of caching for single endpoints
34
+
3
35
  ## 1.10.4
4
36
 
5
37
  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 Status](https://travis-ci.org/flexirest/flexirest.svg?branch=master)](https://travis-ci.org/flexirest/flexirest)
7
+ [![Build](https://github.com/flexirest/flexirest/actions/workflows/build.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)
@@ -49,8 +49,8 @@ You can then use your new class like this:
49
49
  ```ruby
50
50
  # Create a new person
51
51
  @person = Person.create(
52
- first_name:"John"
53
- last_name:"Smith"
52
+ first_name: "John",
53
+ last_name: "Smith"
54
54
  )
55
55
 
56
56
  # Find a person (not needed after creating)
@@ -82,6 +82,7 @@ I've written a TON of documentation on how to use Flexirest and a LITTLE bit on
82
82
  - [Lazy loading](docs/lazy-loading.md)
83
83
  - [Authentication](docs/authentication.md)
84
84
  - [Body types](docs/body-types.md)
85
+ - [Empty body handling](docs/empty-body-handling.md)
85
86
  - [Parallel requests](docs/parallel-requests.md)
86
87
  - [Faking calls](docs/faking-calls.md)
87
88
  - [Per-request timeouts](docs/per-request-timeouts.md)
@@ -0,0 +1,22 @@
1
+ # *Flexirest:* Empty body handling
2
+
3
+ If you call a RESTful method that correctly returns a 204 when the request was accepted, but no body is supplied, Flexirest will return `true`. If you call this on an instance of a Flexirest subclass, it will not affect the existing attributes.
4
+
5
+ ```ruby
6
+ class Person < Flexirest::Base
7
+ put :save, "/people/:id"
8
+ end
9
+
10
+ p = Person.new(id: "1", name: "Jenny")
11
+ saved = p.save
12
+ puts saved === true # true
13
+ puts p.name # Jenny
14
+ ```
15
+
16
+ If your API returns a 200 OK status with an empty body, by default this is handled in the normal way - the attributes are set to an empty set. If you intend to handle it as above for the 204, you can set an extra option on the mapped method like this:
17
+
18
+ ```ruby
19
+ class Person < Flexirest::Base
20
+ put :save, "/people/:id", ignore_empty_response: true
21
+ end
22
+ ```
@@ -17,7 +17,7 @@ module Flexirest
17
17
  end
18
18
 
19
19
  def self.debug(message)
20
- if defined?(Rails) && Rails.respond_to?(:logger)
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.respond_to?(:logger) && Rails.logger
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.respond_to?(:logger)
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.respond_to?(:logger)
68
+ if defined?(Rails) && Rails.logger.present?
69
69
  Rails.logger.error(message)
70
70
  elsif @logfile
71
71
  if @logfile.is_a?(String)
@@ -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]
@@ -627,7 +627,7 @@ module Flexirest
627
627
  def handle_response(response, cached = nil)
628
628
  @response = response
629
629
  status = @response.status || 200
630
- if @response.body.blank?
630
+ if @response.body.blank? && !@method[:options][:ignore_empty_response]
631
631
  @response.response_headers['Content-Type'] = "application/json"
632
632
  @response.body = "{}"
633
633
  end
@@ -639,6 +639,10 @@ module Flexirest
639
639
  end
640
640
 
641
641
  if (200..399).include?(status)
642
+ if status == 204 || (@response.body.blank? && @method[:options][:ignore_empty_response])
643
+ return true
644
+ end
645
+
642
646
  if @method[:options][:plain]
643
647
  return @response = Flexirest::PlainResponse.from_response(@response)
644
648
  elsif is_json_response? || is_xml_response?
@@ -862,14 +866,14 @@ module Flexirest
862
866
 
863
867
  if ignore_root
864
868
  [ignore_root].flatten.each do |key|
865
- body = body[key.to_s]
869
+ body = body[key.to_s] if body.has_key?(key.to_s)
866
870
  end
867
871
  end
868
872
  elsif is_xml_response?
869
873
  body = @response.body.blank? ? {} : Crack::XML.parse(@response.body)
870
874
  if ignore_root
871
875
  [ignore_root].flatten.each do |key|
872
- body = body[key.to_s]
876
+ body = body[key.to_s] if body.has_key?(key.to_s)
873
877
  end
874
878
  elsif options[:ignore_xml_root]
875
879
  Flexirest::Logger.warn("Using `ignore_xml_root` is deprecated, please switch to `ignore_root`")
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.10.5"
2
+ VERSION = "1.10.9"
3
3
  end
@@ -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
@@ -48,6 +48,7 @@ describe Flexirest::Request do
48
48
  post :test_encoding, "/encoding", request_body_type: :json
49
49
  post :testing_no_content_headers, "/no-content"
50
50
  put :update, "/put/:id"
51
+ put :update_with_empty, "/put/:id", ignore_empty_response: true
51
52
  put :wrapped, "/put/:id", wrap_root: "example"
52
53
  put :conversion, "/put/:id", parse_fields: [:converted]
53
54
  put :conversion_child, "/put/:id", parse_fields: [:converted_child]
@@ -206,6 +207,16 @@ describe Flexirest::Request do
206
207
  }
207
208
  end
208
209
 
210
+ class IgnoredRootWithUnexpectedResponseExampleClient < ExampleClient
211
+ get :root, "/root", ignore_root: "feed", fake: %Q{
212
+ {
213
+ "error": {
214
+ "message": "Example Error"
215
+ }
216
+ }
217
+ }
218
+ end
219
+
209
220
  class IgnoredMultiLevelRootExampleClient < ExampleClient
210
221
  get :multi_level_root, "/multi-level-root", ignore_root: [:response, "data", "object"], fake: %Q{
211
222
  {
@@ -426,7 +437,7 @@ describe Flexirest::Request do
426
437
  end
427
438
 
428
439
  it "should get an HTTP connection when called and call delete without a body if send_delete_body is not specified" do
429
- 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:{})))
440
+ 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:{})))
430
441
  ExampleClient.remove(id:1, something: "else")
431
442
  end
432
443
 
@@ -512,6 +523,24 @@ describe Flexirest::Request do
512
523
  ExampleClient.find("1234")
513
524
  end
514
525
 
526
+ it "should handle a 204 response and not erase the instance's attributes" do
527
+ expect_any_instance_of(Flexirest::Connection).to receive(:put).and_return(::FaradayResponseMock.new(OpenStruct.new(body: "", response_headers: {}, status: 204)))
528
+ client = ExampleClient.new
529
+ client.id = "1234"
530
+ ret = client.update
531
+ expect(client.id).to eq("1234")
532
+ expect(ret).to be_truthy
533
+ end
534
+
535
+ it "should handle a 204 response and not erase the instance's attributes" do
536
+ expect_any_instance_of(Flexirest::Connection).to receive(:put).and_return(::FaradayResponseMock.new(OpenStruct.new(body: "", response_headers: {}, status: 200)))
537
+ client = ExampleClient.new
538
+ client.id = "1234"
539
+ ret = client.update_with_empty
540
+ expect(client.id).to eq("1234")
541
+ expect(ret).to be_truthy
542
+ end
543
+
515
544
  it "should pass through url parameters and get parameters" do
516
545
  expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/1234?debug=true", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", response_headers:{})))
517
546
  ExampleClient.find id:1234, debug:true
@@ -1524,6 +1553,10 @@ describe Flexirest::Request do
1524
1553
  expect(IgnoredRootExampleClient.root.title).to eq("Example Feed")
1525
1554
  end
1526
1555
 
1556
+ it "should ignore an ignore_root parameter if the specified element is not in the response" do
1557
+ expect(IgnoredRootWithUnexpectedResponseExampleClient.root.error.message).to eq("Example Error")
1558
+ end
1559
+
1527
1560
  it "should ignore a specified multi-level root element" do
1528
1561
  expect(IgnoredMultiLevelRootExampleClient.multi_level_root.title).to eq("Example Multi Level Feed")
1529
1562
  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.5
4
+ version: 1.10.9
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-04-20 00:00:00.000000000 Z
11
+ date: 2022-01-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
@@ -282,6 +282,7 @@ files:
282
282
  - docs/combined-example.md
283
283
  - docs/debugging.md
284
284
  - docs/default-parameters.md
285
+ - docs/empty-body-handling.md
285
286
  - docs/faking-calls.md
286
287
  - docs/faraday-configuration.md
287
288
  - docs/filtering-result-lists.md
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.7.0
4
- - 2.6.0
5
- - 2.5.0