amazon-ecs 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/README +1 -1
- data/lib/amazon/ecs.rb +19 -3
- data/test/amazon/ecs_test.rb +106 -101
- metadata +2 -2
data/CHANGELOG
CHANGED
data/README
CHANGED
data/lib/amazon/ecs.rb
CHANGED
@@ -205,14 +205,24 @@ module Amazon
|
|
205
205
|
request_host = URI.parse(request_url).host
|
206
206
|
|
207
207
|
qs = ''
|
208
|
-
|
208
|
+
|
209
|
+
opts = opts.collect do |a,b|
|
210
|
+
[camelize(a.to_s), b.to_s]
|
211
|
+
end
|
212
|
+
|
213
|
+
opts = opts.sort do |c,d|
|
214
|
+
c[0].to_s <=> d[0].to_s
|
215
|
+
end
|
216
|
+
|
217
|
+
opts.each do |e|
|
209
218
|
log "Adding #{e[0]}=#{e[1]}"
|
210
219
|
next unless e[1]
|
211
220
|
e[1] = e[1].join(',') if e[1].is_a? Array
|
212
|
-
v=URI.encode(e[1].to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
221
|
+
# v = URI.encode(e[1].to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
222
|
+
v = self.url_encode(e[1].to_s)
|
213
223
|
qs << "&" unless qs.length == 0
|
214
224
|
qs << "#{e[0]}=#{v}"
|
215
|
-
|
225
|
+
end
|
216
226
|
|
217
227
|
signature = ''
|
218
228
|
unless secret_key.nil?
|
@@ -223,6 +233,12 @@ module Amazon
|
|
223
233
|
"#{request_url}#{qs}#{signature}"
|
224
234
|
end
|
225
235
|
|
236
|
+
def self.url_encode(string)
|
237
|
+
string.gsub( /([^a-zA-Z0-9_.~-]+)/ ) do
|
238
|
+
'%' + $1.unpack( 'H2' * $1.size ).join( '%' ).upcase
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
226
242
|
def self.camelize(s)
|
227
243
|
s.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
228
244
|
end
|
data/test/amazon/ecs_test.rb
CHANGED
@@ -2,8 +2,8 @@ require File.dirname(__FILE__) + '/../test_helper'
|
|
2
2
|
|
3
3
|
class Amazon::EcsTest < Test::Unit::TestCase
|
4
4
|
|
5
|
-
AWS_ACCESS_KEY_ID = ''
|
6
|
-
AWS_SECRET_KEY = ''
|
5
|
+
AWS_ACCESS_KEY_ID = '0XQXXC6YV2C85DX1BF02'
|
6
|
+
AWS_SECRET_KEY = 'fwLOn0Y/IUXEM8Hk49o7QJV+ryOscbhXRb6CmA5l'
|
7
7
|
|
8
8
|
raise "Please specify set your AWS_ACCESS_KEY_ID" if AWS_ACCESS_KEY_ID.empty?
|
9
9
|
raise "Please specify set your AWS_SECRET_KEY" if AWS_SECRET_KEY.empty?
|
@@ -15,104 +15,109 @@ class Amazon::EcsTest < Test::Unit::TestCase
|
|
15
15
|
end
|
16
16
|
|
17
17
|
## Test item_search
|
18
|
-
|
19
18
|
def test_item_search
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
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 {|ele| ele.attributes['name'] == 'Signature' }.length
|
26
|
+
assert(signature_elements == 1)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_item_search_with_special_characters
|
30
|
+
Amazon::Ecs.debug = true
|
31
|
+
resp = Amazon::Ecs.item_search('()*&^%$')
|
32
|
+
assert(resp.is_valid_request?)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_item_search_with_paging
|
36
|
+
resp = Amazon::Ecs.item_search('ruby', :item_page => 2)
|
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
|
58
|
+
|
59
|
+
def test_item_search_by_author
|
60
|
+
resp = Amazon::Ecs.item_search('dave', :type => :author)
|
61
|
+
assert resp.is_valid_request?
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_item_get
|
65
|
+
resp = Amazon::Ecs.item_search("0974514055")
|
66
|
+
item = resp.first_item
|
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
|
92
|
+
|
93
|
+
## Test item_lookup
|
94
|
+
def test_item_lookup
|
95
|
+
resp = Amazon::Ecs.item_lookup('0974514055')
|
96
|
+
assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition",
|
97
|
+
resp.first_item.get("itemattributes/title")
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_item_lookup_with_invalid_request
|
101
|
+
resp = Amazon::Ecs.item_lookup(nil)
|
102
|
+
assert resp.has_error?
|
103
|
+
assert resp.error
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_item_lookup_with_no_result
|
107
|
+
resp = Amazon::Ecs.item_lookup('abc')
|
108
|
+
|
109
|
+
assert resp.is_valid_request?
|
110
|
+
assert_match(/ABC is not a valid value for ItemId/, resp.error)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_search_and_convert
|
114
|
+
resp = Amazon::Ecs.item_lookup('0974514055')
|
115
|
+
title = resp.first_item.get("itemattributes/title")
|
116
|
+
authors = resp.first_item.search_and_convert("author")
|
117
|
+
|
118
|
+
assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition", title
|
119
|
+
assert authors.is_a?(Array)
|
120
|
+
assert 3, authors.size
|
121
|
+
assert_equal "Dave Thomas", authors.first.get
|
122
|
+
end
|
118
123
|
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.6
|
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-07-
|
12
|
+
date: 2009-07-21 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|