hakanensari/vacuum

Works with Rails 5? Getting Excon::Error::BadRequest

toadkicker opened this issue · 1 comments

Hello,

I am trying to integrate this gem into a Rails 5.1 application to pull product images. Running the code from the rails console works fine, but calling from a controller returns Excon::Error::BadRequest (Expected([200, 403]) <=> Actual(400 Bad Request).

Gemfile:

gem 'vacuum', github: 'hakanensari/vacuum', tag: 'v2.0.2', require: 'vacuum'

Controller:

def show
    req = Vacuum.new
    req.configure(aws_access_key_id: ENV['AWS_PROD_IMG_ACCESS_KEY'],
                  aws_secret_access_key: ENV['AWS_PROD_IMG_SECRET_KEY'])
    req.associate_tag = 'foo'
    query = {
      ResponseGroup: 'Images',
      ItemId: '1338099132'
    }
    res = req.item_lookup(query: query)
    @images = res.to_h
  end

  private

  def product_image_params
    params.permit(:asin)
  end

Of course i want to replace ItemId with params[:asin] when this works in the controller.

I'm stumped because I don't know why copying the guts of show into rails console produces results, but calling it over its HTTP enpoint would throw a bad request from Vacuum.

And of course as soon as I post this I figured out that my env var wasn't set properly in my IDE.

But what I did find useful while stepping through Excon is turning on debugging via env vars. This would be useful to know in the README as well:

EXCON_DEBUG=true