mhuggins / a2z

Simple Ruby DSL for searching & retrieving items from the Amazon Product Advertising API
MIT License
41 stars 9 forks source link

Exception received while fetching item from amazon #7

Closed jchauhan closed 11 years ago

jchauhan commented 11 years ago

Exception details are below:

NoMethodError: undefined method []' for nil:NilClass from ~/.rvm/gems/ruby-1.9.3-p286/gems/a2z-0.1.1/lib/a2z/responses/offer_summary.rb:51:inblock in from_response'

      if data['LowestNewPrice']
        offer_summary.lowest_new_price = Money.new(data['LowestNewPrice']['Amount'].to_i, data['LowestNewPrice']['CurrencyCode'])
      end

      if data['LowestUsedPrice']
        offer_summary.lowest_used_price = Money.new(data['LowestNewPrice']['Amount'].to_i, data['LowestNewPrice']['CurrencyCode'])
      end
mhuggins commented 11 years ago

Can you paste the code you used to make the call?

jchauhan commented 11 years ago

The code to send a request to amazon is following:

def self.send_search_req(q, cat, page = 1, per_page = 10, options = {}) client = A2z::Client.new(@@config) response = client.item_search do category cat item_page page keywords q response_group 'Medium' end response end

After going through the a2z library it looks like it is typo bug. In the following lines of code (lib/a2z/responses/offer_summary.rb, line number 51), if you notice, data['LowestUsedPrice'] is checked for not being nil, however data['LowestNewPrice'] is used to to set value of offer_summary.lowest_used_price.

lib/a2z/responses/offer_summary.rb:51:inblock in from_response' if data['LowestNewPrice'] offer_summary.lowest_new_price = Money.new(data['LowestNewPrice']['Amount'].to_i, data['LowestNewPrice']['CurrencyCode']) end

  if data['LowestUsedPrice']
    offer_summary.lowest_used_price = Money.new(data['LowestNewPrice']['Amount'].to_i, data['LowestNewPrice']['CurrencyCode'])
  end
jchauhan commented 11 years ago

Any Updated. We want to fix it before going live.

mhuggins commented 11 years ago

Just updated the gem to 0.1.2 with a fix. Please let me know if you're still having any issues. Thanks!

jchauhan commented 11 years ago

Many Thanks. It has fixed the issue.

mhuggins commented 11 years ago

:thumbsup: