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
env[R]
Public Class Methods
new(env = nil)
click to toggle source
# File lib/faraday/response.rb, line 27 def initialize(env = nil) @env = Env.from(env) if env @on_complete_callbacks = [] end
Public Instance Methods
apply_request(request_env)
click to toggle source
Expand the env with more properties, without overriding existing ones. Useful for applying request params after restoring a marshalled Response
.
# File lib/faraday/response.rb, line 94 def apply_request(request_env) raise "response didn't finish yet" unless finished? @env = Env.from(request_env).update(@env) self end
body()
click to toggle source
# File lib/faraday/response.rb, line 47 def body finished? ? env.body : nil end
finish(env)
click to toggle source
# File lib/faraday/response.rb, line 64 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
finished?()
click to toggle source
# File lib/faraday/response.rb, line 51 def finished? !!env end
headers()
click to toggle source
# File lib/faraday/response.rb, line 42 def headers finished? ? env.response_headers : {} end
marshal_dump()
click to toggle source
because @on_complete_callbacks cannot be marshalled
# File lib/faraday/response.rb, line 84 def marshal_dump finished? ? to_hash : nil end
marshal_load(env)
click to toggle source
# File lib/faraday/response.rb, line 88 def marshal_load(env) @env = Env.from(env) end
on_complete() { |env| ... }
click to toggle source
# File lib/faraday/response.rb, line 55 def on_complete(&block) if !finished? @on_complete_callbacks << block else yield(env) end self end
reason_phrase()
click to toggle source
# File lib/faraday/response.rb, line 38 def reason_phrase finished? ? env.reason_phrase : nil end
status()
click to toggle source
# File lib/faraday/response.rb, line 34 def status finished? ? env.status : nil end
success?()
click to toggle source
# File lib/faraday/response.rb, line 72 def success? finished? && env.success? end
to_hash()
click to toggle source
# File lib/faraday/response.rb, line 76 def to_hash { status: env.status, body: env.body, response_headers: env.response_headers } end