Class: Pigeon::Http::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/pigeon/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, uri) ⇒ Response

Returns a new instance of Response.



160
161
162
163
# File 'lib/pigeon/http.rb', line 160

def initialize response, uri
  @response = response
  @uri      = uri
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



158
159
160
# File 'lib/pigeon/http.rb', line 158

def response
  @response
end

#uriObject (readonly)

Returns the value of attribute uri.



158
159
160
# File 'lib/pigeon/http.rb', line 158

def uri
  @uri
end

Instance Method Details

#bodyObject



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/pigeon/http.rb', line 173

def body
  case headers['content-encoding'].to_s.downcase
    when 'gzip'
      gz = Zlib::GzipReader.new(StringIO.new(response.body))
      begin
        gz.read
      ensure
        gz.close
      end
    when 'deflate'
      Zlib.inflate(response.body)
    else
      response.body
  end
end

#codeObject



165
166
167
# File 'lib/pigeon/http.rb', line 165

def code
  response.code.to_i
end

#headersObject



169
170
171
# File 'lib/pigeon/http.rb', line 169

def headers
  @headers ||= Hash[response.each_header.entries]
end

#inspectObject



189
190
191
# File 'lib/pigeon/http.rb', line 189

def inspect
  "#<#{self.class} @code=#{code} @uri=#{uri}>"
end