Sha256: ff100f469b1c57f9915e8ea865fbf2d9d850a55aa8c7c753991f76e256c8d049

Contents?: true

Size: 578 Bytes

Versions: 2

Compression:

Stored size: 578 Bytes

Contents

require 'delegate'
require 'dig_rb'
require 'forwardable'
require 'multi_xml'

module Vacuum
  # A wrapper around the Amazon Product Advertising API response.
  class Response < SimpleDelegator
    extend Forwardable

    class << self
      attr_accessor :parser
    end

    def_delegator :to_h, :dig

    attr_writer :parser

    def parser
      @parser || self.class.parser
    end

    def parse
      parser ? parser.parse(body) : to_h
    end

    def to_h
      MultiXml.parse(body)
    end

    def body
      __getobj__.body.force_encoding('UTF-8')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vacuum-2.0.2 lib/vacuum/response.rb
vacuum-2.0.1 lib/vacuum/response.rb