]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/aviator/lib/puppet/feature/aviator/core/response.rb
add aimonb/aviator to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / aviator / lib / puppet / feature / aviator / core / response.rb
1 module Aviator
2
3   class Response
4     extend Forwardable
5
6     def_delegators :@response, :status
7
8     attr_reader :request
9
10     def initialize(response, request)
11       @response = response
12       @request  = request
13     end
14
15
16     def body
17       @body ||= if raw_body.length > 0
18         if Aviator::Compatibility::RUBY_1_8_MODE
19           clean_body = raw_body.gsub(/\\ /, ' ')
20         else
21           clean_body = raw_body
22         end
23
24         Hashish.new(JSON.parse(clean_body))
25       else
26         Hashish.new({})
27       end
28     end
29
30
31     def headers
32       @headers ||= Hashish.new(@response.headers)
33     end
34
35
36     def to_hash
37       Hashish.new({
38         :status  => status,
39         :headers => headers,
40         :body    => body
41       })
42     end
43
44     private
45
46     def raw_body
47       @raw_body ||= @response.body
48     end
49
50   end
51
52 end