Module: Netphase::Acts::Amazonable::InstanceMethods
- Defined in:
- lib/acts_as_amazon_product.rb
Overview
This module contains instance methods
Instance Method Summary collapse
-
#after_save ⇒ Object
def method_missing(method, *args) end.
- #amazon ⇒ Object
Instance Method Details
#after_save ⇒ Object
def method_missing(method, *args) end
82 83 84 85 86 87 |
# File 'lib/acts_as_amazon_product.rb', line 82 def after_save unless self.amazon_product.nil? self.amazon_product.destroy self.reload end end |
#amazon ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/acts_as_amazon_product.rb', line 52 def amazon if self.amazon_product.nil? asin = (self.respond_to?('amazon_asin')) ? self.send(self.amazon_asin) : nil name = (self.respond_to?('amazon_name')) ? self.send(self.amazon_name) : nil search_index = (self.respond_to?('amazon_search_index')) ? self.amazon_search_index : 'Books' if !asin.nil? && asin.length > 0 # puts "Looking up #{asin}" res = Amazon::Ecs.item_lookup(self.send(self.amazon_asin), :response_group => 'Medium') self.amazon_product = AmazonProduct.new(:xml => res.doc.to_html, :asin => res.doc.at('asin').inner_html) self.amazon_product.save elsif !name.nil? && name.length > 0 # puts "Searching for #{name}" res = Amazon::Ecs.item_search(self.send(self.amazon_name), :search_index => self.amazon_search_index, :response_group => 'Medium') #, :sort => 'salesrank' res = res.doc.at('items/item') self.amazon_product = AmazonProduct.new(:xml => res.to_html, :asin => (res.at('itemattributes/isbn').nil? ? res.at('asin').inner_html : res.at('itemattributes/isbn').inner_html)) self.amazon_product.save else logger.error "No known attributes to search by" end end self.amazon_product end |