dpickett-amazon_associate 0.6.3 → 0.6.4
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/.gitignore +1 -0
- data/{README → README.rdoc} +17 -10
- data/Rakefile +3 -3
- data/VERSION.yml +4 -0
- data/amazon_associate.gemspec +7 -5
- data/lib/amazon_associate/cache_factory.rb +1 -0
- data/lib/amazon_associate/caching_strategy/filesystem.rb +81 -86
- data/test/amazon_associate/cache_test.rb +1 -2
- data/test/amazon_associate/caching_strategy/filesystem_test.rb +9 -0
- data/test/amazon_associate/cart_test.rb +2 -1
- data/test/amazon_associate/request_test.rb +2 -2
- data/test/test_helper.rb +1 -1
- metadata +7 -5
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.swp
|
data/{README → README.rdoc}
RENAMED
@@ -15,7 +15,7 @@ instead you just need to change the element path.
|
|
15
15
|
Version: 0.6.1
|
16
16
|
|
17
17
|
== WANTS
|
18
|
-
|
18
|
+
* instance based refactoring (singletons are not ideal here)
|
19
19
|
|
20
20
|
== INSTALLATION
|
21
21
|
|
@@ -26,7 +26,9 @@ Version: 0.6.1
|
|
26
26
|
require 'amazon_associate'
|
27
27
|
|
28
28
|
# set the default options; options will be camelized and converted to REST request parameters.
|
29
|
-
AmazonAssociate::Request.
|
29
|
+
AmazonAssociate::Request.configure do |options|
|
30
|
+
options[:aWS_access_key_id] = [your developer token]
|
31
|
+
end
|
30
32
|
|
31
33
|
# options provided on method call will merge with the default options
|
32
34
|
res = AmazonAssociate::Request.item_search('ruby', {:response_group => 'Medium', :sort => 'salesrank'})
|
@@ -86,23 +88,28 @@ http://www.awszone.com/scratchpads/aws/ecs.us/index.aws
|
|
86
88
|
|
87
89
|
== CACHING
|
88
90
|
|
89
|
-
|
91
|
+
Filesystem caching is now available.
|
90
92
|
|
91
|
-
AmazonAssociate::Request.
|
92
|
-
:
|
93
|
-
|
93
|
+
AmazonAssociate::Request.configure do |options|
|
94
|
+
options[:aWS_access_key_id] = [your developer token]
|
95
|
+
options[:caching_strategy] = :filesystem
|
96
|
+
options[:caching_options] = {
|
97
|
+
:disk_quota => 200,
|
98
|
+
:cache_path => <path where you want to store requests>,
|
99
|
+
:sweep_frequency => 4
|
100
|
+
}
|
101
|
+
end
|
94
102
|
|
95
|
-
|
103
|
+
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
104
|
|
97
|
-
|
105
|
+
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
106
|
|
99
107
|
== LINKS
|
100
108
|
|
101
109
|
* http://amazon-ecs.rubyforge.org
|
102
|
-
* http://www.pluitsolutions.com/amazon-ecs
|
103
110
|
|
104
111
|
== LICENSE
|
105
112
|
|
106
113
|
(The MIT License)
|
107
114
|
|
108
|
-
Copyright (c) 2008 Dan Pickett, Enlight Solutions, Inc.
|
115
|
+
Copyright (c) 2008 Dan Pickett, Enlight Solutions, Inc.
|
data/Rakefile
CHANGED
@@ -16,12 +16,12 @@ Rake::TestTask.new(:test) do |t|
|
|
16
16
|
t.warning = true
|
17
17
|
end
|
18
18
|
|
19
|
-
desc "Generate documentation for the
|
19
|
+
desc "Generate documentation for the amazon_associate plugin."
|
20
20
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
21
21
|
rdoc.rdoc_dir = "rdoc"
|
22
22
|
rdoc.title = "amazon_associate"
|
23
23
|
rdoc.options << "--line-numbers" << "--inline-source" << "--main" << "README.textile"
|
24
|
-
rdoc.rdoc_files.include("README", "CHANGELOG")
|
24
|
+
rdoc.rdoc_files.include("README.rdoc", "CHANGELOG")
|
25
25
|
rdoc.rdoc_files.include("lib/**/*.rb")
|
26
26
|
end
|
27
27
|
|
@@ -32,7 +32,7 @@ begin
|
|
32
32
|
gemspec.summary = "Amazon Associates API Interface using Hpricot"
|
33
33
|
gemspec.email = "dpickett@enlightsolutions.com"
|
34
34
|
gemspec.homepage = "http://github.com/dpickett/amazon_associate"
|
35
|
-
gemspec.description = "
|
35
|
+
gemspec.description = "interfaces with Amazon Associate's API using Hpricot"
|
36
36
|
gemspec.authors = ["Dan Pickett"]
|
37
37
|
end
|
38
38
|
rescue LoadError
|
data/VERSION.yml
ADDED
data/amazon_associate.gemspec
CHANGED
@@ -2,23 +2,25 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{amazon_associate}
|
5
|
-
s.version = "0.6.
|
5
|
+
s.version = "0.6.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Dan Pickett"]
|
9
|
-
s.date = %q{2009-
|
10
|
-
s.description = %q{
|
9
|
+
s.date = %q{2009-06-30}
|
10
|
+
s.description = %q{interfaces with Amazon Associate's API using Hpricot}
|
11
11
|
s.email = %q{dpickett@enlightsolutions.com}
|
12
12
|
s.extra_rdoc_files = [
|
13
|
-
"README"
|
13
|
+
"README.rdoc"
|
14
14
|
]
|
15
15
|
s.files = [
|
16
16
|
".autotest",
|
17
|
+
".gitignore",
|
17
18
|
".project",
|
18
19
|
"CHANGELOG",
|
19
20
|
"MIT-LICENSE",
|
20
|
-
"README",
|
21
|
+
"README.rdoc",
|
21
22
|
"Rakefile",
|
23
|
+
"VERSION.yml",
|
22
24
|
"amazon_associate.gemspec",
|
23
25
|
"lib/amazon_associate.rb",
|
24
26
|
"lib/amazon_associate/cache_factory.rb",
|
@@ -9,6 +9,7 @@ module AmazonAssociate
|
|
9
9
|
unless self.strategy_class_hash.keys.include?(options[:caching_strategy])
|
10
10
|
raise AmazonAssociate::ConfigurationError, "Invalid caching strategy"
|
11
11
|
end
|
12
|
+
|
12
13
|
strategy_class_hash[options[:caching_strategy]].initialize_options(options)
|
13
14
|
end
|
14
15
|
|
@@ -9,106 +9,101 @@ module AmazonAssociate
|
|
9
9
|
|
10
10
|
#frequency of sweeping in hours
|
11
11
|
DEFAULT_SWEEP_FREQUENCY = 2
|
12
|
-
|
13
|
-
def self.cache(request, response)
|
14
|
-
path = self.cache_path
|
15
|
-
cached_filename = Digest::SHA1.hexdigest(response.request_url)
|
16
|
-
cached_folder = cached_filename[0..2]
|
17
12
|
|
18
|
-
|
13
|
+
class << self
|
14
|
+
attr_accessor :cache_path
|
15
|
+
attr_accessor :disk_quota
|
16
|
+
attr_accessor :sweep_frequency
|
17
|
+
|
18
|
+
def cache(request, response)
|
19
|
+
path = self.cache_path
|
20
|
+
cached_filename = Digest::SHA1.hexdigest(response.request_url)
|
21
|
+
cached_folder = cached_filename[0..2]
|
22
|
+
|
23
|
+
FileUtils.mkdir_p(File.join(path, cached_folder, cached_folder))
|
24
|
+
|
25
|
+
cached_file = File.open(File.join(path, cached_folder, cached_filename), "w")
|
26
|
+
cached_file.puts response.doc.to_s
|
27
|
+
cached_file.close
|
28
|
+
end
|
19
29
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
if FileTest.exists?(file_path)
|
30
|
-
File.read(file_path).chomp
|
31
|
-
else
|
32
|
-
nil
|
30
|
+
def get(request)
|
31
|
+
path = self.cache_path
|
32
|
+
cached_filename = Digest::SHA1.hexdigest(request)
|
33
|
+
file_path = File.join(path, cached_filename[0..2], cached_filename)
|
34
|
+
if FileTest.exists?(file_path)
|
35
|
+
File.read(file_path).chomp
|
36
|
+
else
|
37
|
+
nil
|
38
|
+
end
|
33
39
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
|
41
|
+
def initialize_options(options)
|
42
|
+
#check for required options
|
43
|
+
if options[:caching_options].nil? || options[:caching_options][:cache_path].nil?
|
44
|
+
raise AmazonAssociate::ConfigurationError, "You must specify caching options for filesystem caching: :cache_path is required"
|
45
|
+
end
|
46
|
+
|
47
|
+
#default disk quota to 200MB
|
48
|
+
Filesystem.disk_quota = options[:caching_options][:disk_quota] || DEFAULT_DISK_QUOTA
|
49
|
+
|
50
|
+
Filesystem.sweep_frequency = options[:caching_options][:sweep_frequency] || DEFAULT_SWEEP_FREQUENCY
|
51
|
+
|
52
|
+
Filesystem.cache_path = options[:caching_options][:cache_path]
|
53
|
+
|
54
|
+
if Filesystem.cache_path.nil? || !File.directory?(Filesystem.cache_path)
|
55
|
+
raise AmazonAssociate::ConfigurationError, "You must specify a cache path for filesystem caching"
|
56
|
+
end
|
57
|
+
return options
|
40
58
|
end
|
41
59
|
|
42
|
-
|
43
|
-
|
60
|
+
def sweep
|
61
|
+
perform_sweep if must_sweep?
|
62
|
+
end
|
44
63
|
|
45
|
-
|
64
|
+
private
|
65
|
+
def perform_sweep
|
66
|
+
FileUtils.rm_rf(Dir.glob("#{Filesystem.cache_path}/*"))
|
67
|
+
|
68
|
+
timestamp_sweep_performance
|
69
|
+
end
|
46
70
|
|
47
|
-
|
71
|
+
def timestamp_sweep_performance
|
72
|
+
#remove the timestamp
|
73
|
+
FileUtils.rm_rf(timestamp_filename)
|
74
|
+
|
75
|
+
#create a new one its place
|
76
|
+
timestamp = File.open(timestamp_filename, "w")
|
77
|
+
timestamp.puts(Time.now)
|
78
|
+
timestamp.close
|
79
|
+
end
|
48
80
|
|
49
|
-
|
50
|
-
|
81
|
+
def must_sweep?
|
82
|
+
sweep_time_expired? || disk_quota_exceeded?
|
51
83
|
end
|
52
84
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
def self.sweep
|
57
|
-
self.perform_sweep if must_sweep?
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.disk_quota
|
61
|
-
@@disk_quota
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.sweep_frequency
|
65
|
-
@@sweep_frequency
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.cache_path
|
69
|
-
@@cache_path
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
def self.perform_sweep
|
74
|
-
FileUtils.rm_rf(Dir.glob("#{@@cache_path}/*"))
|
85
|
+
def sweep_time_expired?
|
86
|
+
FileTest.exists?(timestamp_filename) && Time.parse(File.read(timestamp_filename).chomp) < Time.now - (sweep_frequency * 3600)
|
87
|
+
end
|
75
88
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
def self.timestamp_sweep_performance
|
80
|
-
#remove the timestamp
|
81
|
-
FileUtils.rm_rf(self.timestamp_filename)
|
89
|
+
def disk_quota_exceeded?
|
90
|
+
cache_size > Filesystem.disk_quota
|
91
|
+
end
|
82
92
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
def self.sweep_time_expired?
|
94
|
-
FileTest.exists?(timestamp_filename) && Time.parse(File.read(timestamp_filename).chomp) < Time.now - (sweep_frequency * 3600)
|
95
|
-
end
|
96
|
-
|
97
|
-
def self.disk_quota_exceeded?
|
98
|
-
cache_size > @@disk_quota
|
99
|
-
end
|
100
|
-
|
101
|
-
def self.timestamp_filename
|
102
|
-
File.join(self.cache_path, ".amz_timestamp")
|
103
|
-
end
|
104
|
-
|
105
|
-
def self.cache_size
|
106
|
-
size = 0
|
107
|
-
Find.find(@@cache_path) do|f|
|
108
|
-
size += File.size(f) if File.file?(f)
|
93
|
+
def timestamp_filename
|
94
|
+
File.join(Filesystem.cache_path, ".amz_timestamp")
|
95
|
+
end
|
96
|
+
|
97
|
+
def cache_size
|
98
|
+
size = 0
|
99
|
+
Find.find(Filesystem.cache_path) do|f|
|
100
|
+
size += File.size(f) if File.file?(f)
|
101
|
+
end
|
102
|
+
size / 1000000
|
109
103
|
end
|
110
|
-
|
104
|
+
|
111
105
|
end
|
106
|
+
|
112
107
|
end
|
113
108
|
end
|
114
109
|
end
|
@@ -27,6 +27,15 @@ class AmazonAssociate::CachingStrategy::FilesystemTest < Test::Unit::TestCase
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
should "raise an exception when a cache_path is nil" do
|
32
|
+
assert_raise(AmazonAssociate::ConfigurationError) do
|
33
|
+
AmazonAssociate::Request.configure do |options|
|
34
|
+
options[:caching_strategy] = :filesystem
|
35
|
+
options[:caching_options] = {}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
30
39
|
|
31
40
|
should "set default values for disk_quota and sweep_frequency" do
|
32
41
|
AmazonAssociate::Request.configure do |options|
|
@@ -4,6 +4,7 @@ class AmazonAssociate::CartTest < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
# create a cart to store cart_id and hmac for add, get, modify, and clear tests
|
6
6
|
def setup
|
7
|
+
sleep(2)
|
7
8
|
@asin = "0672328844"
|
8
9
|
resp = AmazonAssociate::Request.cart_create(@asin)
|
9
10
|
@cart_id = resp.doc.get_elements_by_tag_name("cartid").inner_text
|
@@ -86,4 +87,4 @@ class AmazonAssociate::CartTest < Test::Unit::TestCase
|
|
86
87
|
assert_not_nil resp.doc.get_elements_by_tag_name("hmac").inner_text
|
87
88
|
end
|
88
89
|
|
89
|
-
end
|
90
|
+
end
|
@@ -2,9 +2,9 @@ require File.dirname(__FILE__) + "/../test_helper"
|
|
2
2
|
|
3
3
|
class AmazonAssociate::RequestTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
+
sleep(1)
|
5
6
|
AmazonAssociate::Request.configure do |options|
|
6
7
|
options[:response_group] = "Large"
|
7
|
-
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -105,4 +105,4 @@ class AmazonAssociate::RequestTest < Test::Unit::TestCase
|
|
105
105
|
assert_equal "Dave Thomas", authors.first.get
|
106
106
|
end
|
107
107
|
|
108
|
-
end
|
108
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -10,7 +10,7 @@ require 'amazon_associate'
|
|
10
10
|
|
11
11
|
|
12
12
|
AmazonAssociate::Request.configure do |options|
|
13
|
-
options[:aWS_access_key_id] = ""
|
13
|
+
options[:aWS_access_key_id] = ENV["AWS_ACCESS_KEY"] || ""
|
14
14
|
|
15
15
|
#raise exception if user has not entered their access key
|
16
16
|
if options[:aWS_access_key_id] == ""
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dpickett-amazon_associate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Pickett
|
@@ -9,25 +9,27 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-30 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description:
|
16
|
+
description: interfaces with Amazon Associate's API using Hpricot
|
17
17
|
email: dpickett@enlightsolutions.com
|
18
18
|
executables: []
|
19
19
|
|
20
20
|
extensions: []
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
|
-
- README
|
23
|
+
- README.rdoc
|
24
24
|
files:
|
25
25
|
- .autotest
|
26
|
+
- .gitignore
|
26
27
|
- .project
|
27
28
|
- CHANGELOG
|
28
29
|
- MIT-LICENSE
|
29
|
-
- README
|
30
|
+
- README.rdoc
|
30
31
|
- Rakefile
|
32
|
+
- VERSION.yml
|
31
33
|
- amazon_associate.gemspec
|
32
34
|
- lib/amazon_associate.rb
|
33
35
|
- lib/amazon_associate/cache_factory.rb
|