Class: Faraday::Response

Inherits:
Object show all
Extended by:
AutoloadHelper
Defined in:
lib/faraday/response.rb

Defined Under Namespace

Classes: ActiveSupportJson, Middleware, Nokogiri, Yajl

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AutoloadHelper

all_loaded_constants, autoload_all, load_autoloaded_constants, lookup_module, register_lookup_modules

Constructor Details

#initializeResponse

Returns a new instance of Response.



36
37
38
39
# File 'lib/faraday/response.rb', line 36

def initialize
  @status, @headers, @body = nil, nil, nil
  @on_complete_callbacks = []
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



34
35
36
# File 'lib/faraday/response.rb', line 34

def body
  @body
end

#headersObject

Returns the value of attribute headers.



34
35
36
# File 'lib/faraday/response.rb', line 34

def headers
  @headers
end

#statusObject

Returns the value of attribute status.



34
35
36
# File 'lib/faraday/response.rb', line 34

def status
  @status
end

Instance Method Details

#finish(env) ⇒ Object



45
46
47
48
49
50
# File 'lib/faraday/response.rb', line 45

def finish(env)
  env[:body] ||= ''
  @on_complete_callbacks.each { |c| c.call(env) }
  @status, @headers, @body = env[:status], env[:response_headers], env[:body]
  self
end

#on_complete(&block) ⇒ Object



41
42
43
# File 'lib/faraday/response.rb', line 41

def on_complete(&block)
  @on_complete_callbacks << block
end

#success?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/faraday/response.rb', line 52

def success?
  status == 200
end