Module: HttpTest::HttpMethods::Response

Defined in:
lib/http-test/http_methods.rb

Defined Under Namespace

Modules: FaradayHelper Classes: BlankResponse

Class Method Summary collapse

Class Method Details

.create(faraday_response) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/http-test/http_methods.rb', line 30

def self.create(faraday_response)
  body, headers = faraday_response.body, faraday_response.headers
  return BlankResponse.new(faraday_response) unless body && body.length > 0

  response = case content_type = headers["content-type"]
  when /\Aapplication\/json/ then JSON.parse faraday_response.body
  when /\Atext\//            then faraday_response.body
  else                            raise "unsupported content_type: #{content_type.inspect}"
  end

  response.extend FaradayHelper
  response.faraday_response = faraday_response
  response
end