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.
Files changed (5) hide show
  1. data/CHANGELOG +4 -0
  2. data/README +1 -1
  3. data/lib/amazon/ecs.rb +19 -3
  4. data/test/amazon/ecs_test.rb +106 -101
  5. metadata +2 -2
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ 0.5.6 2009-07-21
2
+ ----------------
3
+ * Update parameter value encoding to support special characters
4
+
1
5
  0.5.5 2009-07-18
2
6
  ----------------
3
7
  * Sign request
data/README CHANGED
@@ -12,7 +12,7 @@ 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.5
15
+ Version: 0.5.6
16
16
 
17
17
  == INSTALLATION
18
18
 
@@ -205,14 +205,24 @@ module Amazon
205
205
  request_host = URI.parse(request_url).host
206
206
 
207
207
  qs = ''
208
- opts.collect {|a,b| [camelize(a.to_s), b.to_s] }.sort {|c,d| c[0].to_s <=> d[0].to_s}.each {|e|
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
@@ -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
- resp = Amazon::Ecs.item_search('ruby')
21
-
22
- assert(resp.is_valid_request?)
23
- assert(resp.total_results >= 3600)
24
- assert(resp.total_pages >= 360)
25
-
26
- signature_elements = (resp.doc/"arguments/argument").select {|ele| ele.attributes['name'] == 'Signature' }.length
27
- assert(signature_elements == 1)
28
- end
29
-
30
- def test_item_search_with_paging
31
- resp = Amazon::Ecs.item_search('ruby', :item_page => 2)
32
- assert resp.is_valid_request?
33
- assert 2, resp.item_page
34
- end
35
-
36
- def test_item_search_with_invalid_request
37
- resp = Amazon::Ecs.item_search(nil)
38
- assert !resp.is_valid_request?
39
- end
40
-
41
- def test_item_search_with_no_result
42
- resp = Amazon::Ecs.item_search('afdsafds')
43
-
44
- assert resp.is_valid_request?
45
- assert_equal "We did not find any matches for your request.",
46
- resp.error
47
- end
48
-
49
- def test_item_search_uk
50
- resp = Amazon::Ecs.item_search('ruby', :country => :uk)
51
- assert resp.is_valid_request?
52
- end
53
-
54
- def test_item_search_by_author
55
- resp = Amazon::Ecs.item_search('dave', :type => :author)
56
- assert resp.is_valid_request?
57
- end
58
-
59
- def test_item_get
60
- resp = Amazon::Ecs.item_search("0974514055")
61
- item = resp.first_item
62
-
63
- # test get
64
- assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition",
65
- item.get("itemattributes/title")
66
-
67
- # test get_array
68
- assert_equal ['Dave Thomas', 'Chad Fowler', 'Andy Hunt'],
69
- item.get_array("author")
70
-
71
- # test get_hash
72
- small_image = item.get_hash("smallimage")
73
-
74
- assert_equal 3, small_image.keys.size
75
- assert_match ".jpg", small_image[:url]
76
- assert_equal "75", small_image[:height]
77
- assert_equal "59", small_image[:width]
78
-
79
- # test /
80
- reviews = item/"editorialreview"
81
- reviews.each do |review|
82
- # returns unescaped HTML content, Hpricot escapes all text values
83
- assert Amazon::Element.get_unescaped(review, 'source')
84
- assert Amazon::Element.get_unescaped(review, 'content')
85
- end
86
- end
87
-
88
- ## Test item_lookup
89
- def test_item_lookup
90
- resp = Amazon::Ecs.item_lookup('0974514055')
91
- assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition",
92
- resp.first_item.get("itemattributes/title")
93
- end
94
-
95
- def test_item_lookup_with_invalid_request
96
- resp = Amazon::Ecs.item_lookup(nil)
97
- assert resp.has_error?
98
- assert resp.error
99
- end
100
-
101
- def test_item_lookup_with_no_result
102
- resp = Amazon::Ecs.item_lookup('abc')
103
-
104
- assert resp.is_valid_request?
105
- assert_match(/ABC is not a valid value for ItemId/, resp.error)
106
- end
107
-
108
- def test_search_and_convert
109
- resp = Amazon::Ecs.item_lookup('0974514055')
110
- title = resp.first_item.get("itemattributes/title")
111
- authors = resp.first_item.search_and_convert("author")
112
-
113
- assert_equal "Programming Ruby: The Pragmatic Programmers' Guide, Second Edition", title
114
- assert authors.is_a?(Array)
115
- assert 3, authors.size
116
- assert_equal "Dave Thomas", authors.first.get
117
- 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 {|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.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-18 00:00:00 +08:00
12
+ date: 2009-07-21 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency