class Faraday::Response
Response
represents the returned value of a sent Faraday
request. @see lib/faraday/response.rb Original class location
Response
represents an HTTP response from making an HTTP request.
Attributes
Public Class Methods
Source
# File lib/faraday/response.rb, line 33 def initialize(env = nil) @env = Env.from(env) if env @on_complete_callbacks = [] end
Public Instance Methods
Source
# File lib/faraday/response.rb, line 100 def apply_request(request_env) raise "response didn't finish yet" unless finished? @env = Env.from(request_env).update(@env) self end
Expand the env with more properties, without overriding existing ones. Useful for applying request params after restoring a marshalled Response
.
Source
# File lib/faraday/response.rb, line 70 def finish(env) raise 'response already finished' if finished? @env = env.is_a?(Env) ? env : Env.from(env) @on_complete_callbacks.each { |callback| callback.call(@env) } self end
Source
# File lib/faraday/response.rb, line 48 def headers finished? ? env.response_headers : {} end
Source
# File lib/faraday/response.rb, line 90 def marshal_dump finished? ? to_hash : nil end
because @on_complete_callbacks cannot be marshalled
Source
# File lib/faraday/response.rb, line 94 def marshal_load(env) @env = Env.from(env) end
Source
# File lib/faraday/response.rb, line 61 def on_complete(&block) if !finished? @on_complete_callbacks << block else yield(env) end self end
Source
# File lib/faraday/response.rb, line 44 def reason_phrase finished? ? env.reason_phrase : nil end
Source
# File lib/faraday/response.rb, line 40 def status finished? ? env.status : nil end
Source
# File lib/faraday/response.rb, line 78 def success? finished? && env.success? end
Source
# File lib/faraday/response.rb, line 82 def to_hash { status: env.status, body: env.body, response_headers: env.response_headers } end