Sha256: bc7dded0249ea6e1b01b5ed39599cd4b8852c0f8af48d9684575aeb0c1cc848b

Contents?: true

Size: 531 Bytes

Versions: 16

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, _| k.include?('Result') }
      results ? results.last : nil
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
peddler-0.16.0 lib/peddler/xml_parser.rb
peddler-0.15.0 lib/peddler/xml_parser.rb
peddler-0.14.0 lib/peddler/xml_parser.rb
peddler-0.13.0 lib/peddler/xml_parser.rb
peddler-0.12.7 lib/peddler/xml_parser.rb
peddler-0.12.5 lib/peddler/xml_parser.rb
peddler-0.12.4 lib/peddler/xml_parser.rb
peddler-0.12.2 lib/peddler/xml_parser.rb
peddler-0.12.1 lib/peddler/xml_parser.rb
peddler-0.12.0 lib/peddler/xml_parser.rb
peddler-0.11.1 lib/peddler/xml_parser.rb
peddler-0.11.0 lib/peddler/xml_parser.rb
peddler-0.10.0 lib/peddler/xml_parser.rb
peddler-0.9.2 lib/peddler/xml_parser.rb
peddler-0.9.1 lib/peddler/xml_parser.rb
peddler-0.9.0 lib/peddler/xml_parser.rb