Sha256: e006ee7ac1e05bb8ac44bb7475cc64f0f062f8276ca1523b6ea9be4caa588700

Contents?: true

Size: 835 Bytes

Versions: 6

Compression:

Stored size: 835 Bytes

Contents

# frozen_string_literal: true

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

module Peddler
  # @!visibility private
  module Parser
    class << self
      # We're massaging data produced by a motley army of developers. It's
      # messy.
      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

      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

6 entries across 6 versions & 1 rubygems

Version Path
peddler-2.4.5 lib/peddler/parser.rb
peddler-2.4.4 lib/peddler/parser.rb
peddler-2.4.3 lib/peddler/parser.rb
peddler-2.4.1 lib/peddler/parser.rb
peddler-2.4.0 lib/peddler/parser.rb
peddler-2.3.0 lib/peddler/parser.rb