Class: Faraday::Response

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

Direct Known Subclasses

YajlResponse

Defined Under Namespace

Classes: YajlResponse

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AutoloadHelper

autoload_all, load

Constructor Details

#initialize(headers = nil, body = nil) ⇒ Response


14
15
16
17
18
19
20
# File 'lib/faraday/response.rb', line 14

def initialize(headers = nil, body = nil)
  super(headers || {}, body)
  if block_given?
    yield self
    processed!
  end
end

Class Attribute Details

.load_errorObject

Returns the value of attribute load_error


4
5
6
# File 'lib/faraday/response.rb', line 4

def load_error
  @load_error
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body


2
3
4
# File 'lib/faraday/response.rb', line 2

def body
  @body
end

#headersObject

Returns the value of attribute headers


2
3
4
# File 'lib/faraday/response.rb', line 2

def headers
  @headers
end

Class Method Details

.loaded?Boolean


5
6
7
# File 'lib/faraday/response.rb', line 5

def loaded?
  !load_error
end

Instance Method Details

#process(chunk) ⇒ Object

TODO: process is a funky name. change it processes a chunk of the streamed body.


24
25
26
27
28
29
# File 'lib/faraday/response.rb', line 24

def process(chunk)
  if !body
    self.body = []
  end
  body << chunk
end

#process!(full_body) ⇒ Object

Assume the given content is the full body, and not streamed.


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

def process!(full_body)
  process(full_body)
  processed!
end

#processed!Object

Signals the end of streamed content. Do whatever you need to clean up the streamed body.


39
40
41
# File 'lib/faraday/response.rb', line 39

def processed!
  self.body = body.join if body.respond_to?(:join)
end