Class: Puppet::Rest::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/rest/response.rb

Overview

This is a wrapper for the HTTP::Message class of the HTTPClient gem. It is designed to wrap a message sent as an HTTP response.

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Response

Returns a new instance of Response


6
7
8
# File 'lib/puppet/rest/response.rb', line 6

def initialize(message)
  @message = message
end

Instance Method Details

#bodyObject


10
11
12
# File 'lib/puppet/rest/response.rb', line 10

def body
  @message.body
end

#content_encodingObject


18
19
20
# File 'lib/puppet/rest/response.rb', line 18

def content_encoding
  @message.headers['Content-Encoding']
end

#content_typeObject


14
15
16
# File 'lib/puppet/rest/response.rb', line 14

def content_type
  @message.content_type
end

#ok?Boolean

Returns:

  • (Boolean)

26
27
28
# File 'lib/puppet/rest/response.rb', line 26

def ok?
  @message.ok?
end

#status_codeObject


22
23
24
# File 'lib/puppet/rest/response.rb', line 22

def status_code
  @message.status
end

#to_exceptionObject


30
31
32
33
# File 'lib/puppet/rest/response.rb', line 30

def to_exception
  message = _("Error %{code} on SERVER: %{returned_message}") % { code: status_code, returned_message: body }
  Puppet::Rest::ResponseError.new(message, self)
end