flexirest 1.7.2 → 1.7.3

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: ddeed579fa942a385f6b7abb6c67ce95cbec9663
4
- data.tar.gz: f95768e9b39ffe1df399d531e12fd3f76a40424f
3
+ metadata.gz: 4588448f89d5370f5b208ad7185537c4c70fac4d
4
+ data.tar.gz: b496d2852fdacc8ef9656656e96a5a469419de4e
5
5
  SHA512:
6
- metadata.gz: 8f3eecbc6d5a7b3075b616c30eb2bb1f0d8ead60605b719cd2f3289e7ecc59e2c3333ec6b9171d2a15869a44521fa3060a3d2b3c12d0f109e0685d9fbc073b5f
7
- data.tar.gz: d382545e8d5e382affc6780a5d4478acb9fc17181e8637e0ce665f64ac07bdfff220e99a6e0b3a80692a5b35ff19fbf5f45f220648c2817a61a732e645e7ac0d
6
+ metadata.gz: 055f11c39ba735be43fdb5bebabb77d9c1912fded9cfe0040c06dfe4b12b33f093b8dc60295cb8abf7ccd8bac4ffd40b0729e6b47bd179b262818848e12490d6
7
+ data.tar.gz: c131e203c28350206d3f18ddaeb0c6610b099f192e8c85d7f29756343da06bdcd1875636067465ff136d750a12ed23d7690bc7bcadead01cc7380f85fe7f2a89
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.7.3
4
+
5
+ Bugfix:
6
+
7
+ - Form encoded requests should also honour `wrap_root` (thanks to noctivityinc for the issue report)
8
+
9
+ Feature:
10
+
11
+ - Returning `false` from a callback will halt the callback chain and cancel the request (thanks to noctivityinc for the feature request)
12
+
3
13
  ## 1.7.2
4
14
 
5
15
  Bugfix:
@@ -108,6 +108,8 @@ class Person < Flexirest::Base
108
108
  end
109
109
  ```
110
110
 
111
+ If you want to cancel the request from within a callback, you can simply return `false` and the mapped method result will also be `false`, however, we would normally advocate raising an exception so the reason for the callback failure is more explicit.
112
+
111
113
 
112
114
  -----
113
115
 
@@ -35,6 +35,9 @@ module Flexirest
35
35
  else
36
36
  result = callback.call(name, param)
37
37
  end
38
+ if result == false
39
+ return false
40
+ end
38
41
  if result == :retry
39
42
  return :retry
40
43
  end
@@ -192,10 +192,14 @@ module Flexirest
192
192
  return handle_response(OpenStruct.new(status:200, body:fake, response_headers:{"X-ARC-Faked-Response" => "true", "Content-Type" => content_type}))
193
193
  end
194
194
  if object_is_class?
195
- @object.send(:_callback_request, :before, @method[:name], self)
195
+ callback_result = @object.send(:_callback_request, :before, @method[:name], self)
196
196
  else
197
- @object.class.send(:_callback_request, :before, @method[:name], self)
197
+ callback_result = @object.class.send(:_callback_request, :before, @method[:name], self)
198
198
  end
199
+ if callback_result == false
200
+ return false
201
+ end
202
+
199
203
  append_get_parameters
200
204
  prepare_request_body
201
205
  self.original_url = self.url
@@ -405,7 +409,11 @@ module Flexirest
405
409
  elsif @post_params.is_a?(String)
406
410
  @post_params
407
411
  else
408
- (params || @post_params || {}).to_query
412
+ p = (params || @post_params || {})
413
+ if @method[:options][:wrap_root].present?
414
+ p = {@method[:options][:wrap_root] => p}
415
+ end
416
+ p.to_query
409
417
  end
410
418
  headers["Content-Type"] ||= "application/x-www-form-urlencoded"
411
419
  elsif request_body_type == :json
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.7.2"
2
+ VERSION = "1.7.3"
3
3
  end
@@ -15,6 +15,12 @@ describe Flexirest::Request do
15
15
  end
16
16
  end
17
17
 
18
+ before_request do |name, request|
19
+ if request.method[:name] == :cancel_callback
20
+ false
21
+ end
22
+ end
23
+
18
24
  after_request do |name, response|
19
25
  if name == :change
20
26
  response.body = "{\"test\": 1}"
@@ -27,6 +33,7 @@ describe Flexirest::Request do
27
33
  get :babies, "/babies", :has_many => {:children => ExampleOtherClient}
28
34
  get :single_association, "/single", :has_one => {:single => ExampleSingleClient}, :has_many => {:children => ExampleOtherClient}
29
35
  get :headers, "/headers"
36
+ get :cancel_callback, "/cancel-callback"
30
37
  put :headers_default, "/headers_default"
31
38
  put :headers_json, "/headers_json", request_body_type: :json
32
39
  get :find, "/:id", required: [:id]
@@ -290,6 +297,11 @@ describe Flexirest::Request do
290
297
  ExampleClient.update id:1234, debug:true
291
298
  end
292
299
 
300
+ it "should pass through url parameters and get parameters" do
301
+ expect_any_instance_of(Flexirest::Connection).to_not receive(:get)
302
+ ExampleClient.cancel_callback
303
+ end
304
+
293
305
  it "should pass through 'array type' get parameters" do
294
306
  expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/?include%5B%5D=your&include%5B%5D=friends", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", response_headers:{})))
295
307
  ExampleClient.all :include => [:your,:friends]
@@ -317,6 +329,11 @@ describe Flexirest::Request do
317
329
  ExampleClient.wrapped id:1234, debug:true, test:'foo'
318
330
  end
319
331
 
332
+ it "should wrap elements if specified, in form-encoded format" do
333
+ expect_any_instance_of(Flexirest::Connection).to receive(:put).with("/put/1234", %q(example%5Bdebug%5D=true&example%5Btest%5D=foo), an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", response_headers:{})))
334
+ ExampleClient.wrapped id:1234, debug:true, test:'foo'
335
+ end
336
+
320
337
  it "should not pass through an encoded empty body parameter" do
321
338
  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:{})))
322
339
  ExampleClient.request_body_type :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.7.2
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-28 00:00:00.000000000 Z
11
+ date: 2018-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler