Class: Faraday::Response

Inherits:
Struct
  • Object
show all
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

Constructor Details

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

Returns a new instance of Response



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

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

Returns:

  • (Object)

    the current value of body



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

def body
  @body
end

#headersObject

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



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

def headers
  @headers
end

Class Method Details

.loaded?Boolean

Returns:

  • (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.



22
23
24
25
26
27
# File 'lib/faraday/response.rb', line 22

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.



30
31
32
33
# File 'lib/faraday/response.rb', line 30

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.



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

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