Class: Lumberg::FormatWhm

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/lumberg/format_whm.rb

Instance Method Summary collapse

Constructor Details

#initialize(env, *args, &block) ⇒ FormatWhm

Returns a new instance of FormatWhm.



6
7
8
9
10
11
# File 'lib/lumberg/format_whm.rb', line 6

def initialize(env, *args, &block)
  @type = args[0]
  @key = args[1]
  @boolean_params = args[2]
  super(env)
end

Instance Method Details

#on_complete(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/lumberg/format_whm.rb', line 13

def on_complete(env)
  encoding = env[:response_headers]['content-encoding']

  encoding = encoding.to_s.downcase if encoding

  body = case encoding
         when 'gzip'
           env[:response_headers].delete('content-encoding')
           Zlib::GzipReader.new(StringIO.new(env[:body])).read
         when 'deflate'
           env[:response_headers].delete('content-encoding')
           Zlib::Inflate.inflate(env[:body])
         else
           env[:body]
         end

  env[:body] = format_response body
end

#response_values(env) ⇒ Object



32
33
34
# File 'lib/lumberg/format_whm.rb', line 32

def response_values(env)
  {status: env[:status], headers: env[:response_headers], body: env[:body]}
end