flexirest 1.3.13 → 1.3.14

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: bc2dd846c4d1cab6b3bc1fc2a1d162bfbb5419e9
4
- data.tar.gz: fb4672356cf5e7fec571ebe73ff381d89a47f1ce
3
+ metadata.gz: fb527b4e0686f41868c0c0074ca60f38c890367b
4
+ data.tar.gz: d61137bb423545b4f30a915beff69184988eb8f1
5
5
  SHA512:
6
- metadata.gz: 293a96596ed43f163a15614597913ddcf6682432176fd6d8fa32a31ca5db1adad77543e3384ab0f231ca97da7b62b5d392a03bca7b0d9f6073bc5863fc064919
7
- data.tar.gz: a851723f3928d483b287b63744146aa28865a5148cbc74e0ad889d3bf4d1dec31f2bbe941b87bcc603c3dcdf7bdbfe5391e5aa4cf98bac16a2f1cd91b3f27197
6
+ metadata.gz: 344f2accd4f6446496d370879be78d0e2412dd77ee2cec427846503031a626afc1d0f73961ce2a26dca452a15a50c5cc3ec9d5620addda6936b90eced45b8049
7
+ data.tar.gz: 9cf9485402e1bbcab606f3cbe59be7c1dc07987935f14706e7385aa26e3f46155926599dbcc3109ee2e91c61efe2757c763413780fa5cb7e1b372b2152a9ef8c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.3.14
4
+
5
+ Feature:
6
+
7
+ - Plain Requests (both using the `plain: true` option to mapped methods and using `_plain_request`) return a `Flexirest::PlainResponse` which is string-like for all intents and purposes (it's comparable with strings using the body of the response) and also has `_status` and `_headers` methods (thanks to Rui Ribeiro for the request/inspiration).
8
+
3
9
  ## 1.3.13
4
10
 
5
11
  Feature:
data/README.md CHANGED
@@ -696,6 +696,8 @@ class Person < Flexirest::Base
696
696
  end
697
697
  ```
698
698
 
699
+ The response of a plain request (from either source) is a `Flexirest::PlainResponse` which acts like a string containing the response's body, but it also has a `_headers` method that returns the HTTP response headers and a `_status` method containing the response's HTTP method.
700
+
699
701
  ### Proxying APIs
700
702
 
701
703
  Sometimes you may be working with an old API that returns JSON in a less than ideal format or the URL or parameters required have changed. In this case you can define a descendent of `Flexirest::ProxyBase`, pass it to your model as the proxy and have it rework URLs/parameters on the way out and the response on the way back in (already converted to a Ruby hash/array). By default any non-proxied URLs are just passed through to the underlying connection layer. For example:
@@ -0,0 +1,13 @@
1
+ module Flexirest
2
+ class PlainResponse < ::String
3
+ attr_accessor :_status
4
+ attr_accessor :_headers
5
+
6
+ def self.from_response(response)
7
+ plain = self.new(response.body)
8
+ plain._status = response.status
9
+ plain._headers = response.response_headers
10
+ plain
11
+ end
12
+ end
13
+ end
@@ -388,7 +388,7 @@ module Flexirest
388
388
 
389
389
  if (200..399).include?(status)
390
390
  if @method[:options][:plain]
391
- return @response = response.body
391
+ return @response = Flexirest::PlainResponse.from_response(response)
392
392
  elsif is_json_response? || is_xml_response?
393
393
  if @response.respond_to?(:proxied) && @response.proxied
394
394
  Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Response was proxied, unable to determine size"
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.3.13"
2
+ VERSION = "1.3.14"
3
3
  end
data/lib/flexirest.rb CHANGED
@@ -21,6 +21,7 @@ require "flexirest/proxy_base"
21
21
  require "flexirest/recording"
22
22
  require "flexirest/base"
23
23
  require "flexirest/monkey_patching"
24
+ require "flexirest/plain_response"
24
25
 
25
26
  module Flexirest
26
27
  @@name = "Flexirest"
@@ -300,6 +300,12 @@ describe Flexirest::Base do
300
300
  expect(EmptyExample._plain_request("http://api.example.com/", :post, {id:1234})).to eq(response_body)
301
301
  end
302
302
 
303
+ it "should return a PlainResponse from the directly called URL bypassing JSON loading" do
304
+ response_body = "This is another non-JSON string"
305
+ expect_any_instance_of(Flexirest::Connection).to receive(:post).with(any_args).and_return(::FaradayResponseMock.new(OpenStruct.new(status:200, response_headers:{}, body:response_body)))
306
+ expect(EmptyExample._plain_request("http://api.example.com/", :post, {id:1234})).to be_a(Flexirest::PlainResponse)
307
+ end
308
+
303
309
  context "Simulating Faraday connection in_parallel" do
304
310
  it "should be able to pass the plain response from the directly called URL bypassing JSON loading" do
305
311
  response_body = "This is another non-JSON string"
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Flexirest::PlainResponse do
4
+ let(:response) { OpenStruct.new(status:200, body:"fake response", response_headers:{"X-ARC-Faked-Response" => "true", "Content-Type" => "application/json"}) }
5
+
6
+ it "is comparable to a string" do
7
+ expect(Flexirest::PlainResponse.new("test")).to eq "test"
8
+ end
9
+
10
+ it "can be instantiated from a response" do
11
+ expect(Flexirest::PlainResponse.from_response(response)).to eq "fake response"
12
+ end
13
+
14
+ it "returns the response's status" do
15
+ expect(Flexirest::PlainResponse.from_response(response)._status).to eq 200
16
+ end
17
+
18
+ it "returns the response's headers" do
19
+ expect(Flexirest::PlainResponse.from_response(response)._headers["Content-Type"]).to eq "application/json"
20
+ end
21
+ end
@@ -267,6 +267,12 @@ describe Flexirest::Request do
267
267
  expect(ExampleClient.plain(id:1234)).to eq(response_body)
268
268
  end
269
269
 
270
+ it "should return a PlainResponse from a plain request" do
271
+ response_body = "This is another non-JSON string"
272
+ expect_any_instance_of(Flexirest::Connection).to receive(:get).with(any_args).and_return(::FaradayResponseMock.new(OpenStruct.new(status:200, response_headers:{}, body:response_body)))
273
+ expect(ExampleClient.plain(id:1234)).to be_a(Flexirest::PlainResponse)
274
+ end
275
+
270
276
  it "should return a lazy loader object if lazy loading is enabled" do
271
277
  object = LazyLoadedExampleClient.fake id:1234, debug:true
272
278
  expect(object).to be_an_instance_of(Flexirest::LazyLoader)
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.3.13
4
+ version: 1.3.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-03 00:00:00.000000000 Z
11
+ date: 2016-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -243,6 +243,7 @@ files:
243
243
  - lib/flexirest/logger.rb
244
244
  - lib/flexirest/mapping.rb
245
245
  - lib/flexirest/monkey_patching.rb
246
+ - lib/flexirest/plain_response.rb
246
247
  - lib/flexirest/proxy_base.rb
247
248
  - lib/flexirest/recording.rb
248
249
  - lib/flexirest/request.rb
@@ -265,6 +266,7 @@ files:
265
266
  - spec/lib/lazy_loader_spec.rb
266
267
  - spec/lib/logger_spec.rb
267
268
  - spec/lib/mapping_spec.rb
269
+ - spec/lib/plain_response_spec.rb
268
270
  - spec/lib/proxy_spec.rb
269
271
  - spec/lib/recording_spec.rb
270
272
  - spec/lib/request_filtering_spec.rb
@@ -315,6 +317,7 @@ test_files:
315
317
  - spec/lib/lazy_loader_spec.rb
316
318
  - spec/lib/logger_spec.rb
317
319
  - spec/lib/mapping_spec.rb
320
+ - spec/lib/plain_response_spec.rb
318
321
  - spec/lib/proxy_spec.rb
319
322
  - spec/lib/recording_spec.rb
320
323
  - spec/lib/request_filtering_spec.rb