Method: Puppet::Indirector::REST#deserialize

Defined in:
lib/vendor/puppet/indirector/rest.rb

#deserialize(response, multiple = false) ⇒ Object

Figure out the content type, turn that into a format, and use the format to extract the body of the response.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vendor/puppet/indirector/rest.rb', line 37

def deserialize(response, multiple = false)
  case response.code
  when "404"
    return nil
  when /^2/
    raise "No content type in http response; cannot parse" unless response['content-type']

    content_type = response['content-type'].gsub(/\s*;.*$/,'') # strip any appended charset

    body = uncompress_body(response)

    # Convert the response to a deserialized object.
    if multiple
      model.convert_from_multiple(content_type, body)
    else
      model.convert_from(content_type, body)
    end
  else
    # Raise the http error if we didn't get a 'success' of some kind.
    raise convert_to_http_error(response)
  end
end