0
@@ -21,16 +21,18 @@ module Netphase
0
:access_key => ENV['AMAZON_ACCESS_KEY_ID'],
0
- :associate_tag => ENV['AMAZON_ASSOCIATE_TAG']
0
+ :associate_tag => ENV['AMAZON_ASSOCIATE_TAG'],
0
+ :search_index => 'Books'
0
options = defaults.merge options
0
Amazon::Ecs.options = {:aWS_access_key_id => options[:access_key], :associate_tag => options[:associate_tag] }
0
write_inheritable_attribute(:amazon_asin, options[:asin])
0
- write_inheritable_attribute(:amazon_name, options[:name])
0
+ write_inheritable_attribute(:amazon_name, options[:name])
0
+ write_inheritable_attribute(:amazon_search_index, options[:search_index])
0
write_inheritable_attribute(:amazon_associate_key, options[:associate_key])
0
- class_inheritable_reader :amazon_asin, :amazon_name, :amazon_
associate_key
0
+ class_inheritable_reader :amazon_asin, :amazon_name, :amazon_
search_index, :amazon_associate_key
0
has_one :amazon_product, :as => :amazonable #, :dependent => :delete
0
include Netphase::Acts::Amazonable::InstanceMethods
0
@@ -51,20 +53,21 @@ module Netphase
0
if self.amazon_product.nil?
0
asin = (self.respond_to?('amazon_asin')) ? self.send(self.amazon_asin) : nil
0
name = (self.respond_to?('amazon_name')) ? self.send(self.amazon_name) : nil
0
+ search_index = (self.respond_to?('amazon_search_index')) ? self.amazon_search_index : 'Books'
0
if !asin.nil? && asin.length > 0
0
- #
puts "Looking up #{asin}"
0
+ #
puts "Looking up #{asin}"
0
res = Amazon::Ecs.item_lookup(self.send(self.amazon_asin), :response_group => 'Medium')
0
AmazonProduct.new(:xml => res.doc.to_html, :asin => res.doc.at('asin').inner_html)
0
self.amazon_product.save
0
elsif !name.nil? && name.length > 0
0
- #puts "Searching for #{name}"
0
- res = Amazon::Ecs.item_search(self.send(self.amazon_name), :response_group => 'Medium') #, :sort => 'salesrank'
0
+ # puts "Searching for #{name}"
0
+ res = Amazon::Ecs.item_search(self.send(self.amazon_name), :search_index => self.amazon_search_index, :response_group => 'Medium') #, :sort => 'salesrank'
0
res = res.doc.at('items/item')
0
- AmazonProduct.new(:xml => res.to_html, :asin =>
res.at('itemattributes/isbn').inner_html)
0
+ AmazonProduct.new(:xml => res.to_html, :asin =>
(res.at('itemattributes/isbn').nil? ? res.at('asin').inner_html : res.at('itemattributes/isbn').inner_html))
0
self.amazon_product.save
0
logger.error "No known attributes to search by"
Comments
No one has commented yet.