Sha256: 9d30c0a443f5afb41f670064b966d8a09b857058ce885ad4018d3469b15478c9

Contents?: true

Size: 531 Bytes

Versions: 5

Compression:

Stored size: 531 Bytes

Contents

require 'delegate'
require 'multi_xml'

module Peddler
  # @api private
  class XMLParser < SimpleDelegator
    def next_token
      parse.fetch('NextToken', false)
    end

    def parse
      @result ||= find_result
    end

    def xml
      MultiXml.parse(body)
    end

    def valid?
      headers['Content-Length'].to_i == body.size if headers['Content-Length']
    end

    private

    def find_result
      results = xml.values[0].find { |k, v| k.include?('Result') }
      results ? results.last : nil
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
peddler-0.8.0 lib/peddler/xml_parser.rb
peddler-0.7.11 lib/peddler/xml_parser.rb
peddler-0.7.10 lib/peddler/xml_parser.rb
peddler-0.7.9 lib/peddler/xml_parser.rb
peddler-0.7.8 lib/peddler/xml_parser.rb