dpickett-amazon_associate 0.6.2 → 0.6.3

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.
data/.autotest ADDED
@@ -0,0 +1,8 @@
1
+ Autotest.add_hook :initialize do |at|
2
+ at.clear_mappings
3
+
4
+ at.add_mapping(%r{^test/.*_test\.rb$}) {|f, _| [f] }
5
+ at.add_mapping(%r{^lib/amazon/(.*)\.rb$}) {|_, m| ["test/#{m[1]}_test.rb"] }
6
+ at.add_mapping(%r{^test/(test_helper)\.rb$}) { at.files_matching %r{^test/.*_test\.rb$} }
7
+ at.add_mapping(%r{^lib/.*\.rb$}) { at.files_matching %r{^test/.*_test\.rb$} }
8
+ end
data/.project ADDED
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>amazon-ecs</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>org.rubypeople.rdt.core.rubybuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ <buildCommand>
14
+ <name>com.ibm.etools.validation.validationbuilder</name>
15
+ <arguments>
16
+ </arguments>
17
+ </buildCommand>
18
+ </buildSpec>
19
+ <natures>
20
+ <nature>org.radrails.rails.ui.railsnature</nature>
21
+ <nature>org.rubypeople.rdt.core.rubynature</nature>
22
+ </natures>
23
+ </projectDescription>
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2008 Dan Pickett, Enlight Solutions
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
data/Rakefile ADDED
@@ -0,0 +1,43 @@
1
+ require "rubygems"
2
+ require "rake"
3
+ require "rake/testtask"
4
+ require "rake/rdoctask"
5
+ require "rake/gempackagetask"
6
+ require "date"
7
+
8
+ desc "Run unit tests."
9
+ task :default => :test
10
+
11
+ desc "Test the amazon_associate library."
12
+ Rake::TestTask.new(:test) do |t|
13
+ t.libs << "test"
14
+ t.test_files = FileList["test/**/*test.rb"]
15
+ t.verbose = true
16
+ t.warning = true
17
+ end
18
+
19
+ desc "Generate documentation for the factory_girl plugin."
20
+ Rake::RDocTask.new(:rdoc) do |rdoc|
21
+ rdoc.rdoc_dir = "rdoc"
22
+ rdoc.title = "amazon_associate"
23
+ rdoc.options << "--line-numbers" << "--inline-source" << "--main" << "README.textile"
24
+ rdoc.rdoc_files.include("README", "CHANGELOG")
25
+ rdoc.rdoc_files.include("lib/**/*.rb")
26
+ end
27
+
28
+ begin
29
+ require 'jeweler'
30
+ Jeweler::Tasks.new do |gemspec|
31
+ gemspec.name = "amazon_associate"
32
+ gemspec.summary = "Amazon Associates API Interface using Hpricot"
33
+ gemspec.email = "dpickett@enlightsolutions.com"
34
+ gemspec.homepage = "http://github.com/dpickett/amazon_associate"
35
+ gemspec.description = "TODO"
36
+ gemspec.authors = ["Dan Pickett"]
37
+ end
38
+ rescue LoadError
39
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
40
+ end
41
+
42
+ desc "Clean files generated by rake tasks"
43
+ task :clobber => [:clobber_rdoc, :clobber_package]
@@ -0,0 +1,66 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{amazon_associate}
5
+ s.version = "0.6.3"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Dan Pickett"]
9
+ s.date = %q{2009-05-15}
10
+ s.description = %q{TODO}
11
+ s.email = %q{dpickett@enlightsolutions.com}
12
+ s.extra_rdoc_files = [
13
+ "README"
14
+ ]
15
+ s.files = [
16
+ ".autotest",
17
+ ".project",
18
+ "CHANGELOG",
19
+ "MIT-LICENSE",
20
+ "README",
21
+ "Rakefile",
22
+ "amazon_associate.gemspec",
23
+ "lib/amazon_associate.rb",
24
+ "lib/amazon_associate/cache_factory.rb",
25
+ "lib/amazon_associate/caching_strategy.rb",
26
+ "lib/amazon_associate/caching_strategy/base.rb",
27
+ "lib/amazon_associate/caching_strategy/filesystem.rb",
28
+ "lib/amazon_associate/configuration_error.rb",
29
+ "lib/amazon_associate/element.rb",
30
+ "lib/amazon_associate/request.rb",
31
+ "lib/amazon_associate/request_error.rb",
32
+ "lib/amazon_associate/response.rb",
33
+ "test/amazon_associate/browse_node_lookup_test.rb",
34
+ "test/amazon_associate/cache_test.rb",
35
+ "test/amazon_associate/caching_strategy/filesystem_test.rb",
36
+ "test/amazon_associate/cart_test.rb",
37
+ "test/amazon_associate/request_test.rb",
38
+ "test/test_helper.rb",
39
+ "test/utilities/filesystem_test_helper.rb"
40
+ ]
41
+ s.has_rdoc = true
42
+ s.homepage = %q{http://github.com/dpickett/amazon_associate}
43
+ s.rdoc_options = ["--charset=UTF-8"]
44
+ s.require_paths = ["lib"]
45
+ s.rubygems_version = %q{1.3.2}
46
+ s.summary = %q{Amazon Associates API Interface using Hpricot}
47
+ s.test_files = [
48
+ "test/amazon_associate/browse_node_lookup_test.rb",
49
+ "test/amazon_associate/cache_test.rb",
50
+ "test/amazon_associate/caching_strategy/filesystem_test.rb",
51
+ "test/amazon_associate/cart_test.rb",
52
+ "test/amazon_associate/request_test.rb",
53
+ "test/test_helper.rb",
54
+ "test/utilities/filesystem_test_helper.rb"
55
+ ]
56
+
57
+ if s.respond_to? :specification_version then
58
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
59
+ s.specification_version = 3
60
+
61
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
62
+ else
63
+ end
64
+ else
65
+ end
66
+ end
@@ -97,28 +97,47 @@ module AmazonAssociate
97
97
  # Item.ASIN.Quantity defaults to 1, unless otherwise specified in _opts_
98
98
 
99
99
  # Creates remote shopping cart containing _asin_
100
- def self.cart_create(asin, opts = {})
100
+ def self.cart_create(items, opts = {})
101
101
  opts = self.options.merge(opts) if self.options
102
102
  opts[:operation] = "CartCreate"
103
- opts["Item.#{asin}.Quantity"] = opts[:quantity] || 1
104
- opts["Item.#{asin}.ASIN"] = asin
103
+
104
+ if items.is_a?(String)
105
+ asin = items
106
+ opts["Item.#{asin}.Quantity"] = opts[:quantity] || 1
107
+ opts["Item.#{asin}.ASIN"] = asin
108
+ else
109
+ items.each do |item|
110
+ (item[:offer_listing_id].nil? || item[:offer_listing_id].empty?) ? opts["Item.#{item[:asin]}.ASIN"] = item[:asin] : opts["Item.#{item[:asin]}.OfferListingId"] = item[:offer_listing_id]
111
+ opts["Item.#{item[:asin]}.Quantity"] = item[:quantity] || 1
112
+ end
113
+ end
105
114
 
106
115
  self.send_request(opts)
107
116
  end
108
117
 
109
- # Adds item to remote shopping cart
110
- def self.cart_add(asin, cart_id, hmac, opts = {})
118
+ # Adds items to remote shopping cart
119
+ def self.cart_add(items, cart_id, hmac, opts = {})
111
120
  opts = self.options.merge(opts) if self.options
112
121
  opts[:operation] = "CartAdd"
113
- opts["Item.#{asin}.Quantity"] = opts[:quantity] || 1
114
- opts["Item.#{asin}.ASIN"] = asin
122
+
123
+ if items.is_a?(String)
124
+ asin = items
125
+ opts["Item.#{asin}.Quantity"] = opts[:quantity] || 1
126
+ opts["Item.#{asin}.ASIN"] = asin
127
+ else
128
+ items.each do |item|
129
+ (item[:offer_listing_id].nil? || item[:offer_listing_id].empty?) ? opts["Item.#{item[:asin]}.ASIN"] = item[:asin] : opts["Item.#{item[:asin]}.OfferListingId"] = item[:offer_listing_id]
130
+ opts["Item.#{item[:asin]}.Quantity"] = item[:quantity] || 1
131
+ end
132
+ end
133
+
115
134
  opts[:cart_id] = cart_id
116
135
  opts[:hMAC] = hmac
117
136
 
118
137
  self.send_request(opts)
119
138
  end
120
139
 
121
- # Adds item to remote shopping cart
140
+ # Retrieve a remote shopping cart
122
141
  def self.cart_get(cart_id, hmac, opts = {})
123
142
  opts = self.options.merge(opts) if self.options
124
143
  opts[:operation] = "CartGet"
@@ -255,6 +274,7 @@ module AmazonAssociate
255
274
  qs = ""
256
275
  opts.each {|k,v|
257
276
  next unless v
277
+ next if [:caching_options, :caching_strategy].include?(k)
258
278
  v = v.join(",") if v.is_a? Array
259
279
  qs << "&#{camelize(k.to_s)}=#{URI.encode(v.to_s)}"
260
280
  }
@@ -273,4 +293,4 @@ module AmazonAssociate
273
293
  AmazonAssociate::CacheFactory.cache(request, response, options)
274
294
  end
275
295
  end
276
- end
296
+ end
@@ -88,6 +88,12 @@ class AmazonAssociate::CachingStrategy::FilesystemTest < Test::Unit::TestCase
88
88
  assert FileTest.exists?(File.join(@@cache_path + @filename[0..2], @filename))
89
89
  assert_equal @resp.doc.to_s, File.read(File.join(@@cache_path + @filename[0..2], @filename)).chomp
90
90
  end
91
+
92
+ should "not send cache parameters in the request" do
93
+ [:caching_strategy].each do |param|
94
+ assert_no_match /#{param.to_s}/, @resp.request_url
95
+ end
96
+ end
91
97
  end
92
98
 
93
99
  context "getting a cached request" do
@@ -55,4 +55,35 @@ class AmazonAssociate::CartTest < Test::Unit::TestCase
55
55
  assert_not_nil resp.doc.get_elements_by_tag_name("hmac").inner_text
56
56
  end
57
57
 
58
+ # Test cart_create with an array of hashes representing multiple items
59
+ def test_cart_create_with_multiple_items
60
+ items = [ { :asin => "0974514055", :quantity => 2 }, { :asin => "0672328844", :quantity => 3 } ]
61
+ resp = AmazonAssociate::Request.cart_create(items)
62
+ assert resp.is_valid_request?
63
+ first_item, second_item = resp.items.reverse[0], resp.items.reverse[1]
64
+
65
+ assert_equal items[0][:asin], first_item.get("asin")
66
+ assert_equal items[0][:quantity].to_s, first_item.get("quantity")
67
+
68
+ assert_equal items[1][:asin], second_item.get("asin")
69
+ assert_equal items[1][:quantity].to_s, second_item.get("quantity")
70
+
71
+ assert_not_nil resp.doc.get_elements_by_tag_name("cartid").inner_text
72
+ assert_not_nil resp.doc.get_elements_by_tag_name("hmac").inner_text
73
+ end
74
+
75
+ # Test cart_create with offer_listing_id instead of asin
76
+ def test_cart_create_with_offer_listing_id
77
+ items = [ { :offer_listing_id => "MCK%2FnCXIges8tpX%2B222nOYEqeZ4AzbrFyiHuP6pFf45N3vZHTm8hFTytRF%2FLRONNkVmt182%2BmeX72n%2BbtUcGEtpLN92Oy9Y7", :quantity => 2 } ]
78
+ resp = AmazonAssociate::Request.cart_create(items)
79
+ assert resp.is_valid_request?
80
+ first_item = resp.items.first
81
+
82
+ assert_equal items[0][:offer_listing_id], first_item.get("offerlistingid")
83
+ assert_equal items[0][:quantity].to_s, first_item.get("quantity")
84
+
85
+ assert_not_nil resp.doc.get_elements_by_tag_name("cartid").inner_text
86
+ assert_not_nil resp.doc.get_elements_by_tag_name("hmac").inner_text
87
+ end
88
+
58
89
  end
@@ -0,0 +1,19 @@
1
+ require "rubygems"
2
+ require "test/unit"
3
+ require "shoulda"
4
+ require "mocha"
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__) , '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__) , 'utilities'))
8
+ require "filesystem_test_helper"
9
+ require 'amazon_associate'
10
+
11
+
12
+ AmazonAssociate::Request.configure do |options|
13
+ options[:aWS_access_key_id] = ""
14
+
15
+ #raise exception if user has not entered their access key
16
+ if options[:aWS_access_key_id] == ""
17
+ raise "Access key is not entered - enter an access key in test_helper.rb if you'd like to run tests"
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ module FilesystemTestHelper
2
+ @@cache_path = File.dirname(__FILE__) + "/cache/"
3
+
4
+ protected
5
+ def get_valid_caching_options
6
+ #configure Amazon library for filesystem caching
7
+ AmazonAssociate::Request.configure do |options|
8
+ options[:caching_strategy] = :filesystem
9
+ options[:caching_options] = {:cache_path => @@cache_path}
10
+ options[:disk_quota] = 200
11
+ end
12
+ end
13
+
14
+ def destroy_caching_options
15
+ #reset caching to off
16
+ AmazonAssociate::Request.configure do |options|
17
+ options[:caching_strategy] = nil
18
+ options[:caching_options] = nil
19
+ end
20
+ end
21
+
22
+ def get_cache_directory
23
+ #make the caching directory
24
+ FileUtils.makedirs(@@cache_path)
25
+ end
26
+
27
+ def destroy_cache_directory
28
+ #remove all the cache files
29
+ FileUtils.rm_rf(@@cache_path)
30
+ end
31
+ end
metadata CHANGED
@@ -1,66 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dpickett-amazon_associate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Pickett
8
- - Herryanto Siatono
9
- autorequire: amazon_associate
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
 
13
- date: 2008-11-25 00:00:00 -08:00
12
+ date: 2009-05-15 00:00:00 -07:00
14
13
  default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: hpricot
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0.6"
24
- version:
25
- description:
26
- email:
27
- - dpickett@enlightsolutions.com
28
- - herryanto@pluitsolutions.com
14
+ dependencies: []
15
+
16
+ description: TODO
17
+ email: dpickett@enlightsolutions.com
29
18
  executables: []
30
19
 
31
20
  extensions: []
32
21
 
33
22
  extra_rdoc_files:
34
23
  - README
35
- - CHANGELOG
36
24
  files:
37
- - lib/amazon_associate
25
+ - .autotest
26
+ - .project
27
+ - CHANGELOG
28
+ - MIT-LICENSE
29
+ - README
30
+ - Rakefile
31
+ - amazon_associate.gemspec
32
+ - lib/amazon_associate.rb
38
33
  - lib/amazon_associate/cache_factory.rb
39
- - lib/amazon_associate/caching_strategy
34
+ - lib/amazon_associate/caching_strategy.rb
40
35
  - lib/amazon_associate/caching_strategy/base.rb
41
36
  - lib/amazon_associate/caching_strategy/filesystem.rb
42
- - lib/amazon_associate/caching_strategy.rb
43
37
  - lib/amazon_associate/configuration_error.rb
44
38
  - lib/amazon_associate/element.rb
45
39
  - lib/amazon_associate/request.rb
46
40
  - lib/amazon_associate/request_error.rb
47
41
  - lib/amazon_associate/response.rb
48
- - lib/amazon_associate.rb
49
42
  - test/amazon_associate/browse_node_lookup_test.rb
50
43
  - test/amazon_associate/cache_test.rb
51
44
  - test/amazon_associate/caching_strategy/filesystem_test.rb
52
45
  - test/amazon_associate/cart_test.rb
53
46
  - test/amazon_associate/request_test.rb
54
- - README
55
- - CHANGELOG
47
+ - test/test_helper.rb
48
+ - test/utilities/filesystem_test_helper.rb
56
49
  has_rdoc: true
57
- homepage: http://github.com/dpickett/amazon_associate/tree/master
50
+ homepage: http://github.com/dpickett/amazon_associate
58
51
  post_install_message:
59
52
  rdoc_options:
60
- - --line-numbers
61
- - --inline-source
62
- - --main
63
- - README
53
+ - --charset=UTF-8
64
54
  require_paths:
65
55
  - lib
66
56
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -80,11 +70,13 @@ requirements: []
80
70
  rubyforge_project:
81
71
  rubygems_version: 1.2.0
82
72
  signing_key:
83
- specification_version: 2
84
- summary: Generic Amazon Associates Web Service (Formerly ECS) REST API. Supports ECS 4.0.
73
+ specification_version: 3
74
+ summary: Amazon Associates API Interface using Hpricot
85
75
  test_files:
86
76
  - test/amazon_associate/browse_node_lookup_test.rb
87
77
  - test/amazon_associate/cache_test.rb
88
78
  - test/amazon_associate/caching_strategy/filesystem_test.rb
89
79
  - test/amazon_associate/cart_test.rb
90
80
  - test/amazon_associate/request_test.rb
81
+ - test/test_helper.rb
82
+ - test/utilities/filesystem_test_helper.rb