lib/a2z/responses/item.rb in a2z-0.0.2 vs lib/a2z/responses/item.rb in a2z-0.0.3

- old
+ new

@@ -1,15 +1,17 @@ module A2z module Responses class Item include Helpers - attr_accessor :asin, :detail_page_url, :links + attr_accessor :asin, :parent_asin, :detail_page_url, :links, :image_sets, + :small_image, :medium_image, :large_image def initialize @links = [] @attrs = {} + @image_sets = {} end def keys @attrs.keys end @@ -43,18 +45,33 @@ end def self.from_response(data) new.tap do |item| item.asin = data['ASIN'] + item.parent_asin = data['ParentASIN'] item.detail_page_url = data['DetailPageURL'] if data['ItemLinks'] item.links = data['ItemLinks']['ItemLink'].collect { |link| ItemLink.from_response(link) } end if data['ItemAttributes'] data['ItemAttributes'].each { |key, value| item[underscore(key)] = value } end + + if data['ImageSets'] && data['ImageSets']['ImageSet'] + image_sets = data['ImageSets']['ImageSet'] + image_sets = [image_sets] unless image_sets.kind_of?(Array) + + image_sets.each do |image_set| + image_set = ImageSet.from_response(image_set) + item.image_sets[image_set.category.to_sym] = image_set + end + end + + item.small_image = Image.from_response(data['SmallImage']) if data['SmallImage'] + item.medium_image = Image.from_response(data['MediumImage']) if data['MediumImage'] + item.large_image = Image.from_response(data['LargeImage']) if data['LargeImage'] item.freeze end end end