Module: Peddler::Parser Private

Defined in:
lib/peddler/parser.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Class Method Details

.new(res, encoding = 'ISO-8859-1') ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The inevitable-seeming messiness of massaging data produced by a motley army of Amazon developers



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/peddler/parser.rb', line 11

def new(res, encoding = 'ISO-8859-1')
  # Don't parse if there's no body
  return res unless res.body

  content_type = res.headers['Content-Type']
  if content_type.start_with?('text/xml')
    XMLResponseParser.new(res)
  else
    # Amazon returns a variety of content types for flat files, so we
    # simply assume that anything not XML is a flat file rather than code
    # defensively and check content type again.
    FlatFileParser.new(res, encoding)
  end
end