flexirest 1.5.4 → 1.5.5
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 +4 -4
- data/lib/flexirest/request.rb +18 -3
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/base_spec.rb +12 -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: c539f302332de70b8e529cc91c7dabc1969d0749
|
4
|
+
data.tar.gz: 24540b75ac1730f4070324816f911b88259371eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a810e9776a26e970f4fd2be25501e84b7fb33a1056281ffb7cbb75fa55f23285a5dcad5f4d28d948bcc55e72cacebe540eab968352704c30acddc13423edbb70
|
7
|
+
data.tar.gz: 4e971064716e6bb1d38e4c4714570395fbd98cfadb435493c27300cfa30af34308738b4b267e855c082b2e78302f4d6f5c011faecc4fd009c29e3c4fb1765cb5
|
data/lib/flexirest/request.rb
CHANGED
@@ -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 ||= (
|
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 ||= (
|
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
|
data/lib/flexirest/version.rb
CHANGED
data/spec/lib/base_spec.rb
CHANGED
@@ -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\//}).
|