flexirest 1.10.8 → 1.10.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +4 -3
- data/docs/empty-body-handling.md +22 -0
- data/lib/flexirest/request.rb +5 -1
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/request_spec.rb +19 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '010099426a7d7332a404d79bb7efa98c7c236b3ccf6124c2c300e276b1d5192a'
|
4
|
+
data.tar.gz: 15c9b6e809ac7c0dc0fd3f254efb9f8f69ca4255b5e4e888907fab252efadfd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c540558e844d25850a99b56e1a85ef919832ebc3496d26689d80080a39e2e635ff2df2a53b234740cf79c7119c0fb8ff91296e0e119e1eaf06525d72d8f1fdf6
|
7
|
+
data.tar.gz: 887afa323b740f966bd4c481066d7109fab4212d3b940b5c2c4603675d7f3f6f423bd54e8401bb1ed09e21f4856a5ebab1d96c05fbe57864663da9b32051ee7a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
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
|
+
|
3
11
|
## 1.10.8
|
4
12
|
|
5
13
|
Bugfix:
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
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](https://github.com/flexirest/flexirest/actions/workflows/
|
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
|
+
```
|
data/lib/flexirest/request.rb
CHANGED
@@ -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?
|
data/lib/flexirest/version.rb
CHANGED
data/spec/lib/request_spec.rb
CHANGED
@@ -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]
|
@@ -522,6 +523,24 @@ describe Flexirest::Request do
|
|
522
523
|
ExampleClient.find("1234")
|
523
524
|
end
|
524
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
|
+
|
525
544
|
it "should pass through url parameters and get parameters" do
|
526
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:{})))
|
527
546
|
ExampleClient.find id:1234, debug:true
|
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.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:
|
11
|
+
date: 2022-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -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
|