I am trying to create a new hash out of object attributes from an array of objects. I am using the Amazon API via the ruby aaws gem, and I am having trouble figuring out how to loop through the array that the API returns so that it will only the attributes and not the entire array. When i run the code below, it returns the entire array.
def self.amazon(search)
keywords = "#{search}"
resp = Amazon::AWS.item_search('Books', { 'Title' => keywords })
items = resp.item_search_response[0].items[0].item
items.each do |attribs|
a = attribs.item_attributes
@results = []
@results << {:label => "#{a.title.to_s[0,85] unless a.title.nil?}",
:value => "#{a.title.to_s unless a.title.nil?}",
:img => "#{attribs.medium_image.url.to_s unless attribs.medium_image.url.nil?}"""
}
end
end
I need to modify the loop, but I am not sure exactly where I am wrong.