Class: HTTPAdapter::TyphoeusResponseAdapter
- Inherits:
-
Object
- Object
- HTTPAdapter::TyphoeusResponseAdapter
- Defined in:
- lib/httpadapter/adapters/typhoeus.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(response) ⇒ TyphoeusResponseAdapter
constructor
A new instance of TyphoeusResponseAdapter.
- #to_ary ⇒ Object
Constructor Details
#initialize(response) ⇒ TyphoeusResponseAdapter
Returns a new instance of TyphoeusResponseAdapter.
86 87 88 89 90 91 |
# File 'lib/httpadapter/adapters/typhoeus.rb', line 86 def initialize(response) unless response.kind_of?(Typhoeus::Response) raise TypeError, "Expected Typhoeus::Response, got #{response.class}." end @response = response end |
Class Method Details
.from_ary(array) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/httpadapter/adapters/typhoeus.rb', line 112 def self.from_ary(array) status, headers, body = array status = status.to_i merged_body = "" body.each do |chunk| merged_body += chunk end response = Typhoeus::Response.new( :code => status, :headers => headers.inject('') { |a,(h,v)| a << "#{h}: #{v}\r\n"; a }, :body => merged_body ) return response end |
Instance Method Details
#to_ary ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/httpadapter/adapters/typhoeus.rb', line 93 def to_ary status = @response.code.to_i headers = [] @response.headers_hash.each do |header, value| # Eh? Seriously? This is NOT a header! next if header =~ /^HTTP\/\d\.\d \d{3} .+$/ if value.kind_of?(Array) for repeated_header_value in value # Header appears multiple times; common for Set-Cookie headers << [header, repeated_header_value] end else headers << [header, value] end end body = @response.body || "" return [status, headers, [body]] end |