flexirest 1.4.5 → 1.4.6

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
  SHA1:
3
- metadata.gz: b57d06388df46647b1e69e7f1673ae5a6dd36a5f
4
- data.tar.gz: 669373fad9d9592266b3e362e0c565a46245c942
3
+ metadata.gz: f0179b1032c7c9c28be5895b6dc2f6268924469b
4
+ data.tar.gz: b2096625168b34e7dbe4509363546426cafd1899
5
5
  SHA512:
6
- metadata.gz: '05659745e284dd34aaeed585cb19648e503df0851f6d680b687d9dc32322307b1ce560e07782cc15f532f2d7eaa9b265eed27d59a21b814a9ee90ec79ba0699f'
7
- data.tar.gz: 7f55f9a8db580d9371b59e27b77fd8835228cbefd29e1384faf077a56bbe7f83026b52ef90c75de4df25b6eb13988616bdd1eee64ccbf913c0d0aabfa934d65b
6
+ metadata.gz: 6dd4e5f49b2ee856235101eb2a4039fb3200cbdcde7e5880346724a541c72452f3174a071684291decc91c16fa2c541b1086af984735ae634ff981849c4384a4
7
+ data.tar.gz: aa4c442cb8646e480249122168c50a8bf81748e4273d225526d08b8e39bf883d29a8a674e27b7e65f7f85183c4caa5fce605ffe2cf8ba861f150bae746c44a22
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.4.6
4
+
5
+ Feature:
6
+
7
+ - You can define how to handle the body of `delete` requests now with the mapping option `send_delete_body`.
8
+
3
9
  ## 1.4.5
4
10
 
5
11
  Bugfix:
data/README.md CHANGED
@@ -94,6 +94,7 @@ class Person < Flexirest::Base
94
94
  get :find, "/people/:id"
95
95
  put :save, "/people/:id"
96
96
  post :create, "/people"
97
+ delete :remove, "/people/:id"
97
98
  end
98
99
  ```
99
100
 
@@ -129,6 +130,12 @@ id = @person.id
129
130
  end
130
131
  ```
131
132
 
133
+ For `delete` requests whether an API can handle a body or not is undefined. The default is to ignore any parameters not sent in the URL named parameters, but you can optionally specify `send_delete_body` and it will encode them in your chosen way into the body.
134
+
135
+ ```
136
+ delete :remove, "/people/:id", send_delete_body: true
137
+ ```
138
+
132
139
  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).
133
140
 
134
141
  ```ruby
@@ -249,6 +249,9 @@ module Flexirest
249
249
  if http_method == :get
250
250
  @get_params = default_params.merge(params || {})
251
251
  @post_params = nil
252
+ elsif http_method == :delete && @method[:options][:send_delete_body]
253
+ @post_params = default_params.merge(params || {})
254
+ @get_params = {}
252
255
  else
253
256
  @post_params = default_params.merge(params || {})
254
257
  @get_params = {}
@@ -335,7 +338,7 @@ module Flexirest
335
338
 
336
339
  def prepare_request_body(params = nil)
337
340
  if proxy == :json_api
338
- if http_method == :get || http_method == :delete
341
+ if http_method == :get || (http_method == :delete && !@method[:options][:send_delete_body])
339
342
  @body = ""
340
343
  else
341
344
  headers["Content-Type"] ||= "application/vnd.api+json"
@@ -344,7 +347,7 @@ module Flexirest
344
347
 
345
348
  headers["Accept"] ||= "application/vnd.api+json"
346
349
  JsonAPIProxy::Headers.save(headers)
347
- elsif http_method == :get || http_method == :delete
350
+ elsif http_method == :get || (http_method == :delete && !@method[:options][:send_delete_body])
348
351
  @body = ""
349
352
  elsif request_body_type == :form_encoded
350
353
  @body ||= (params || @post_params || {}).to_query
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.4.5"
2
+ VERSION = "1.4.6"
3
3
  end
@@ -37,6 +37,7 @@ describe Flexirest::Request do
37
37
  put :update, "/put/:id"
38
38
  put :conversion, "/put/:id", parse_fields: [:converted]
39
39
  delete :remove, "/remove/:id"
40
+ delete :remove_body, "/remove/:id", send_delete_body: true
40
41
  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}
41
42
  get :fake, "/fake", fake:"{\"result\":true, \"list\":[1,2,3,{\"test\":true}], \"child\":{\"grandchild\":{\"test\":true}}}"
42
43
  get :fake_proc, "/fake", fake:->(request) { "{\"result\":#{request.get_params[:id]}}" }
@@ -150,6 +151,16 @@ describe Flexirest::Request do
150
151
  ExampleClient.remove(id:1)
151
152
  end
152
153
 
154
+ it "should get an HTTP connection when called and call delete with a body if send_delete_body is specified" do
155
+ 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:{})))
156
+ ExampleClient.remove_body(id:1, something: "else")
157
+ end
158
+
159
+ it "should get an HTTP connection when called and call delete without a body if send_delete_body is not specified" do
160
+ 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:{})))
161
+ ExampleClient.remove(id:1, something: "else")
162
+ end
163
+
153
164
  it "should work with faraday response objects" do
154
165
  response = Faraday::Response.new
155
166
  allow(response).to receive(:body).and_return({}.to_json)
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.4.5
4
+ version: 1.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-31 00:00:00.000000000 Z
11
+ date: 2017-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler