Class: Weary::Response

Inherits:
Object
  • Object
show all
Includes:
Rack::Response::Helpers
Defined in:
lib/weary/response.rb

Instance Method Summary (collapse)

Constructor Details

- (Response) initialize(body, status, headers)

Returns a new instance of Response



9
10
11
12
# File 'lib/weary/response.rb', line 9

def initialize(body, status, headers)
  @response = Rack::Response.new body, status, headers
  @status = self.status
end

Instance Method Details

- (Object) body



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

def body
  buffer = ""
  @response.body.each {|chunk| buffer << chunk }
  buffer
end

- (Object) call(env)



49
50
51
# File 'lib/weary/response.rb', line 49

def call(env)
  self.finish
end

- (Object) each(&iterator)



29
30
31
# File 'lib/weary/response.rb', line 29

def each(&iterator)
  @response.body.each(&iterator)
end

- (Object) finish



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

def finish
  [status, header, self]
end

- (Object) header Also known as: headers



18
19
20
# File 'lib/weary/response.rb', line 18

def header
  @response.header
end

- (Object) length



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

def length
  @response.length
end

- (Object) parse



53
54
55
56
57
58
59
60
61
# File 'lib/weary/response.rb', line 53

def parse
  raise "The response does not contain a body" if body.nil? || body.empty?
  if block_given?
    yield body, content_type
  else
    raise "Unable to parse Content-Type: #{content_type}" unless content_type =~ /json($|;.*)/
    MultiJson.decode body
  end
end

- (Boolean) redirected?

Returns:

  • (Boolean)


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

def redirected?
  @response.redirection?
end

- (Object) status



14
15
16
# File 'lib/weary/response.rb', line 14

def status
  @response.status.to_i
end

- (Boolean) success?

Returns:

  • (Boolean)


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

def success?
  @response.successful?
end