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) ⇒ 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.

We’re massaging data produced by a motley army of developers. It’s messy.



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

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

  if xml?(res)
    XMLResponseParser.new(res)
  else
    # Amazon returns a variety of content types for flat files. I simply
    # assume anything not XML is a flat file.
    FlatFileParser.new(res, encoding)
  end
end

.xml?(res) ⇒ Boolean

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.

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'lib/peddler/parser.rb', line 25

def xml?(res)
  return true if res.headers['Content-Type'].start_with?('text/xml')
  return true if res.body.start_with?('<?xml')

  false
end