Class: Faraday::Response

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

Defined Under Namespace

Classes: Logger, Middleware, RaiseError

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

- (Response) initialize(env = nil)



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

def initialize(env = nil)
  @env = env
  @on_complete_callbacks = []
end

Instance Attribute Details

- (Object) env (readonly) 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

- (Object) apply_request(request_env)

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

- (Object) body



50
51
52
# File 'lib/faraday/response.rb', line 50

def body
  finished? ? env[:body] : nil
end

- (Object) finish(env)



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

- (Boolean) finished?



54
55
56
# File 'lib/faraday/response.rb', line 54

def finished?
  !!env
end

- (Object) headers



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

def headers
  finished? ? env[:response_headers] : {}
end

- (Object) marshal_dump

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

- (Object) marshal_load(env)



86
87
88
# File 'lib/faraday/response.rb', line 86

def marshal_load(env)
  @env = env
end

- (Object) on_complete



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

- (Object) status



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

def status
  finished? ? env[:status] : nil
end

- (Boolean) success?



74
75
76
# File 'lib/faraday/response.rb', line 74

def success?
  status == 200
end