ECS 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/lib/ecs.rb +24 -10
- data/test/unit/ecs_test.rb +42 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
0.1.1
|
2
|
+
* Forces ECS API version 2007-02-22
|
3
|
+
* Modified ECS.method_missing to understand methods like ECS.search_INDEX_by_PARAMETER
|
4
|
+
This means you can do ECS.search_DVD_by_Actor( 'Carrot Top' )
|
5
|
+
or ECS.search_Books_by_Title( 'Microserfs' )
|
6
|
+
* Added ECS.counter to track calls to the web service
|
7
|
+
|
8
|
+
|
1
9
|
0.1.0
|
2
10
|
* Initial release
|
3
11
|
* Forces ECS API version 2007-01-17
|
data/lib/ecs.rb
CHANGED
@@ -29,6 +29,7 @@ module ECS
|
|
29
29
|
@@cache_directory = ''
|
30
30
|
@@cache = true
|
31
31
|
@@cache_suffix = 'ecs_cache'
|
32
|
+
@@counter = 0
|
32
33
|
|
33
34
|
# libxml-ruby is not able to do XML::Document#find or XML::Node#find with xml returned from Amazon.
|
34
35
|
# If you remove the namespace from the xml, it works perfectly
|
@@ -36,22 +37,23 @@ module ECS
|
|
36
37
|
|
37
38
|
def self.method_missing( meth, *args )
|
38
39
|
meth_s = meth.to_s
|
40
|
+
a = *args
|
39
41
|
begin
|
40
42
|
klass_name = meth_s.camel_case
|
41
43
|
instance = nil
|
42
|
-
|
44
|
+
case meth_s
|
45
|
+
when /^(.*)_response_group$/
|
43
46
|
instance = self.resolve_response_group_klass( klass_name )
|
47
|
+
when /^search_([^_]*)_by_([^_]*)$/
|
48
|
+
# Allow things like ECS.search_Books_by_Author( 'Marcus Aurelius' )
|
49
|
+
params = { :SearchIndex => $1 }.merge( a.is_a?( Hash ) ? a : { $2.to_sym => a } )
|
50
|
+
instance = self.item_search( params )
|
44
51
|
else
|
45
52
|
klass = self.resolve_operation_klass( klass_name )
|
46
|
-
|
47
|
-
# string_to_eval = "#{klass_name}.new"
|
48
|
-
# puts "Now going to #{string_to_eval}"
|
49
53
|
instance = klass.new
|
50
|
-
|
51
|
-
instance.parameters = *args
|
52
|
-
instance.parameters = {} unless instance.parameters.is_a?( Hash )
|
54
|
+
instance.parameters = a.is_a?( Hash ) ? a : {}
|
53
55
|
|
54
|
-
# If no
|
56
|
+
# If no ResponseGroup is set, then allow the defaults
|
55
57
|
unless instance.parameters[:ResponseGroup].nil?
|
56
58
|
# Otherwise, be sure :Request is included
|
57
59
|
instance.parameters[:ResponseGroup] = [instance.parameters[:ResponseGroup]] unless instance.parameters[:ResponseGroup].is_a?( Array )
|
@@ -63,8 +65,18 @@ module ECS
|
|
63
65
|
raise NameError, "#{e.message}"#Are you sure that ECS::#{klass_name} is defined?"
|
64
66
|
end
|
65
67
|
end
|
66
|
-
|
67
|
-
|
68
|
+
|
69
|
+
|
70
|
+
def self.counter
|
71
|
+
@@counter
|
72
|
+
end
|
73
|
+
def self.reset_counter
|
74
|
+
@@counter = 0
|
75
|
+
end
|
76
|
+
def self.increment_counter
|
77
|
+
@@counter += 1
|
78
|
+
end
|
79
|
+
|
68
80
|
def self.associate_id
|
69
81
|
@@associate_id
|
70
82
|
end
|
@@ -133,6 +145,7 @@ module ECS
|
|
133
145
|
parameters.delete( :locale )
|
134
146
|
|
135
147
|
sleep( ECS::TimeManagement.sleep_duration )
|
148
|
+
self.increment_counter
|
136
149
|
url = "#{ self.base_urls[locale] }&AWSAccessKeyId=#{self.access_key_id}&Version=#{self.api_version}&AssociateTag=#{self.associate_id}&#{ parameters.keys.map{ |k| "#{ERB::Util.url_encode( k.to_s ) }=#{ERB::Util.url_encode( parameters[k].is_a?( Array ) ? parameters[k].join( ',' ) : parameters[k].to_s )}" }.join( '&' ) }"
|
137
150
|
#puts url
|
138
151
|
r = Net::HTTP.get_response( URI.parse( url ) )
|
@@ -240,6 +253,7 @@ module ECS
|
|
240
253
|
def self.resolve_cache_tag( p={} )
|
241
254
|
"#{cache_directory}/#{Digest::MD5.hexdigest( p.is_a?( String ) ? p : query_string( p ) )}.#{@@cache_suffix}"
|
242
255
|
end
|
256
|
+
|
243
257
|
end
|
244
258
|
|
245
259
|
##At this point I can do
|
data/test/unit/ecs_test.rb
CHANGED
@@ -230,6 +230,27 @@ class ECSTest < Test::Unit::TestCase
|
|
230
230
|
assert_equal '', ECS.query_string( 'c=d&a=b' )
|
231
231
|
end
|
232
232
|
|
233
|
+
|
234
|
+
def test_counter
|
235
|
+
initial_counter = ECS.counter
|
236
|
+
assert ECS.reset_counter
|
237
|
+
assert_equal 0, ECS.counter
|
238
|
+
|
239
|
+
(1..10).to_a.each do |i|
|
240
|
+
assert ECS.increment_counter
|
241
|
+
end
|
242
|
+
assert_equal 10, ECS.counter
|
243
|
+
assert ECS.reset_counter
|
244
|
+
assert_equal 0, ECS.counter
|
245
|
+
|
246
|
+
while ECS.counter < initial_counter do
|
247
|
+
ECS.increment_counter
|
248
|
+
end
|
249
|
+
assert_equal initial_counter, ECS.counter
|
250
|
+
end
|
251
|
+
|
252
|
+
|
253
|
+
|
233
254
|
def test_call_web_service
|
234
255
|
sleep 1 #make sure we don't need to sleep
|
235
256
|
time_1 = time_2 = time_3 = nil
|
@@ -357,6 +378,27 @@ class ECSTest < Test::Unit::TestCase
|
|
357
378
|
def test_api_version
|
358
379
|
assert_equal '2007-02-22', ECS.api_version
|
359
380
|
end
|
381
|
+
|
382
|
+
|
383
|
+
def test_index_type_search
|
384
|
+
search_results = ECS.search_Books_by_Author( 'Steven King' )
|
385
|
+
|
386
|
+
assert_equal 10, search_results.Item.size
|
387
|
+
assert_equal 0, search_results.errors.size
|
388
|
+
first_title = search_results.Item.first.ItemAttributes.Title.content
|
389
|
+
|
390
|
+
search_results = ECS.search_Books_by_Author( :Author => 'Steven King', :locale => :uk )
|
391
|
+
|
392
|
+
assert_equal 10, search_results.Item.size
|
393
|
+
assert_equal 0, search_results.errors.size
|
394
|
+
assert_not_equal first_title, search_results.Item.first.ItemAttributes.Title.content
|
395
|
+
|
396
|
+
search_results = ECS.search_DVD_by_Title( "James Bond" )
|
397
|
+
assert_equal 10, search_results.Item.size
|
398
|
+
|
399
|
+
search_results = ECS.search_Music_by_Artist( "U2" )
|
400
|
+
assert_equal 10, search_results.Item.size
|
401
|
+
end
|
360
402
|
end
|
361
403
|
|
362
404
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ECS
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-03-
|
6
|
+
version: 0.1.1
|
7
|
+
date: 2007-03-12 00:00:00 -07:00
|
8
8
|
summary: A Ruby interface to Amazon's E-Commerce Service.
|
9
9
|
require_paths:
|
10
10
|
- lib
|