Vacuum is a Ruby wrapper to the Amazon Product Advertising API.
Set up a request:
req = Vacuum.new
.configure(
aws_access_key_id: 'foo',
aws_secret_access_key: 'secret',
associate_tag: 'biz-val'
)
The locale defaults to the US. If you wish to use another locale, specify its ISO-3166 two-letter code when instantiating the request:
Vacuum.new('GB')
Make a request:
params = { 'Operation' => 'ItemSearch',
'SearchIndex' => 'Books',
'Keywords' => 'Architecture' }
res = req.get(query: params)
Once you have a response, parse it with your favourite XML parser and parsing method.
If you don't mind the performance hit, here is a simplistic solution based on
MultiXml
:
require 'forwardable'
require 'multi_xml'
class Response
extend Forwardable
def_delegators :@response, :code, :body
def initialize(response)
@response = response
end
def to_h
MultiXml.parse(body)
end
end
Response.new(res).to_h