Merge pull request #66 from relaxdiego/fix/63

This commit is contained in:
Mark Maglana
2013-09-25 11:23:42 -07:00

View File

@@ -1,39 +1,31 @@
module Aviator module Aviator
class Response class Response
extend Forwardable
def_delegators :@response, :headers, :status
attr_reader :request
def initialize(response, request)
@response = response
@request = request
end
def body def body
@body ||= if response.body.length > 0 if raw_body.length > 0
JSON.parse(response.body).with_indifferent_access JSON.parse(raw_body).with_indifferent_access
else
{}
end
@body.dup
end
def method_missing(name, *args)
case name
when :headers, :status
response.send(name)
when :request
request
else else
super(name, *args) {}
end end
end end
private private
attr_reader :response, def raw_body
:request @response.body
def initialize(response, request)
@response = response
@request = request
end end
end end