Class: Faraday::Response
Defined Under Namespace
Classes: Logger, Middleware, RaiseError
Instance Attribute Summary collapse
-
#env ⇒ Object
(also: #to_hash)
readonly
Returns the value of attribute env.
Instance Method Summary
collapse
all_loaded_constants, autoload_all, load_autoloaded_constants, lookup_module, register_lookup_modules
Constructor Details
#initialize(env = nil) ⇒ Response
Returns a new instance of Response.
33
34
35
36
|
# File 'lib/faraday/response.rb', line 33
def initialize(env = nil)
@env = env
@on_complete_callbacks = []
end
|
Instance Attribute Details
#env ⇒ Object
Also known as:
to_hash
Returns the value of attribute env.
38
39
40
|
# File 'lib/faraday/response.rb', line 38
def env
@env
end
|
Instance Method Details
#apply_request(request_env) ⇒ Object
Expand the env with more properties, without overriding existing ones. Useful for applying request params after restoring a marshalled Response.
92
93
94
95
96
|
# File 'lib/faraday/response.rb', line 92
def apply_request(request_env)
raise "response didn't finish yet" unless finished?
@env = request_env.merge @env
return self
end
|
50
51
52
|
# File 'lib/faraday/response.rb', line 50
def body
finished? ? env[:body] : nil
end
|
#finish(env) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/faraday/response.rb', line 67
def finish(env)
raise "response already finished" if finished?
@env = env
@on_complete_callbacks.each { |callback| callback.call(env) }
return self
end
|
#finished? ⇒ Boolean
54
55
56
|
# File 'lib/faraday/response.rb', line 54
def finished?
!!env
end
|
45
46
47
|
# File 'lib/faraday/response.rb', line 45
def
finished? ? env[:response_headers] : {}
end
|
#marshal_dump ⇒ Object
because @on_complete_callbacks cannot be marshalled
79
80
81
82
83
84
|
# File 'lib/faraday/response.rb', line 79
def marshal_dump
!finished? ? nil : {
:status => @env[:status], :body => @env[:body],
:response_headers => @env[:response_headers]
}
end
|
#marshal_load(env) ⇒ Object
86
87
88
|
# File 'lib/faraday/response.rb', line 86
def marshal_load(env)
@env = env
end
|
#on_complete ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/faraday/response.rb', line 58
def on_complete
if not finished?
@on_complete_callbacks << Proc.new
else
yield env
end
return self
end
|
41
42
43
|
# File 'lib/faraday/response.rb', line 41
def status
finished? ? env[:status] : nil
end
|
#success? ⇒ Boolean
74
75
76
|
# File 'lib/faraday/response.rb', line 74
def success?
(200..299).include?(status)
end
|