flexirest 1.5.9 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +22 -2
- data/lib/flexirest/request.rb +5 -1
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/request_spec.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8959a6f4a0183bc9395d12c61676d30da8157f30
|
4
|
+
data.tar.gz: dedf65e6535a9da183a39a8cae90aea1c95584f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49edb2862a956a893d484d01a9baab9a53645129d29c8445cbabb59684355381b8127d3be16ec93d7b67b033984247efe9a6b74654ab579829a59ad661f9729d
|
7
|
+
data.tar.gz: 1edb7882ab1e52bfbffebf5940c53e95f878a9665aa2c07a8789a1f038b62c60b04f514d491b54c3964cef0b49753effffa97d1b0621e490633937f9f1da4c1d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1026,16 +1026,36 @@ class Person < Flexirest::Base
|
|
1026
1026
|
end
|
1027
1027
|
```
|
1028
1028
|
|
1029
|
-
### Root
|
1029
|
+
### Root elements
|
1030
1030
|
|
1031
1031
|
If your JSON or XML object comes back with a root node and you'd like to ignore it, you can define the mapping as:
|
1032
1032
|
|
1033
1033
|
```ruby
|
1034
1034
|
class Feed < Flexirest::Base
|
1035
|
-
|
1035
|
+
post :list, "/feed", ignore_root: "feed"
|
1036
1036
|
end
|
1037
1037
|
```
|
1038
1038
|
|
1039
|
+
Alternatively if you want to wrap your JSON request body in a root element, e.g.:
|
1040
|
+
|
1041
|
+
```json
|
1042
|
+
{
|
1043
|
+
"feed": {
|
1044
|
+
"id": 1
|
1045
|
+
}
|
1046
|
+
}
|
1047
|
+
```
|
1048
|
+
|
1049
|
+
You can do it like this:
|
1050
|
+
|
1051
|
+
```ruby
|
1052
|
+
class Feed < Flexirest::Base
|
1053
|
+
post :list, "/feed", wrap_root: "feed"
|
1054
|
+
end
|
1055
|
+
|
1056
|
+
Feed.list(id: 1)
|
1057
|
+
```
|
1058
|
+
|
1039
1059
|
### Required Parameters
|
1040
1060
|
|
1041
1061
|
If you want to specify that certain parameters are required for a specific call, you can specify them like:
|
data/lib/flexirest/request.rb
CHANGED
@@ -402,7 +402,11 @@ module Flexirest
|
|
402
402
|
elsif @post_params.is_a?(String)
|
403
403
|
@post_params
|
404
404
|
else
|
405
|
-
|
405
|
+
if @method[:options][:wrap_root].present?
|
406
|
+
{@method[:options][:wrap_root] => (params || @post_params || {})}.to_json
|
407
|
+
else
|
408
|
+
(params || @post_params || {}).to_json
|
409
|
+
end
|
406
410
|
end
|
407
411
|
headers["Content-Type"] ||= "application/json; charset=utf-8"
|
408
412
|
end
|
data/lib/flexirest/version.rb
CHANGED
data/spec/lib/request_spec.rb
CHANGED
@@ -36,6 +36,7 @@ describe Flexirest::Request do
|
|
36
36
|
post :test_encoding, "/encoding", request_body_type: :json
|
37
37
|
post :testing_no_content_headers, "/no-content"
|
38
38
|
put :update, "/put/:id"
|
39
|
+
put :wrapped, "/put/:id", wrap_root: "example"
|
39
40
|
put :conversion, "/put/:id", parse_fields: [:converted]
|
40
41
|
delete :remove, "/remove/:id"
|
41
42
|
delete :remove_body, "/remove/:id", send_delete_body: true
|
@@ -282,6 +283,12 @@ describe Flexirest::Request do
|
|
282
283
|
ExampleClient.update id:1234, debug:true, test:'foo'
|
283
284
|
end
|
284
285
|
|
286
|
+
it "should encode the body in a JSON format if specified" do
|
287
|
+
expect_any_instance_of(Flexirest::Connection).to receive(:put).with("/put/1234", %q({"example":{"debug":true,"test":"foo"}}), an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", response_headers:{})))
|
288
|
+
ExampleClient.request_body_type :json
|
289
|
+
ExampleClient.wrapped id:1234, debug:true, test:'foo'
|
290
|
+
end
|
291
|
+
|
285
292
|
it "should not pass through an encoded empty body parameter" do
|
286
293
|
expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/1234", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", response_headers:{})))
|
287
294
|
ExampleClient.request_body_type :json
|