Class: Aitch::Response::Body

Inherits:
Object
  • Object
show all
Defined in:
lib/aitch/response/body.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Body

Returns a new instance of Body.



6
7
8
9
10
# File 'lib/aitch/response/body.rb', line 6

def initialize(response)
  @response = response
  @body = response.body
  @encoding = @response["content-encoding"]
end

Instance Method Details

#deflate?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/aitch/response/body.rb', line 16

def deflate?
  @encoding == "deflate"
end

#gzip?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/aitch/response/body.rb', line 12

def gzip?
  @encoding == "gzip"
end

#to_sObject



20
21
22
23
24
25
26
27
28
# File 'lib/aitch/response/body.rb', line 20

def to_s
  if gzip?
    Zlib::GzipReader.new(StringIO.new(@body)).read
  elsif deflate?
    Zlib::Inflate.inflate(@body)
  else
    @body
  end
end