Class: HTTPAdapter::RackResponseAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/httpadapter/adapters/rack.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ RackResponseAdapter

Returns a new instance of RackResponseAdapter.



98
99
100
101
102
103
# File 'lib/httpadapter/adapters/rack.rb', line 98

def initialize(response)
  unless response.kind_of?(Rack::Response)
    raise TypeError, "Expected Rack::Response, got #{response.class}."
  end
  @response = response
end

Class Method Details

.from_ary(array) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/httpadapter/adapters/rack.rb', line 109

def self.from_ary(array)
  status, headers, body = array
  status = status.to_i
  body.each do |chunk|
    # Purely for strict type-checking
    unless chunk.kind_of?(String)
      raise TypeError, "Expected String, got #{chunk.class}."
    end
  end
  response = Rack::Response.new(body, status, Hash[headers])
  return response
end

Instance Method Details

#to_aryObject



105
106
107
# File 'lib/httpadapter/adapters/rack.rb', line 105

def to_ary
  return @response.finish
end