flexirest 1.5.4 → 1.5.5

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: 96d88b8be9d4f041d00c6da07228fb7dccc57092
4
- data.tar.gz: 9b7314b8f2685ccc77f0de3093558bd49abc0bec
3
+ metadata.gz: c539f302332de70b8e529cc91c7dabc1969d0749
4
+ data.tar.gz: 24540b75ac1730f4070324816f911b88259371eb
5
5
  SHA512:
6
- metadata.gz: 7b863f36580dddf3415740f2f2ca7cb8ded5371404e9384996d8c11a18dea26dfd76674f3972eee2d6c92aa2b1f5d159217d5d3c56c902b3dc219103b7388789
7
- data.tar.gz: 30dd6fe0eaa1e9b4c63f9f7802a6b1f1b98c060231bf246e5993710f58f19c000ee05af5b6111e4a5a32b2cca68e84ed0452596cd78af1452ae5349fd5f60b7c
6
+ metadata.gz: a810e9776a26e970f4fd2be25501e84b7fb33a1056281ffb7cbb75fa55f23285a5dcad5f4d28d948bcc55e72cacebe540eab968352704c30acddc13423edbb70
7
+ data.tar.gz: 4e971064716e6bb1d38e4c4714570395fbd98cfadb435493c27300cfa30af34308738b4b267e855c082b2e78302f4d6f5c011faecc4fd009c29e3c4fb1765cb5
@@ -259,8 +259,11 @@ module Flexirest
259
259
  elsif http_method == :delete && @method[:options][:send_delete_body]
260
260
  @post_params = default_params.merge(params || {})
261
261
  @get_params = {}
262
+ elsif params.is_a? String
263
+ @post_params = params
264
+ @get_params = {}
262
265
  else
263
- @post_params = default_params.merge(params || {})
266
+ @post_params = (default_params || {}).merge(params || {})
264
267
  @get_params = {}
265
268
  end
266
269
 
@@ -362,10 +365,22 @@ module Flexirest
362
365
  end
363
366
  @body = ""
364
367
  elsif request_body_type == :form_encoded
365
- @body ||= (params || @post_params || {}).to_query
368
+ @body ||= if params.is_a?(String)
369
+ params
370
+ elsif @post_params.is_a?(String)
371
+ @post_params
372
+ else
373
+ (params || @post_params || {}).to_query
374
+ end
366
375
  headers["Content-Type"] ||= "application/x-www-form-urlencoded"
367
376
  elsif request_body_type == :json
368
- @body ||= (params || @post_params || {}).to_json
377
+ @body ||= if params.is_a?(String)
378
+ params
379
+ elsif @post_params.is_a?(String)
380
+ @post_params
381
+ else
382
+ (params || @post_params || {}).to_json
383
+ end
369
384
  headers["Content-Type"] ||= "application/json; charset=utf-8"
370
385
  end
371
386
  end
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.5.4"
2
+ VERSION = "1.5.5"
3
3
  end
@@ -311,6 +311,18 @@ describe Flexirest::Base do
311
311
  EmptyExample._request("http://api.example.com/")
312
312
  end
313
313
 
314
+ it "allows already encoded bodies" do
315
+ Flexirest::ConnectionManager.reset!
316
+ connection = double("Connection")
317
+ allow(connection).to receive(:base_url).and_return("http://api.example.com")
318
+ expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://api.example.com/").and_return(connection)
319
+ expect(connection).
320
+ to receive(:post).
321
+ with("http://api.example.com/", "{\"test\":\"value\"}",an_instance_of(Hash)).
322
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", response_headers:{}, status:200)))
323
+ EmptyExample._request("http://api.example.com/", :post, {test: "value"}.to_json, request_body_type: :json)
324
+ end
325
+
314
326
  it "passes headers" do
315
327
  stub_request(:get, "http://api.example.com/v1").
316
328
  with(headers: {'Accept'=>'application/hal+json, application/json;q=0.5', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Connection'=>'Keep-Alive', 'Content-Type'=>'application/x-www-form-urlencoded', 'X-Something'=>'foo/bar', 'User-Agent'=>/Flexirest\//}).
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.4
4
+ version: 1.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries