Sha256: 15557793f0ba2c190f039123f91c32cb8668f881d8a336de041382cb1bc98f06

Contents?: true

Size: 899 Bytes

Versions: 7

Compression:

Stored size: 899 Bytes

Contents

require 'peddler/flat_file_parser'
require 'peddler/xml_response_parser'

module Peddler
  # @api private
  module Parser
    class << self
      # The inevitable-seeming messiness of massaging data produced by a motley
      # army of Amazon developers
      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, 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

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

        false
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
peddler-1.6.3 lib/peddler/parser.rb
peddler-1.6.2 lib/peddler/parser.rb
peddler-1.6.1 lib/peddler/parser.rb
peddler-1.6.0 lib/peddler/parser.rb
peddler-1.5.0 lib/peddler/parser.rb
peddler-1.4.1 lib/peddler/parser.rb
peddler-1.4.0 lib/peddler/parser.rb