lib/sawyer/response.rb in sawyer-0.0.9 vs lib/sawyer/response.rb in sawyer-0.1.0
- old
+ new
@@ -8,17 +8,19 @@
# Builds a Response after a completed request.
#
# agent - The Sawyer::Agent that is managing the API connection.
# res - A Faraday::Response.
- def initialize(agent, res)
+ def initialize(agent, res, options = {})
@agent = agent
@status = res.status
@headers = res.headers
@env = res.env
@data = @headers[:content_type] =~ /json|msgpack/ ? process_data(@agent.decode_body(res.body)) : res.body
@rels = process_rels
+ @started = options[:sawyer_started]
+ @ended = options[:sawyer_ended]
end
# Turns parsed contents from an API response into a Resource or
# collection of Resources.
#
@@ -46,14 +48,14 @@
Hash[*links.flatten]
end
def timing
- @timing ||= @env[:sawyer_ended] - @env[:sawyer_started]
+ @timing ||= @ended - @started
end
def time
- @env[:sawyer_ended]
+ @ended
end
def inspect
%(#<#{self.class}: #{@status} @rels=#{@rels.inspect} @data=#{@data.inspect}>)
end