ECS 0.1.6 → 0.1.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 +6 -0
- data/lib/ecs.rb +17 -0
- data/lib/ecs/errors.rb +39 -0
- data/lib/ecs/help.rb +5 -2
- data/test/unit/ecs/errors_test.rb +65 -0
- data/test/unit/ecs/help_test.rb +15 -1
- data/test/unit/ecs_test.rb +11 -0
- metadata +5 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
0.1.7
|
2
|
+
* Instead of RuntimeErrors, the classes for response errors from AWS are now generated dynamically.
|
3
|
+
The name of the dynamic class resembles the AWS error code, so code
|
4
|
+
AWS.ECommerceService.NoExactMatches becomes class ECS::AwseCommerceServiceNoExactMatches.
|
5
|
+
|
6
|
+
|
1
7
|
0.1.6
|
2
8
|
* Fixed bug #9482 (http://rubyforge.org/tracker/index.php?func=detail&aid=9482&group_id=3190&atid=12267)
|
3
9
|
* Fixed bug #9469 (http://rubyforge.org/tracker/index.php?func=detail&aid=9469&group_id=3190&atid=12267)
|
data/lib/ecs.rb
CHANGED
@@ -13,6 +13,7 @@ module ECS
|
|
13
13
|
Dir[File.join( File.dirname( __FILE__ ), "*.rb" )].each { |f| require f }
|
14
14
|
|
15
15
|
require File.join( File.dirname( __FILE__ ), 'ecs', 'operations' )
|
16
|
+
require File.join( File.dirname( __FILE__ ), 'ecs', 'errors' )
|
16
17
|
require File.join( File.dirname( __FILE__ ), 'ecs', 'response_groups' )
|
17
18
|
require File.join( File.dirname( __FILE__ ), 'ecs', 'help' )
|
18
19
|
require File.join( File.dirname( __FILE__ ), 'ecs', 'help_response_group' )
|
@@ -171,6 +172,7 @@ module ECS
|
|
171
172
|
#{klass_name}"
|
172
173
|
#puts string_to_eval
|
173
174
|
klass = instance_eval( string_to_eval, __FILE__, __LINE__ )
|
175
|
+
ECS::ResponseGroups[klass_name] = klass
|
174
176
|
end
|
175
177
|
klass
|
176
178
|
end
|
@@ -190,9 +192,24 @@ module ECS
|
|
190
192
|
#{klass_name}"
|
191
193
|
# puts string_to_eval
|
192
194
|
klass = instance_eval( string_to_eval, __FILE__, __LINE__ )
|
195
|
+
ECS::Operations[klass_name] = klass
|
193
196
|
end
|
194
197
|
klass
|
195
198
|
end
|
199
|
+
def self.resolve_error_klass( name='' )
|
200
|
+
klass_name = ECS::Help.resolve_error_name( name )
|
201
|
+
klass = ECS::Errors[klass_name]
|
202
|
+
if klass.nil?
|
203
|
+
string_to_eval = "class #{klass_name.to_s} < RuntimeError
|
204
|
+
end
|
205
|
+
#{klass_name}"
|
206
|
+
# puts string_to_eval
|
207
|
+
klass = eval( string_to_eval, binding, __FILE__, __LINE__ )
|
208
|
+
ECS::Errors[klass_name] = klass
|
209
|
+
end
|
210
|
+
klass
|
211
|
+
end
|
212
|
+
|
196
213
|
|
197
214
|
def self.xml_for_parameters( parameters={}, force=false )
|
198
215
|
# if you pass a block to this method, the XML::Document object
|
data/lib/ecs/errors.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
|
3
|
+
|
4
|
+
module ECS
|
5
|
+
class Errors
|
6
|
+
@@klasses = {}
|
7
|
+
|
8
|
+
def self.clear
|
9
|
+
@@klasses = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.[]=( ideal, actual )
|
13
|
+
self.clear unless @@klasses.is_a?( Hash )
|
14
|
+
@@klasses[( ideal.is_a?( Class ) ? ideal.name : ideal.to_s ).to_sym] = actual.is_a?( Class ) ? actual : actual.class
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.[]( ideal )
|
18
|
+
self.clear unless @@klasses.is_a?( Hash )
|
19
|
+
@@klasses[( ideal.is_a?( Class ) ? ideal.name : ideal.to_s ).to_sym]
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.method_missing( meth, *args )
|
23
|
+
#You can send anything to ECS::Errors that you can send to a hash
|
24
|
+
#If there is a conflict between the hash's (@@klasses) method name and
|
25
|
+
#the ECS::Errors module's method name, you can call the method with o_ prepended
|
26
|
+
#
|
27
|
+
# E.G.
|
28
|
+
#
|
29
|
+
# ECS::Errors.include?( something ) # => calls the include? method on ECS::Errors
|
30
|
+
# ECS::Errors.o_include?( something ) # => calls the include? method on the @@klasses class variable
|
31
|
+
@@klasses = {} unless @@klasses.is_a?( Hash )
|
32
|
+
if meth == :each
|
33
|
+
@@klasses.each { |ideal,actual| yield( ideal, actual ) }
|
34
|
+
else
|
35
|
+
@@klasses.send( (meth.to_s =~ /^o_(.*)/ ? $1.to_sym : meth), *args )
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/ecs/help.rb
CHANGED
@@ -60,8 +60,8 @@ module ECS
|
|
60
60
|
xml.find( '//Errors/Error' ).each do |error_node|
|
61
61
|
begin
|
62
62
|
m = error_node.Message.content
|
63
|
-
c = error_node.Code.content
|
64
|
-
errors <<
|
63
|
+
c = ECS.resolve_error_klass( error_node.Code.content )
|
64
|
+
errors << c.new( m )
|
65
65
|
rescue Exception => e
|
66
66
|
end
|
67
67
|
end
|
@@ -112,6 +112,9 @@ module ECS
|
|
112
112
|
@available_response_groups
|
113
113
|
end
|
114
114
|
|
115
|
+
def self.resolve_error_name( t )
|
116
|
+
t.gsub( /[\.\s:]+/, '' ).camel_case
|
117
|
+
end
|
115
118
|
|
116
119
|
def self.resolve_operation_name( t )
|
117
120
|
t =~ /::([^:]*)$/ ? $1 : t
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require "#{File.expand_path( File.dirname( __FILE__ ) )}/../unit_test_setup"
|
5
|
+
|
6
|
+
class ECSErrorsTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@@initial_errors = {} ; ECS::Errors.each { |ideal,actual| @@initial_errors[ideal] = actual }
|
9
|
+
ECS::Errors.clear
|
10
|
+
end
|
11
|
+
def teardown
|
12
|
+
@@initial_errors.each { |ideal,actual| ECS::Errors[ideal] = actual }
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_exists
|
16
|
+
assert_nothing_raised do
|
17
|
+
ECS::Errors
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_add
|
23
|
+
assert_equal nil, ECS::Errors[:AKlass]
|
24
|
+
assert_nothing_raised do
|
25
|
+
ECS::Errors['AKlass'] = Fixnum
|
26
|
+
end
|
27
|
+
assert_equal Fixnum, ECS::Errors[:AKlass]
|
28
|
+
assert_equal Fixnum, ECS::Errors['AKlass']
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def test_clear
|
33
|
+
assert_equal 0, ECS::Errors.size
|
34
|
+
ECS::Errors['A'] = Fixnum
|
35
|
+
ECS::Errors['B'] = String
|
36
|
+
ECS::Errors['C'] = File
|
37
|
+
|
38
|
+
assert_equal 3, ECS::Errors.size
|
39
|
+
assert_nothing_raised do
|
40
|
+
ECS::Errors.clear
|
41
|
+
end
|
42
|
+
assert_equal 0, ECS::Errors.size
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_each
|
46
|
+
ECS::Errors['A'] = Fixnum
|
47
|
+
ECS::Errors['B'] = String
|
48
|
+
ECS::Errors['C'] = File
|
49
|
+
assert_equal 3, ECS::Errors.size
|
50
|
+
ECS::Errors.each do |ideal,actual|
|
51
|
+
assert [ :A, :B, :C ].include?( ideal )
|
52
|
+
assert_equal Class, actual.class
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def test_actual_class
|
58
|
+
ECS::Errors['A'] = "Fixnum"
|
59
|
+
assert_equal String, ECS::Errors[:A]
|
60
|
+
assert_equal String, ECS::Errors['A']
|
61
|
+
|
62
|
+
ECS::Errors['A'] = Fixnum
|
63
|
+
assert_equal Fixnum, ECS::Errors['A']
|
64
|
+
end
|
65
|
+
end
|
data/test/unit/ecs/help_test.rb
CHANGED
@@ -99,6 +99,14 @@ class ECSBrowseNodeLookupTest < Test::Unit::TestCase
|
|
99
99
|
|
100
100
|
end
|
101
101
|
|
102
|
+
def test_resolve_operation_name
|
103
|
+
assert_equal 'CrazyClass', ECS::Help.resolve_operation_name( 'Some::CrazyClass' )
|
104
|
+
end
|
105
|
+
def test_resolve_error_name
|
106
|
+
assert_equal 'AwsInternalError', ECS::Help.resolve_error_name( 'AWS.InternalError' )
|
107
|
+
end
|
108
|
+
|
109
|
+
|
102
110
|
def test_subclass
|
103
111
|
h = ECS.help( :HelpType => 'Operation', :About => 'BrowseNodeLookup' )
|
104
112
|
b = ECS.browse_node_lookup( :BrowseNodeId => 23 )
|
@@ -574,7 +582,8 @@ class ECSBrowseNodeLookupTest < Test::Unit::TestCase
|
|
574
582
|
def test_errors
|
575
583
|
h = ECS.something_ridiculous
|
576
584
|
assert_equal 1, h.errors.size
|
577
|
-
|
585
|
+
assert h.errors.first.class.ancestors.include?( RuntimeError )
|
586
|
+
assert_equal ECS::AwsInvalidOperationParameter, h.errors.first.class
|
578
587
|
assert_match /^The Operation parameter is invalid\. Please modify the Operation parameter and retry\. Valid values for the Operation parameter/, h.errors.first.message
|
579
588
|
|
580
589
|
h = ECS.help( :HelpType => 'Operation' )
|
@@ -584,6 +593,11 @@ class ECSBrowseNodeLookupTest < Test::Unit::TestCase
|
|
584
593
|
|
585
594
|
h = ECS.help( :HelpType => 'Operation', :About => 'BrowseNodeLookup' )
|
586
595
|
assert_equal 0, h.errors.size
|
596
|
+
|
597
|
+
|
598
|
+
h = ECS.search_Books_by_Author( 'veli matti karkainnen' )
|
599
|
+
assert_equal 1, h.errors.size
|
600
|
+
assert_equal ECS::AwseCommerceServiceNoExactMatches, h.errors.first.class
|
587
601
|
end
|
588
602
|
|
589
603
|
|
data/test/unit/ecs_test.rb
CHANGED
@@ -399,6 +399,17 @@ class ECSTest < Test::Unit::TestCase
|
|
399
399
|
assert_equal Class, ECS::Operations[:Stinky].class
|
400
400
|
assert_equal klass, ECS::Operations[:Stinky]
|
401
401
|
end
|
402
|
+
def test_resolve_error_klass
|
403
|
+
assert_equal NilClass, ECS::Errors[:Stinky].class
|
404
|
+
klass = nil
|
405
|
+
assert_nothing_raised do
|
406
|
+
klass = ECS.resolve_error_klass( 'StinkyError' )
|
407
|
+
end
|
408
|
+
assert !klass.nil?
|
409
|
+
assert_equal Class, klass.class
|
410
|
+
assert_equal Class, ECS::Errors[:StinkyError].class
|
411
|
+
assert_equal klass, ECS::Errors[:StinkyError]
|
412
|
+
end
|
402
413
|
|
403
414
|
|
404
415
|
def test_api_version
|
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-
|
6
|
+
version: 0.1.7
|
7
|
+
date: 2007-04-10 00:00:00 -07:00
|
8
8
|
summary: A Ruby interface to Amazon's E-Commerce Service.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -32,6 +32,7 @@ files:
|
|
32
32
|
- lib/ecs.rb
|
33
33
|
- lib/libxml_additions.rb
|
34
34
|
- lib/string_additions.rb
|
35
|
+
- lib/ecs/errors.rb
|
35
36
|
- lib/ecs/help.rb
|
36
37
|
- lib/ecs/help_response_group.rb
|
37
38
|
- lib/ecs/operations.rb
|
@@ -42,6 +43,7 @@ files:
|
|
42
43
|
- test/unit/libxml_additions_test.rb
|
43
44
|
- test/unit/string_additions_test.rb
|
44
45
|
- test/unit/unit_test_setup.rb
|
46
|
+
- test/unit/ecs/errors_test.rb
|
45
47
|
- test/unit/ecs/help_response_group_test.rb
|
46
48
|
- test/unit/ecs/help_test.rb
|
47
49
|
- test/unit/ecs/operations_test.rb
|
@@ -57,6 +59,7 @@ test_files:
|
|
57
59
|
- test/unit/libxml_additions_test.rb
|
58
60
|
- test/unit/string_additions_test.rb
|
59
61
|
- test/unit/unit_test_setup.rb
|
62
|
+
- test/unit/ecs/errors_test.rb
|
60
63
|
- test/unit/ecs/help_response_group_test.rb
|
61
64
|
- test/unit/ecs/help_test.rb
|
62
65
|
- test/unit/ecs/operations_test.rb
|