I'm using the Ruby-AWS gem to interact with Amazon. I was testing it out in my controller and it worked fine, but when I moved the code into my Model, it isn't correctly parsing the data back from amazon.
For instance, in my controller
@items[0].medium_image.url = "http://ecx.images-amazon.com/images/I/61YIGdgh86L._SL160_.jpg"
But in my model
items[0].medium_umage.url = '[#<Amazon::AWS::AWSObject::URL:0x1030ba758 value="http://ecx.images-amazon.com/images/I/61YIGdgh86L._SL160_.jpg">]'
Please help!
In both cases, my code is:
def add_amazon_links
require 'amazon/aws'
require 'amazon/aws/search'
query = self.name
#!/usr/bin/ruby -w
#
# $Id: item_search1,v 1.4 2008/04/11 19:24:24 ianmacd Exp $
is = ItemSearch.new( 'All', { 'Keywords' => '#{query}' })
rg = ResponseGroup.new( 'Medium', 'Reviews')
req = Request.new
req.locale = 'us'
resp = req.search( is, rg )
items = resp.item_search_response[0].items[0].item
@items = resp.item_search_response[0].items[0].item
unless @items[0].blank?
self.image_url = @items[0].medium_image.url
self.a_price = @items[0].item_attributes[0].list_price[0].formatted_price
self.title = @items[0].item_attributes[0].title
self.a_url = @items[0].detail_page_url
self.save!
end
end