flexirest 1.5.9 → 1.6.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e9ebcb294d7f5316e0a89a7805ff160801d4979
4
- data.tar.gz: c72f3a2d84d9899c3f218458f6506b4ce3d5f46b
3
+ metadata.gz: 8959a6f4a0183bc9395d12c61676d30da8157f30
4
+ data.tar.gz: dedf65e6535a9da183a39a8cae90aea1c95584f6
5
5
  SHA512:
6
- metadata.gz: 3c24542bfe2f4c19b11d75a7942019ba7d3264a998d3333b5bd86031048266df58e072ec95f4578c885b6f953b09129abf773cb4cb9a9a3ab7975d3c1a75d266
7
- data.tar.gz: 06aecf662c5f925856d8f6f99b79027f073248e947ef4e53718d23fd674c4402f18b4902a4cec092b7750fbb364ad19c77d1752a88345cc5dfa42b872a0cc364
6
+ metadata.gz: 49edb2862a956a893d484d01a9baab9a53645129d29c8445cbabb59684355381b8127d3be16ec93d7b67b033984247efe9a6b74654ab579829a59ad661f9729d
7
+ data.tar.gz: 1edb7882ab1e52bfbffebf5940c53e95f878a9665aa2c07a8789a1f038b62c60b04f514d491b54c3964cef0b49753effffa97d1b0621e490633937f9f1da4c1d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.6.0
4
+
5
+ Feature:
6
+
7
+ - APIs that expect request bodies to have a wrapping element can now have this specified at mapping time.
8
+
3
9
  ## 1.5.9
4
10
 
5
11
  Bugfix:
data/README.md CHANGED
@@ -1026,16 +1026,36 @@ class Person < Flexirest::Base
1026
1026
  end
1027
1027
  ```
1028
1028
 
1029
- ### Root element removal
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
- get :list, "/feed", ignore_root: "feed"
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:
@@ -402,7 +402,11 @@ module Flexirest
402
402
  elsif @post_params.is_a?(String)
403
403
  @post_params
404
404
  else
405
- (params || @post_params || {}).to_json
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
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.5.9"
2
+ VERSION = "1.6.0"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexirest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.9
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries