Class: Aviator::Response

Inherits:
Object show all
Extended by:
Forwardable
Defined in:
lib/puppet/feature/aviator/core/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, request) ⇒ Response

Returns a new instance of Response.



10
11
12
13
# File 'lib/puppet/feature/aviator/core/response.rb', line 10

def initialize(response, request)
  @response = response
  @request  = request
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



8
9
10
# File 'lib/puppet/feature/aviator/core/response.rb', line 8

def request
  @request
end

Instance Method Details

#bodyObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/puppet/feature/aviator/core/response.rb', line 16

def body
  @body ||= if raw_body.length > 0
    if Aviator::Compatibility::RUBY_1_8_MODE
      clean_body = raw_body.gsub(/\\ /, ' ')
    else
      clean_body = raw_body
    end

    Hashish.new(JSON.parse(clean_body))
  else
    Hashish.new({})
  end
end

#headersObject



31
32
33
# File 'lib/puppet/feature/aviator/core/response.rb', line 31

def headers
  @headers ||= Hashish.new(@response.headers)
end

#to_hashObject



36
37
38
39
40
41
42
# File 'lib/puppet/feature/aviator/core/response.rb', line 36

def to_hash
  Hashish.new({
    :status  => status,
    :headers => headers,
    :body    => body
  })
end