acts_as_amazon_product 1.1 → 1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,16 +21,18 @@ module Netphase
21
21
  :asin => 'asin',
22
22
  :name => 'name',
23
23
  :access_key => ENV['AMAZON_ACCESS_KEY_ID'],
24
- :associate_tag => ENV['AMAZON_ASSOCIATE_TAG']
24
+ :associate_tag => ENV['AMAZON_ASSOCIATE_TAG'],
25
+ :search_index => 'Books'
25
26
  }
26
27
  options = defaults.merge options
27
28
 
28
29
  Amazon::Ecs.options = {:aWS_access_key_id => options[:access_key], :associate_tag => options[:associate_tag] }
29
30
 
30
31
  write_inheritable_attribute(:amazon_asin, options[:asin])
31
- write_inheritable_attribute(:amazon_name, options[:name])
32
+ write_inheritable_attribute(:amazon_name, options[:name])
33
+ write_inheritable_attribute(:amazon_search_index, options[:search_index])
32
34
  write_inheritable_attribute(:amazon_associate_key, options[:associate_key])
33
- class_inheritable_reader :amazon_asin, :amazon_name, :amazon_associate_key
35
+ class_inheritable_reader :amazon_asin, :amazon_name, :amazon_search_index, :amazon_associate_key
34
36
 
35
37
  has_one :amazon_product, :as => :amazonable #, :dependent => :delete
36
38
  include Netphase::Acts::Amazonable::InstanceMethods
@@ -51,20 +53,21 @@ module Netphase
51
53
  if self.amazon_product.nil?
52
54
  asin = (self.respond_to?('amazon_asin')) ? self.send(self.amazon_asin) : nil
53
55
  name = (self.respond_to?('amazon_name')) ? self.send(self.amazon_name) : nil
56
+ search_index = (self.respond_to?('amazon_search_index')) ? self.amazon_search_index : 'Books'
54
57
 
55
58
  if !asin.nil? && asin.length > 0
56
- #puts "Looking up #{asin}"
59
+ # puts "Looking up #{asin}"
57
60
  res = Amazon::Ecs.item_lookup(self.send(self.amazon_asin), :response_group => 'Medium')
58
61
 
59
62
  self.amazon_product =
60
63
  AmazonProduct.new(:xml => res.doc.to_html, :asin => res.doc.at('asin').inner_html)
61
64
  self.amazon_product.save
62
65
  elsif !name.nil? && name.length > 0
63
- #puts "Searching for #{name}"
64
- res = Amazon::Ecs.item_search(self.send(self.amazon_name), :response_group => 'Medium') #, :sort => 'salesrank'
66
+ # puts "Searching for #{name}"
67
+ res = Amazon::Ecs.item_search(self.send(self.amazon_name), :search_index => self.amazon_search_index, :response_group => 'Medium') #, :sort => 'salesrank'
65
68
  res = res.doc.at('items/item')
66
69
  self.amazon_product =
67
- AmazonProduct.new(:xml => res.to_html, :asin => res.at('itemattributes/isbn').inner_html)
70
+ AmazonProduct.new(:xml => res.to_html, :asin => (res.at('itemattributes/isbn').nil? ? res.at('asin').inner_html : res.at('itemattributes/isbn').inner_html))
68
71
  self.amazon_product.save
69
72
  else
70
73
  logger.error "No known attributes to search by"
@@ -27,6 +27,11 @@ ActiveRecord::Base.connection.create_table :movies do |t|
27
27
  t.column :asin, :string
28
28
  end
29
29
 
30
+ ActiveRecord::Base.connection.create_table :magazines do |t|
31
+ t.column :name, :string
32
+ t.column :asin, :string
33
+ end
34
+
30
35
  ActiveRecord::Base.connection.create_table :amazon_products do |t| # , :id => false
31
36
  t.column :asin, :string
32
37
  t.column :xml, :text
@@ -45,6 +50,10 @@ class Movie < ActiveRecord::Base
45
50
  acts_as_amazon_product
46
51
  end
47
52
 
53
+ class Magazine < ActiveRecord::Base
54
+ acts_as_amazon_product :search_index => 'Magazines'
55
+ end
56
+
48
57
  AmazonProduct.delete_all
49
58
 
50
59
  class ActAsAmazonProductTest < Test::Unit::TestCase
@@ -55,6 +64,8 @@ class ActAsAmazonProductTest < Test::Unit::TestCase
55
64
  @book_ror = Book.create(:title => 'Rails Recipes')
56
65
  @book_perl = Book.create(:title => 'Perl')
57
66
  @movie_dh = Movie.create(:name=>'Live Free or Die Hard', :asin=>'B000VNMMRA')
67
+ Magazine.delete_all
68
+ @mag_lci = Magazine.create(:name => 'La Cucina Italiana')
58
69
  end
59
70
 
60
71
  def test_isbn
@@ -67,9 +78,14 @@ class ActAsAmazonProductTest < Test::Unit::TestCase
67
78
  assert_equal("Getting Things Done: The Art of Stress-Free Productivity", @book_gtd.amazon.title)
68
79
  end
69
80
 
81
+ def test_magazine
82
+ assert_not_nil(@mag_lci.amazon)
83
+ assert_equal("B00009XFML", @mag_lci.amazon.asin)
84
+ end
85
+
70
86
  def test_small_image
71
87
  assert_not_nil(@book_gtd.amazon)
72
- assert_match(/01PBN79FHEL\.jpg/, @book_gtd.amazon.small_image_url)
88
+ assert_match(/4104N6ME70L\._SL75_\.jpg/, @book_gtd.amazon.small_image_url)
73
89
  end
74
90
 
75
91
  def test_author
@@ -1,6 +1,6 @@
1
1
  database:
2
2
  adapter: sqlite3
3
- dbfile: test.db
3
+ dbfile: test/test.db
4
4
 
5
5
  amazon:
6
6
  access_key: 1AAAABBBBCCCCDDDDEE2
data/test/test.db CHANGED
Binary file
metadata CHANGED
@@ -1,61 +1,67 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
3
- specification_version: 1
4
2
  name: acts_as_amazon_product
5
3
  version: !ruby/object:Gem::Version
6
- version: "1.1"
7
- date: 2007-11-03 00:00:00 -04:00
8
- summary: A package for simplifying use of the Amazon/ECS API
9
- require_paths:
10
- - lib
11
- email: scott@netphase.com
12
- homepage:
13
- rubyforge_project:
14
- description:
15
- autorequire: acts_as_amazon_product
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: "1.2"
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Scott Nedderman
8
+ autorequire: acts_as_amazon_product
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-04-24 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: amazon-ecs
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.5.1
23
+ version:
24
+ description:
25
+ email: scott@netphase.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
31
32
  files:
32
33
  - lib/acts_as_amazon_product.rb
33
34
  - lib/amazon_product.rb
34
35
  - test/acts_as_amazon_product_test.rb
35
36
  - test/config-example.yml
36
37
  - test/example.rb
37
- - test/foo.rb
38
38
  - test/test.db
39
39
  - README
40
- test_files: []
41
-
40
+ has_rdoc: true
41
+ homepage:
42
+ post_install_message:
42
43
  rdoc_options: []
43
44
 
44
- extra_rdoc_files:
45
- - README
46
- executables: []
47
-
48
- extensions: []
49
-
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
50
59
  requirements: []
51
60
 
52
- dependencies:
53
- - !ruby/object:Gem::Dependency
54
- name: amazon-ecs
55
- version_requirement:
56
- version_requirements: !ruby/object:Gem::Version::Requirement
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: 0.5.1
61
- version:
61
+ rubyforge_project:
62
+ rubygems_version: 0.9.5
63
+ signing_key:
64
+ specification_version: 2
65
+ summary: A package for simplifying use of the Amazon/ECS API
66
+ test_files: []
67
+
data/test/foo.rb DELETED
@@ -1,7 +0,0 @@
1
-
2
- def pathmap_partial(offset)
3
-
4
- end
5
-
6
- @path = "1/2/file"
7
- pathmap_partial()