# File lib/rhc/rest/client.rb, line 438
        def parse_response(response)
          result = RHC::Json.decode(response)
          type = result['type']
          data = result['data']

          # Copy messages to each object
          messages = Array(result['messages']).map do |m|
            m['text'] if m['field'].nil? or m['field'] == 'result'
          end.compact
          data.each{ |d| d['messages'] = messages } if data.is_a?(Array)
          data['messages'] = messages if data.is_a?(Hash)

          case type
          when 'domains'
            data.map{ |json| Domain.new(json, self) }
          when 'domain'
            Domain.new(data, self)
          when 'authorization'
            Authorization.new(data, self)
          when 'authorizations'
            data.map{ |json| Authorization.new(json, self) }
          when 'applications'
            data.map{ |json| Application.new(json, self) }
          when 'application'
            Application.new(data, self)
          when 'cartridges'
            data.map{ |json| Cartridge.new(json, self) }
          when 'cartridge'
            Cartridge.new(data, self)
          when 'user'
            User.new(data, self)
          when 'keys'
            data.map{ |json| Key.new(json, self) }
          when 'key'
            Key.new(data, self)
          when 'gear_groups'
            data.map{ |json| GearGroup.new(json, self) }
          when 'aliases'
            data.map{ |json| Alias.new(json, self) }
          else
            data
          end
        end