dpickett-ruby_amazon_associates 0.5.4 → 0.6

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/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ 0.6.1 2008-11-10
2
+ * renamed to amazon_associate
3
+
4
+ 0.6 2008-11-09
5
+ * separated the classes in ecs.rb
6
+ * filesystem caching available
7
+ * more test coverage
8
+
1
9
  0.5.4 2008-10-21
2
10
  * include Chris Martin's patches
3
11
  * rename Gem to match Amazon's new name for ECS - Amazon Associates API
@@ -9,7 +17,7 @@
9
17
 
10
18
  0.5.2 2007-09-08
11
19
  ----------------
12
- * Fixed Amazon::Element.get_unescaped error when result returned for given element path is nil
20
+ * Fixed AmazonAssociate::Element.get_unescaped error when result returned for given element path is nil
13
21
 
14
22
  0.5.1 2007-02-08
15
23
  ----------------
data/README CHANGED
@@ -1,10 +1,10 @@
1
- == amazon-ecs
1
+ == amazon-associate
2
2
 
3
3
  Generic Amazon E-commerce REST API using Hpricot with configurable
4
4
  default options and method call options. Uses Response and
5
5
  Element wrapper classes for easy access to REST XML output. It supports ECS 4.0.
6
6
 
7
- It is generic, so you can easily extend <tt>Amazon::Ecs</tt> to support
7
+ It is generic, so you can easily extend <tt>AmazonAssociate::Request</tt> to support
8
8
  other not implemented REST operations; and it is also generic because it just wraps around
9
9
  Hpricot element object, instead of providing one-to-one object/attributes to XML elements map.
10
10
 
@@ -12,21 +12,24 @@ If in the future, there is a change in REST XML output structure,
12
12
  no changes will be required on <tt>amazon-ecs</tt> library,
13
13
  instead you just need to change the element path.
14
14
 
15
- Version: 0.5.4
15
+ Version: 0.6.1
16
16
 
17
+ == WANTS
18
+ * instance based refactoring (singletons are not ideal here)
19
+
17
20
  == INSTALLATION
18
21
 
19
- $ gem install amazon-ecs
22
+ $ gem install dpickett-amazon_associate
20
23
 
21
24
  == EXAMPLE
22
25
 
23
- require 'amazon/ecs'
26
+ require 'amazon_associate'
24
27
 
25
28
  # set the default options; options will be camelized and converted to REST request parameters.
26
- Amazon::Ecs.options = {:aWS_access_key_id => [your developer token]}
29
+ AmazonAssociate::Request.options = {:aWS_access_key_id => [your developer token]}
27
30
 
28
31
  # options provided on method call will merge with the default options
29
- res = Amazon::Ecs.item_search('ruby', {:response_group => 'Medium', :sort => 'salesrank'})
32
+ res = AmazonAssociate::Request.item_search('ruby', {:response_group => 'Medium', :sort => 'salesrank'})
30
33
 
31
34
  # some common response object methods
32
35
  res.is_valid_request? # return true if request is valid
@@ -36,13 +39,13 @@ Version: 0.5.4
36
39
  res.total_results # return total results
37
40
  res.item_page # return current page no if :item_page option is provided
38
41
 
39
- # traverse through each item (Amazon::Element)
42
+ # traverse through each item (AmazonAssociate::Element)
40
43
  res.items.each do |item|
41
44
  # retrieve string value using XML path
42
45
  item.get('asin')
43
46
  item.get('itemattributes/title')
44
47
 
45
- # or return Amazon::Element instance
48
+ # or return AmazonAssociate::Element instance
46
49
  atts = item.search_and_convert('itemattributes')
47
50
  atts.get('title')
48
51
 
@@ -59,28 +62,40 @@ Version: 0.5.4
59
62
  # traverse through Hpricot elements
60
63
  reviews.each do |review|
61
64
  # Getting hash value out of Hpricot element
62
- Amazon::Element.get_hash(review) # [:source => ..., :content ==> ...]
65
+ AmazonAssociate::Element.get_hash(review) # [:source => ..., :content ==> ...]
63
66
 
64
67
  # Or to get unescaped HTML values
65
- Amazon::Element.get_unescaped(review, 'source')
66
- Amazon::Element.get_unescaped(review, 'content')
68
+ AmazonAssociate::Element.get_unescaped(review, 'source')
69
+ AmazonAssociate::Element.get_unescaped(review, 'content')
67
70
 
68
71
  # Or this way
69
- el = Amazon::Element.new(review)
72
+ el = AmazonAssociate::Element.new(review)
70
73
  el.get_unescaped('source')
71
74
  el.get_unescaped('content')
72
75
  end
73
76
 
74
- # returns Amazon::Element instead of string
77
+ # returns AmazonAssociate::Element instead of string
75
78
  item.search_and_convert('itemattributes').
76
79
  end
77
80
 
78
- Refer to Amazon ECS documentation for more information on Amazon REST request parameters and XML output:
81
+ Refer to Amazon Associate's documentation for more information on Amazon REST request parameters and XML output:
79
82
  http://docs.amazonwebservices.com/AWSEcommerceService/2006-09-13/
80
83
 
81
84
  To get a sample of Amazon REST response XML output, use AWSZone.com scratch pad:
82
85
  http://www.awszone.com/scratchpads/aws/ecs.us/index.aws
83
86
 
87
+ == CACHING
88
+
89
+ Filesystem caching is now available.
90
+
91
+ AmazonAssociate::Request.options = {:aWS_access_key_id => [your developer token], :caching_strategy => :filesystem,
92
+ :caching_options => {:disk_quota => 200, :cache_path => <path where you want to store requests>, :sweep_frequency => 4}
93
+ }
94
+
95
+ The above command will cache up to 200MB of requests. It will purge the cache every 4 hours or when the disk quota has been exceeded.
96
+
97
+ Every request will be stored in the cache path. On every request, AmazonAssociate::Request will check for the presence of the cached file before querying Amazon directly.
98
+
84
99
  == LINKS
85
100
 
86
101
  * http://amazon-ecs.rubyforge.org
@@ -90,4 +105,4 @@ http://www.awszone.com/scratchpads/aws/ecs.us/index.aws
90
105
 
91
106
  (The MIT License)
92
107
 
93
- Copyright (c) 2006 Herryanto Siatono, Pluit Solutions
108
+ Copyright (c) 2008 Dan Pickett, Enlight Solutions, Inc.
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dpickett-ruby_amazon_associates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: "0.6"
5
5
  platform: ruby
6
6
  authors:
7
- - Herryanto Siatono
8
7
  - Dan Pickett
9
- autorequire: name
8
+ - Herryanto Siatono
9
+ autorequire: ruby_amazon_associates
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-10-21 00:00:00 -07:00
13
+ date: 2008-11-10 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -24,7 +24,8 @@ dependencies:
24
24
  version:
25
25
  description:
26
26
  email:
27
- - herryanto@pluitsolutions.com, dpickett@enlightsolutions.com
27
+ - dpickett@enlightsolutions.com
28
+ - herryanto@pluitsolutions.com
28
29
  executables: []
29
30
 
30
31
  extensions: []
@@ -33,7 +34,21 @@ extra_rdoc_files:
33
34
  - README
34
35
  - CHANGELOG
35
36
  files:
37
+ - lib/ruby_amazon_associates
38
+ - lib/ruby_amazon_associates/cache_factory.rb
39
+ - lib/ruby_amazon_associates/caching_strategy
40
+ - lib/ruby_amazon_associates/caching_strategy/base.rb
41
+ - lib/ruby_amazon_associates/caching_strategy/filesystem.rb
42
+ - lib/ruby_amazon_associates/caching_strategy.rb
43
+ - lib/ruby_amazon_associates/configuration_error.rb
44
+ - lib/ruby_amazon_associates/ecs.rb
45
+ - lib/ruby_amazon_associates/element.rb
46
+ - lib/ruby_amazon_associates/request_error.rb
47
+ - lib/ruby_amazon_associates/response.rb
48
+ - lib/ruby_amazon_associates.rb
36
49
  - test/amazon/browse_node_lookup_test.rb
50
+ - test/amazon/cache_test.rb
51
+ - test/amazon/caching_strategy/filesystem_test.rb
37
52
  - test/amazon/cart_test.rb
38
53
  - test/amazon/ecs_test.rb
39
54
  - README
@@ -45,7 +60,7 @@ rdoc_options:
45
60
  - --line-numbers
46
61
  - --inline-source
47
62
  - --main
48
- - README.textile
63
+ - README
49
64
  require_paths:
50
65
  - lib
51
66
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -69,5 +84,7 @@ specification_version: 2
69
84
  summary: Generic Amazon Associates Web Service (Formerly ECS) REST API. Supports ECS 4.0.
70
85
  test_files:
71
86
  - test/amazon/browse_node_lookup_test.rb
87
+ - test/amazon/cache_test.rb
88
+ - test/amazon/caching_strategy/filesystem_test.rb
72
89
  - test/amazon/cart_test.rb
73
90
  - test/amazon/ecs_test.rb
@@ -1,38 +0,0 @@
1
- require File.dirname(__FILE__) + "/../test_helper"
2
-
3
- class Amazon::BrowseNodeLookupTest < Test::Unit::TestCase
4
-
5
- ## Test browse_node_lookup
6
- def test_browse_node_lookup
7
- resp = Amazon::Ecs.browse_node_lookup("5")
8
- assert resp.is_valid_request?
9
- browse_node_tags = resp.doc.get_elements_by_tag_name("browsenodeid")
10
- browse_node_tags.each { |node| assert_equal("5", node.inner_text) }
11
- assert_equal "TopSellers", resp.doc.get_elements_by_tag_name("responsegroup").inner_text
12
- end
13
-
14
- def test_browse_node_lookup_with_browse_node_info_response
15
- resp = Amazon::Ecs.browse_node_lookup("5", :response_group => "BrowseNodeInfo")
16
- assert resp.is_valid_request?
17
- assert_equal "BrowseNodeInfo", resp.doc.get_elements_by_tag_name("responsegroup").inner_text
18
- end
19
-
20
- def test_browse_node_lookup_with_new_releases_response
21
- resp = Amazon::Ecs.browse_node_lookup("5", :response_group => "NewReleases")
22
- assert resp.is_valid_request?
23
- assert_equal "NewReleases", resp.doc.get_elements_by_tag_name("responsegroup").inner_text
24
- end
25
-
26
- def test_browse_node_lookup_with_invalid_request
27
- resp = Amazon::Ecs.browse_node_lookup(nil)
28
- assert resp.has_error?
29
- assert resp.error
30
- end
31
-
32
- def test_browse_node_lookup_with_no_result
33
- resp = Amazon::Ecs.browse_node_lookup("abc")
34
-
35
- assert resp.is_valid_request?
36
- assert_match(/abc is not a valid value for BrowseNodeId/, resp.error)
37
- end
38
- end
@@ -1,58 +0,0 @@
1
- require File.dirname(__FILE__) + "/../test_helper"
2
-
3
- class Amazon::CartTest < Test::Unit::TestCase
4
-
5
- # create a cart to store cart_id and hmac for add, get, modify, and clear tests
6
- def setup
7
- @asin = "0672328844"
8
- resp = Amazon::Ecs.cart_create(@asin)
9
- @cart_id = resp.doc.get_elements_by_tag_name("cartid").inner_text
10
- @hmac = resp.doc.get_elements_by_tag_name("hmac").inner_text
11
- item = resp.first_item
12
- # run tests for cart_create with default quantity while we"re at it
13
- assert resp.is_valid_request?
14
- assert_equal @asin, item.get("asin")
15
- assert_equal "1", item.get("quantity")
16
- assert_not_nil @cart_id
17
- assert_not_nil @hmac
18
- end
19
-
20
- # Test cart_get
21
- def test_cart_get
22
- resp = Amazon::Ecs.cart_get(@cart_id, @hmac)
23
- assert resp.is_valid_request?
24
- assert_not_nil resp.doc.get_elements_by_tag_name("purchaseurl").inner_text
25
- end
26
-
27
- # Test cart_modify
28
- def test_cart_modify
29
- resp = Amazon::Ecs.cart_get(@cart_id, @hmac)
30
- cart_item_id = resp.doc.get_elements_by_tag_name("cartitemid").inner_text
31
- resp = Amazon::Ecs.cart_modify(cart_item_id, @cart_id, @hmac, 2)
32
- item = resp.first_item
33
-
34
- assert resp.is_valid_request?
35
- assert_equal "2", item.get("quantity")
36
- assert_not_nil resp.doc.get_elements_by_tag_name("purchaseurl").inner_text
37
- end
38
-
39
- # Test cart_clear
40
- def test_cart_clear
41
- resp = Amazon::Ecs.cart_clear(@cart_id, @hmac)
42
- assert resp.is_valid_request?
43
- end
44
-
45
- ## Test cart_create with a specified quantity
46
- ## note this will create a separate cart
47
- def test_cart_create_with_quantity
48
- asin = "0672328844"
49
- resp = Amazon::Ecs.cart_create(asin, :quantity => 2)
50
- assert resp.is_valid_request?
51
- item = resp.first_item
52
- assert_equal asin, item.get("asin")
53
- assert_equal "2", item.get("quantity")
54
- assert_not_nil resp.doc.get_elements_by_tag_name("cartid").inner_text
55
- assert_not_nil resp.doc.get_elements_by_tag_name("hmac").inner_text
56
- end
57
-
58
- end
@@ -1,106 +0,0 @@
1
- require File.dirname(__FILE__) + "/../test_helper"
2
-
3
- class Amazon::EcsTest < Test::Unit::TestCase
4
- def setup
5
- Amazon::Ecs.configure do |options|
6
- options[:response_group] = "Large"
7
-
8
- end
9
- end
10
- ## Test item_search
11
- def test_item_search
12
- resp = Amazon::Ecs.item_search("ruby")
13
- assert(resp.is_valid_request?)
14
- assert(resp.total_results >= 3600)
15
- assert(resp.total_pages >= 360)
16
- end
17
-
18
- def test_item_search_with_paging
19
- resp = Amazon::Ecs.item_search("ruby", :item_page => 2)
20
- assert resp.is_valid_request?
21
- assert 2, resp.item_page
22
- end
23
-
24
- def test_item_search_with_invalid_request
25
- resp = Amazon::Ecs.item_search(nil)
26
- assert !resp.is_valid_request?
27
- end
28
-
29
- def test_item_search_with_no_result
30
- resp = Amazon::Ecs.item_search("afdsafds")
31
-
32
- assert resp.is_valid_request?
33
- assert_equal "We did not find any matches for your request.",
34
- resp.error
35
- end
36
-
37
- def test_item_search_uk
38
- resp = Amazon::Ecs.item_search("ruby", :country => :uk)
39
- assert resp.is_valid_request?
40
- end
41
-
42
- def test_item_search_by_author
43
- resp = Amazon::Ecs.item_search("dave", :type => :author)
44
- assert resp.is_valid_request?
45
- end
46
-
47
- def test_item_get
48
- resp = Amazon::Ecs.item_search("0974514055")
49
- item = resp.first_item
50
-
51
- # test get
52
- assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition",
53
- item.get("itemattributes/title")
54
-
55
- # test get_array
56
- assert_equal ["Dave Thomas", "Chad Fowler", "Andy Hunt"],
57
- item.get_array("author")
58
-
59
- # test get_hash
60
- small_image = item.get_hash("smallimage")
61
-
62
- assert_equal 3, small_image.keys.size
63
- assert small_image[:url] != nil
64
- assert_equal "75", small_image[:height]
65
- assert_equal "59", small_image[:width]
66
-
67
- # test /
68
- reviews = item/"editorialreview"
69
- reviews.each do |review|
70
- # returns unescaped HTML content, Hpricot escapes all text values
71
- assert Amazon::Element.get_unescaped(review, "source")
72
- assert Amazon::Element.get_unescaped(review, "content")
73
- end
74
- end
75
-
76
- ## Test item_lookup
77
- def test_item_lookup
78
- resp = Amazon::Ecs.item_lookup("0974514055")
79
- assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition",
80
- resp.first_item.get("itemattributes/title")
81
- end
82
-
83
- def test_item_lookup_with_invalid_request
84
- resp = Amazon::Ecs.item_lookup(nil)
85
- assert resp.has_error?
86
- assert resp.error
87
- end
88
-
89
- def test_item_lookup_with_no_result
90
- resp = Amazon::Ecs.item_lookup("abc")
91
-
92
- assert resp.is_valid_request?
93
- assert_match(/ABC is not a valid value for ItemId/, resp.error)
94
- end
95
-
96
- def test_search_and_convert
97
- resp = Amazon::Ecs.item_lookup("0974514055")
98
- title = resp.first_item.get("itemattributes/title")
99
- authors = resp.first_item.search_and_convert("author")
100
-
101
- assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition", title
102
- assert authors.is_a?(Array)
103
- assert 3, authors.size
104
- assert_equal "Dave Thomas", authors.first.get
105
- end
106
- end