3

I'm new to rails, and looking to set up a site that uses Amazon's product API. I'm used to using the API in PHP but keen to move to Ruby if at all possible.

I've been trying the various Amazon product API gems, Ruby/AWS, Amazon-ECS, and now Vacuum. However a problem I am sticking at is how to actually use the code they suggest in their readme files.

For example, Vacuum:

https://github.com/hakanensari/vacuum/

It mentions the following code:

req = Vacuum.new :product_advertising

req.configure do |config|
  config.key    'key'
  config.secret 'secret'
  config.tag    'tag'
end

req.build operation:    'ItemSearch',
      search_index: 'Books',
      keywords:     'Deleuze'
res = req.get

res.valid? or raise res.code

p res.body

Unsure where to put this code, I set up a controller for the test app and put it there. However it fails on the first line, saying that Vacuum is not defined (it's installed as a gem within the gemfile, and I've run bundle install).

I'm probably doing something stupid yet simple to fix, and would really appreciate any suggestions.

D

Edit:

Thanks to x1a4, the following code should be replace the configure block above:

req.configure do |config|
  config.key =    'key'
  config.secret = 'secret'
  config.tag =    'tag'
end
Don H
  • 891
  • 2
  • 15
  • 24
  • 1
    Did you restart your server after running `bundle install`? New gems are not dynamically loaded into a running app. – x1a4 Apr 28 '12 at 22:11
  • Thanks, that certainly helped as it changed the error message :) I'm now getting "wrong number of arguments (1 for 0)", with the trace pointing to the "req.configure do |config|" line. Does that look alright to you? – Don H Apr 28 '12 at 22:28
  • 1
    Nothing looks wrong from here. Could you post the entire trace somewhere, e.g. http://gist.github.com ? – x1a4 Apr 28 '12 at 22:31
  • Thanks for your help with this. A full trace is here: https://gist.github.com/2522499 – Don H Apr 28 '12 at 22:49
  • 1
    It *looks* like the example code is wrong, and you need to use a setter with `=`. In the block being passed to `configure`, try `config.key = 'key'`, `config.secret = 'secret'`, and `config.tag = 'tag'`. I admittedly don't have vacuum experience, but from the trace, it looks like this is the issue. – x1a4 Apr 28 '12 at 23:15
  • That was the problem. I'm now getting back a result. Thanks. – Don H Apr 28 '12 at 23:26
  • @DonH could you release your sample app on GitHub? – Mark Boulder Apr 18 '14 at 16:57
  • Hi @MarkBoulder, I'm not sure the code's in a state to be released, having long since moved on from the work. The solution in this case was to use "=" to set the config variables. I'd missed these in the original code. – Don H Apr 22 '14 at 20:05

1 Answers1

0

Thanks to x1a4, the following code should be replace the configure block above:

req.configure do |config|
  config.key =    'key'
  config.secret = 'secret'
  config.tag =    'tag'
end
Don H
  • 891
  • 2
  • 15
  • 24