Dustbag is a set of response parsers for Vacumm (a Ruby wrapper of the Amazon Product Advertising API
Vacuum is an excellent client for the Amazon Product Advertising API, it handles all the possible interactons with the API, but unfortunately you're required to implement your own response parse mechanisms. So Vacuum just give us a ton of dust (in form of xml), which is not bad, because that's not its job, dustbag's job is to handle all that dust and give it a meaningful use.
Add this line to your application’s Gemfile:
gem 'dustbag'
You'll need credentials to access to the Amazon Product Advertising API, also an affiliate tag, you can get them following this instructions
Once you get your credentials, you'll need to configure Vacuum to use your credentials, you have two options, you can set the following env vars:
export AWS_ACCESS_KEY_ID=key
export AWS_SECRET_ACCESS_KEY=secret
Or, you can explicitly say to vacuum to use your credentials:
request.configure(
aws_access_key_id: 'key',
aws_secret_access_key: 'secret',
associate_tag: 'tag'
)
One more thing, this gem makes use of the Money gem, money makes use of i18n to format money strings, by default this behaviour is disabled, if you want to enable i18n with money, you can enable it by setting the next env var:
export USE_I18N_FOR_MONEY=true
require 'vacuum'
require 'dustbag'
request = Vacuum.new
request.associate_tag = 'tag'
response = request.item_search(
query: {
'Keywords' => 'Architecture',
'SearchIndex' => 'Books'
}
)
response.parser = Dustbag::Parser
response.parse
You'll get an ItemSearchReponse
object, this object has an 'items' method which is a collection of the Items matchig your search, if you want to see what can you do with these itmes, look at the source code of the Item
class
Right now, there is only one response parser implemented (ItemSearchResponse), the remaining work is to implement the following responses:
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request