amazon-ecs 0.5.6 → 0.5.7
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 +4 -0
- data/README +1 -1
- data/lib/amazon/ecs.rb +14 -2
- data/test/amazon/ecs_test.rb +103 -100
- metadata +2 -2
data/CHANGELOG
CHANGED
data/README
CHANGED
data/lib/amazon/ecs.rb
CHANGED
@@ -26,6 +26,7 @@ require 'hpricot'
|
|
26
26
|
require 'cgi'
|
27
27
|
require 'hmac-sha2'
|
28
28
|
require 'base64'
|
29
|
+
require 'openssl'
|
29
30
|
|
30
31
|
module Amazon
|
31
32
|
class RequestError < StandardError; end
|
@@ -39,6 +40,11 @@ module Amazon
|
|
39
40
|
:fr => 'http://webservices.amazon.fr/onca/xml?'
|
40
41
|
}
|
41
42
|
|
43
|
+
OPENSSL_DIGEST_SUPPORT = OpenSSL::Digest.constants.include?( 'SHA256' ) ||
|
44
|
+
OpenSSL::Digest.constants.include?( :SHA256 )
|
45
|
+
|
46
|
+
OPENSSL_DIGEST = OpenSSL::Digest::Digest.new( 'sha256' ) if OPENSSL_DIGEST_SUPPORT
|
47
|
+
|
42
48
|
@@options = {
|
43
49
|
:version => "2009-01-06",
|
44
50
|
:service => "AWSECommerceService"
|
@@ -245,10 +251,16 @@ module Amazon
|
|
245
251
|
|
246
252
|
def self.sign_request(url, key)
|
247
253
|
return nil if key.nil?
|
248
|
-
|
254
|
+
|
255
|
+
if (OPENSSL_DIGEST_SUPPORT)
|
256
|
+
signature = OpenSSL::HMAC.digest(OPENSSL_DIGEST, key, url)
|
257
|
+
signature = [signature].pack('m').chomp
|
258
|
+
else
|
259
|
+
signature = Base64.encode64( HMAC::SHA256.digest(key, url) ).strip
|
260
|
+
end
|
261
|
+
signature = URI.escape(signature, Regexp.new("[+=]"))
|
249
262
|
return signature
|
250
263
|
end
|
251
|
-
|
252
264
|
end
|
253
265
|
|
254
266
|
# Internal wrapper class to provide convenient method to access Hpricot element value.
|
data/test/amazon/ecs_test.rb
CHANGED
@@ -16,108 +16,111 @@ class Amazon::EcsTest < Test::Unit::TestCase
|
|
16
16
|
|
17
17
|
## Test item_search
|
18
18
|
def test_item_search
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
assert resp.is_valid_request?
|
38
|
-
assert 2, resp.item_page
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_item_search_with_invalid_request
|
42
|
-
resp = Amazon::Ecs.item_search(nil)
|
43
|
-
assert !resp.is_valid_request?
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_item_search_with_no_result
|
47
|
-
resp = Amazon::Ecs.item_search('afdsafds')
|
48
|
-
|
49
|
-
assert resp.is_valid_request?
|
50
|
-
assert_equal "We did not find any matches for your request.",
|
51
|
-
resp.error
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_item_search_uk
|
55
|
-
resp = Amazon::Ecs.item_search('ruby', :country => :uk)
|
56
|
-
assert resp.is_valid_request?
|
57
|
-
end
|
19
|
+
resp = Amazon::Ecs.item_search('ruby')
|
20
|
+
|
21
|
+
assert(resp.is_valid_request?)
|
22
|
+
assert(resp.total_results >= 3600)
|
23
|
+
assert(resp.total_pages >= 360)
|
24
|
+
|
25
|
+
signature_elements = (resp.doc/"arguments/argument").select do |ele|
|
26
|
+
ele.attributes['name'] == 'Signature' || ele.attributes['Name'] == 'Signature'
|
27
|
+
end.length
|
28
|
+
|
29
|
+
assert(signature_elements == 1)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_item_search_with_special_characters
|
33
|
+
Amazon::Ecs.debug = true
|
34
|
+
resp = Amazon::Ecs.item_search('()*&^%$')
|
35
|
+
assert(resp.is_valid_request?)
|
36
|
+
end
|
58
37
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
38
|
+
def test_item_search_with_paging
|
39
|
+
resp = Amazon::Ecs.item_search('ruby', :item_page => 2)
|
40
|
+
assert resp.is_valid_request?
|
41
|
+
assert 2, resp.item_page
|
42
|
+
end
|
63
43
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
# test get
|
69
|
-
assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition",
|
70
|
-
item.get("itemattributes/title")
|
71
|
-
|
72
|
-
# test get_array
|
73
|
-
assert_equal ['Dave Thomas', 'Chad Fowler', 'Andy Hunt'],
|
74
|
-
item.get_array("author")
|
75
|
-
|
76
|
-
# test get_hash
|
77
|
-
small_image = item.get_hash("smallimage")
|
78
|
-
|
79
|
-
assert_equal 3, small_image.keys.size
|
80
|
-
assert_match ".jpg", small_image[:url]
|
81
|
-
assert_equal "75", small_image[:height]
|
82
|
-
assert_equal "59", small_image[:width]
|
83
|
-
|
84
|
-
# test /
|
85
|
-
reviews = item/"editorialreview"
|
86
|
-
reviews.each do |review|
|
87
|
-
# returns unescaped HTML content, Hpricot escapes all text values
|
88
|
-
assert Amazon::Element.get_unescaped(review, 'source')
|
89
|
-
assert Amazon::Element.get_unescaped(review, 'content')
|
90
|
-
end
|
91
|
-
end
|
44
|
+
def test_item_search_with_invalid_request
|
45
|
+
resp = Amazon::Ecs.item_search(nil)
|
46
|
+
assert !resp.is_valid_request?
|
47
|
+
end
|
92
48
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
49
|
+
def test_item_search_with_no_result
|
50
|
+
resp = Amazon::Ecs.item_search('afdsafds')
|
51
|
+
|
52
|
+
assert resp.is_valid_request?
|
53
|
+
assert_equal "We did not find any matches for your request.",
|
54
|
+
resp.error
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_item_search_uk
|
58
|
+
resp = Amazon::Ecs.item_search('ruby', :country => :uk)
|
59
|
+
assert resp.is_valid_request?
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_item_search_by_author
|
63
|
+
resp = Amazon::Ecs.item_search('dave', :type => :author)
|
64
|
+
assert resp.is_valid_request?
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_item_get
|
68
|
+
resp = Amazon::Ecs.item_search("0974514055")
|
69
|
+
item = resp.first_item
|
70
|
+
|
71
|
+
# test get
|
72
|
+
assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition",
|
73
|
+
item.get("itemattributes/title")
|
74
|
+
|
75
|
+
# test get_array
|
76
|
+
assert_equal ['Dave Thomas', 'Chad Fowler', 'Andy Hunt'],
|
77
|
+
item.get_array("author")
|
99
78
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
79
|
+
# test get_hash
|
80
|
+
small_image = item.get_hash("smallimage")
|
81
|
+
|
82
|
+
assert_equal 3, small_image.keys.size
|
83
|
+
assert_match ".jpg", small_image[:url]
|
84
|
+
assert_equal "75", small_image[:height]
|
85
|
+
assert_equal "59", small_image[:width]
|
86
|
+
|
87
|
+
# test /
|
88
|
+
reviews = item/"editorialreview"
|
89
|
+
reviews.each do |review|
|
90
|
+
# returns unescaped HTML content, Hpricot escapes all text values
|
91
|
+
assert Amazon::Element.get_unescaped(review, 'source')
|
92
|
+
assert Amazon::Element.get_unescaped(review, 'content')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
## Test item_lookup
|
97
|
+
def test_item_lookup
|
98
|
+
resp = Amazon::Ecs.item_lookup('0974514055')
|
99
|
+
assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition",
|
100
|
+
resp.first_item.get("itemattributes/title")
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_item_lookup_with_invalid_request
|
104
|
+
resp = Amazon::Ecs.item_lookup(nil)
|
105
|
+
assert resp.has_error?
|
106
|
+
assert resp.error
|
107
|
+
end
|
112
108
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
109
|
+
def test_item_lookup_with_no_result
|
110
|
+
resp = Amazon::Ecs.item_lookup('abc')
|
111
|
+
|
112
|
+
assert resp.is_valid_request?
|
113
|
+
assert_match(/ABC is not a valid value for ItemId/, resp.error)
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_search_and_convert
|
117
|
+
resp = Amazon::Ecs.item_lookup('0974514055')
|
118
|
+
title = resp.first_item.get("itemattributes/title")
|
119
|
+
authors = resp.first_item.search_and_convert("author")
|
120
|
+
|
121
|
+
assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition", title
|
122
|
+
assert authors.is_a?(Array)
|
123
|
+
assert 3, authors.size
|
124
|
+
assert_equal "Dave Thomas", authors.first.get
|
125
|
+
end
|
126
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amazon-ecs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Herryanto Siatono
|
@@ -9,7 +9,7 @@ autorequire: name
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-28 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|