flexirest 1.12.4 → 1.12.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/docs/basic-usage.md +6 -0
- data/lib/flexirest/request.rb +10 -9
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/request_spec.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44aa9166918c27766f3d696c23cc78b08e1f956edb6ae8a7413c9e88f01c48e7
|
4
|
+
data.tar.gz: 1068bcb89fb8da7af5505177f989997794615703df092d8d27fa55479987565c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cddabff55c7531fdb3856c863fc9888fa3731c82135f9a02c4e3d5026514c479815ecaa499fc38b6f50c6579bff7703bcbaef688d76ea067a43f7a26dc8efc5
|
7
|
+
data.tar.gz: 204f29f4a0baa07661ea497d88799f137ed55114fdea808f5a1ea905a21f9ff51f2d0ce1c9a82d985c140c6e6f4fc29ae26e394a34a63cc51b87907dbef81139
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.12.5
|
4
|
+
|
5
|
+
Feature:
|
6
|
+
|
7
|
+
- Some broken APIs require a GET body, even though this is against HTTP spec. Added a `send_get_body` parameter like we already have for DELETE requests (thanks to Jan Schroeder for the request)
|
8
|
+
|
3
9
|
## 1.12.4
|
4
10
|
|
5
11
|
Bugfix:
|
data/docs/basic-usage.md
CHANGED
@@ -52,6 +52,12 @@ For `delete` requests whether an API can handle a body or not is undefined. The
|
|
52
52
|
delete :remove, "/people/:id", send_delete_body: true
|
53
53
|
```
|
54
54
|
|
55
|
+
In a similar way, although it's against the HTTP specification, you can force a GET request to send a request body if your API requires that:
|
56
|
+
|
57
|
+
```
|
58
|
+
get :people_search, "/people/search", send_get_body: true
|
59
|
+
```
|
60
|
+
|
55
61
|
If an API returns an array of results and you have [will_paginate](https://rubygems.org/gems/will_paginate) installed then you can call the paginate method to return a particular page of the results (note: this doesn't reduce the load on the server, but it can help with pagination if you have a cached response).
|
56
62
|
|
57
63
|
```ruby
|
data/lib/flexirest/request.rb
CHANGED
@@ -361,10 +361,10 @@ module Flexirest
|
|
361
361
|
if @explicit_parameters
|
362
362
|
params = @explicit_parameters
|
363
363
|
end
|
364
|
-
if http_method == :get || (http_method == :delete && !@method[:options][:send_delete_body] && proxy != :json_api)
|
364
|
+
if (http_method == :get && !@method[:options][:send_get_body]) || (http_method == :delete && !@method[:options][:send_delete_body] && proxy != :json_api)
|
365
365
|
@get_params = default_params.merge(params || {})
|
366
366
|
@post_params = nil
|
367
|
-
elsif http_method == :delete && @method[:options][:send_delete_body]
|
367
|
+
elsif (http_method == :get && @method[:options][:send_get_body]) || (http_method == :delete && @method[:options][:send_delete_body])
|
368
368
|
@post_params = default_params.merge(params || {})
|
369
369
|
@get_params = {}
|
370
370
|
elsif params.is_a? String
|
@@ -476,7 +476,7 @@ module Flexirest
|
|
476
476
|
|
477
477
|
headers["Accept"] ||= "application/vnd.api+json"
|
478
478
|
JsonAPIProxy::Headers.save(headers)
|
479
|
-
elsif http_method == :get || (http_method == :delete && !@method[:options][:send_delete_body])
|
479
|
+
elsif (http_method == :get && !@method[:options][:send_get_body]) || (http_method == :delete && !@method[:options][:send_delete_body])
|
480
480
|
if request_body_type == :form_encoded
|
481
481
|
headers["Content-Type"] ||= "application/x-www-form-urlencoded; charset=utf-8"
|
482
482
|
elsif request_body_type == :form_multipart
|
@@ -607,16 +607,17 @@ module Flexirest
|
|
607
607
|
request_options[:timeout] = @method[:options][:timeout]
|
608
608
|
end
|
609
609
|
|
610
|
-
|
611
|
-
when :get
|
610
|
+
if http_method == :get && !@method[:options][:send_get_body]
|
612
611
|
response = connection.get(@url, request_options)
|
613
|
-
|
612
|
+
elsif http_method == :get
|
613
|
+
response = connection.get(@url, @body, request_options)
|
614
|
+
elsif http_method == :put
|
614
615
|
response = connection.put(@url, @body, request_options)
|
615
|
-
|
616
|
+
elsif http_method == :post
|
616
617
|
response = connection.post(@url, @body, request_options)
|
617
|
-
|
618
|
+
elsif http_method == :patch
|
618
619
|
response = connection.patch(@url, @body, request_options)
|
619
|
-
|
620
|
+
elsif http_method == :delete
|
620
621
|
response = connection.delete(@url, @body, request_options)
|
621
622
|
else
|
622
623
|
raise InvalidRequestException.new("Invalid method #{http_method}")
|
data/lib/flexirest/version.rb
CHANGED
data/spec/lib/request_spec.rb
CHANGED
@@ -54,6 +54,7 @@ describe Flexirest::Request do
|
|
54
54
|
put :conversion_child, "/put/:id", parse_fields: [:converted_child]
|
55
55
|
delete :remove, "/remove/:id"
|
56
56
|
delete :remove_body, "/remove/:id", send_delete_body: true
|
57
|
+
get :get_body, "/get-body", send_get_body: true
|
57
58
|
get :hal, "/hal", fake:"{\"_links\":{\"child\": {\"href\": \"/child/1\"}, \"other\": {\"href\": \"/other/1\"}, \"cars\":[{\"href\": \"/car/1\", \"name\":\"car1\"}, {\"href\": \"/car/2\", \"name\":\"car2\"}, {\"href\": \"/car/not-embed\", \"name\":\"car_not_embed\"} ], \"lazy\": {\"href\": \"/lazy/load\"}, \"invalid\": [{\"href\": \"/invalid/1\"}]}, \"_embedded\":{\"other\":{\"name\":\"Jane\"},\"child\":{\"name\":\"Billy\"}, \"cars\":[{\"_links\": {\"self\": {\"href\": \"/car/1\"} }, \"make\": \"Bugatti\", \"model\": \"Veyron\"}, {\"_links\": {\"self\": {\"href\": \"/car/2\"} }, \"make\": \"Ferrari\", \"model\": \"F458 Italia\"} ], \"invalid\": [{\"present\":true, \"_links\": {} } ] } }", has_many:{other:ExampleOtherClient}
|
58
59
|
get :fake_object, "/fake", fake:"{\"result\":true, \"list\":[1,2,3,{\"test\":true}], \"child\":{\"grandchild\":{\"test\":true}}}"
|
59
60
|
get :fake_proc_object, "/fake", fake:->(request) { "{\"result\":#{request.get_params[:id]}}" }
|
@@ -451,6 +452,11 @@ describe Flexirest::Request do
|
|
451
452
|
ExampleClient.all
|
452
453
|
end
|
453
454
|
|
455
|
+
it "should get an HTTP connection when called and call get with a body if send_get_body is specified" do
|
456
|
+
expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/get-body", "something=else", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
|
457
|
+
ExampleClient.get_body(something: "else")
|
458
|
+
end
|
459
|
+
|
454
460
|
it "should get an HTTP connection when called and call delete on it" do
|
455
461
|
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:{})))
|
456
462
|
ExampleClient.remove(id:1)
|
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.12.
|
4
|
+
version: 1.12.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:
|
11
|
+
date: 2025-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -407,7 +407,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
407
407
|
- !ruby/object:Gem::Version
|
408
408
|
version: '0'
|
409
409
|
requirements: []
|
410
|
-
rubygems_version: 3.5.
|
410
|
+
rubygems_version: 3.5.21
|
411
411
|
signing_key:
|
412
412
|
specification_version: 4
|
413
413
|
summary: This gem is for accessing REST services in a flexible way. ActiveResource
|