em-amazon-sqs 0.1.0
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.md +23 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +18 -0
- data/LICENSE +20 -0
- data/README.md +284 -0
- data/Rakefile +57 -0
- data/TODO.md +2 -0
- data/VERSION +1 -0
- data/example/client.rb +22 -0
- data/example/server.rb +27 -0
- data/lib/simple_qs.rb +41 -0
- data/lib/simple_qs/message.rb +135 -0
- data/lib/simple_qs/queue.rb +298 -0
- data/lib/simple_qs/request.rb +24 -0
- data/lib/simple_qs/request/base.rb +105 -0
- data/lib/simple_qs/request/get.rb +14 -0
- data/lib/simple_qs/request/post.rb +14 -0
- data/lib/simple_qs/responce.rb +30 -0
- data/lib/simple_qs/responce/exceptions.rb +39 -0
- data/lib/simple_qs/responce/failure_builder.rb +33 -0
- data/lib/simple_qs/responce/successful_builder.rb +26 -0
- data/lib/version.rb +3 -0
- data/simple_qs.gemspec +24 -0
- data/spec/simple_qs/message_spec.rb +114 -0
- data/spec/simple_qs/queue_spec.rb +145 -0
- data/spec/simple_qs/request_spec.rb +56 -0
- data/spec/simple_qs/responce_spec.rb +118 -0
- data/spec/simple_qs_spec.rb +36 -0
- data/spec/spec_helper.rb +12 -0
- metadata +170 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module SimpleQS
|
4
|
+
describe Request do
|
5
|
+
before :each do
|
6
|
+
@query_params = {
|
7
|
+
'Action' => 'SetQueueAttributes',
|
8
|
+
'Attribute.Name' => 'VisibilityTimeout',
|
9
|
+
'Attribute.Value' => 90,
|
10
|
+
'Expires' => '2008-02-10T12:00:00Z'
|
11
|
+
}
|
12
|
+
|
13
|
+
@get_request = SimpleQS::Request::Get.new(@query_params)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should raise error if object passed to timestampt is not of Time kind' do
|
17
|
+
lambda {
|
18
|
+
@get_request.timestamp = '10-10-2010'
|
19
|
+
}.should raise_error(ArgumentError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should build correct request' do
|
23
|
+
SimpleQS::Request.build(:get, @query_params).should == @get_request
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should raise SimpleQS::Request::UnknownHttpMethod if unknown method passed' do
|
27
|
+
lambda {
|
28
|
+
SimpleQS::Request.build(:head, @query_params)
|
29
|
+
}.should raise_error(SimpleQS::Request::UnknownHttpMethod)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should generate correct canonicalized query string' do
|
33
|
+
@get_request.canonical_query_string.should == "AWSAccessKeyId=#{SimpleQS.access_key_id}&Action=SetQueueAttributes&Attribute.Name=VisibilityTimeout&Attribute.Value=90&Expires=2008-02-10T12%3A00%3A00Z&SignatureMethod=HmacSHA1&SignatureVersion=2&Version=2009-02-01"
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should generate correct base string' do
|
37
|
+
@get_request.query_string = '/770098461991/queue2'
|
38
|
+
@get_request.signature_base_string.should == "GET\n#{SimpleQS.host}\n/770098461991/queue2\nAWSAccessKeyId=#{SimpleQS.access_key_id}&Action=SetQueueAttributes&Attribute.Name=VisibilityTimeout&Attribute.Value=90&Expires=2008-02-10T12%3A00%3A00Z&SignatureMethod=HmacSHA1&SignatureVersion=2&Version=2009-02-01"
|
39
|
+
|
40
|
+
@get_request.query_string = '770098461991/queue2'
|
41
|
+
@get_request.signature_base_string.should == "GET\n#{SimpleQS.host}\n/770098461991/queue2\nAWSAccessKeyId=#{SimpleQS.access_key_id}&Action=SetQueueAttributes&Attribute.Name=VisibilityTimeout&Attribute.Value=90&Expires=2008-02-10T12%3A00%3A00Z&SignatureMethod=HmacSHA1&SignatureVersion=2&Version=2009-02-01"
|
42
|
+
|
43
|
+
@get_request.query_string = ['770098461991', 'queue2']
|
44
|
+
@get_request.signature_base_string.should == "GET\n#{SimpleQS.host}\n/770098461991/queue2\nAWSAccessKeyId=#{SimpleQS.access_key_id}&Action=SetQueueAttributes&Attribute.Name=VisibilityTimeout&Attribute.Value=90&Expires=2008-02-10T12%3A00%3A00Z&SignatureMethod=HmacSHA1&SignatureVersion=2&Version=2009-02-01"
|
45
|
+
|
46
|
+
@get_request.query_string = nil
|
47
|
+
@get_request.signature_base_string.should == "GET\n#{SimpleQS.host}\n/\nAWSAccessKeyId=#{SimpleQS.access_key_id}&Action=SetQueueAttributes&Attribute.Name=VisibilityTimeout&Attribute.Value=90&Expires=2008-02-10T12%3A00%3A00Z&SignatureMethod=HmacSHA1&SignatureVersion=2&Version=2009-02-01"
|
48
|
+
end
|
49
|
+
|
50
|
+
it '#sign! should generate signature from base string' do
|
51
|
+
@get_request.query_string = ['770098461991', 'queue2']
|
52
|
+
@get_request.sign!
|
53
|
+
@get_request.query_params['Signature'].should_not be_empty
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ResponceHelper
|
4
|
+
def successful_responce
|
5
|
+
responce_xml = %{
|
6
|
+
<CreateQueueResponse
|
7
|
+
xmlns="http://queue.amazonaws.com/doc/2009-02-01/"
|
8
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
9
|
+
xsi:type="CreateQueueResponse">
|
10
|
+
|
11
|
+
<CreateQueueResult>
|
12
|
+
<QueueUrl>http://queue.amazonaws.com/770098461991/queue2</QueueUrl>
|
13
|
+
</CreateQueueResult>
|
14
|
+
<ResponseMetadata>
|
15
|
+
<RequestId>cb919c0a-9bce-4afe-9b48-9bdf2412bb67</RequestId>
|
16
|
+
</ResponseMetadata>
|
17
|
+
|
18
|
+
</CreateQueueResponse>
|
19
|
+
}
|
20
|
+
|
21
|
+
SimpleQS::Responce.new responce_xml
|
22
|
+
end
|
23
|
+
|
24
|
+
def failure_responce
|
25
|
+
responce_xml = %{
|
26
|
+
<ErrorResponse>
|
27
|
+
<Error>
|
28
|
+
<Type>Sender</Type>
|
29
|
+
<Code>InvalidParameterValue</Code>
|
30
|
+
<Message>Value (quename_nonalpha) for parameter QueueName is invalid. Must be an alphanumeric String of 1 to 80 in length</Message>
|
31
|
+
</Error>
|
32
|
+
<RequestId>42d59b56-7407-4c4a-be0f-4c88daeea257</RequestId>
|
33
|
+
</ErrorResponse>
|
34
|
+
}
|
35
|
+
|
36
|
+
SimpleQS::Responce.new responce_xml
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module SimpleQS
|
41
|
+
describe Responce do
|
42
|
+
describe 'when request is successful' do
|
43
|
+
|
44
|
+
include ResponceHelper
|
45
|
+
|
46
|
+
before :each do
|
47
|
+
@responce = successful_responce
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should be successful' do
|
51
|
+
@responce.should be_successful
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should have request id' do
|
55
|
+
@responce.request_id.should == 'cb919c0a-9bce-4afe-9b48-9bdf2412bb67'
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should have action name' do
|
59
|
+
@responce.action_name.should == 'CreateQueue'
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should have action specific responce values' do
|
63
|
+
@responce.queue_url.should == 'http://queue.amazonaws.com/770098461991/queue2'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'when request is unsuccessful' do
|
68
|
+
|
69
|
+
include ResponceHelper
|
70
|
+
|
71
|
+
before :each do
|
72
|
+
@responce = failure_responce
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should not be successful' do
|
76
|
+
@responce.should_not be_successful
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should be sender error' do
|
80
|
+
@responce.should be_sender_error
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should have request id' do
|
84
|
+
@responce.request_id.should == '42d59b56-7407-4c4a-be0f-4c88daeea257'
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should not be receiver error' do
|
88
|
+
@responce.should_not be_receiver_error
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should have error code' do
|
92
|
+
@responce.error_code.should == 'InvalidParameterValue'
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should have error message' do
|
96
|
+
@responce.error_message.should == "Value (quename_nonalpha) for parameter QueueName is invalid. Must be an alphanumeric String of 1 to 80 in length"
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'when error is returned' do
|
100
|
+
it 'should be valid error instance' do
|
101
|
+
@responce.to_error.should be_instance_of(SimpleQS::Responce::InvalidParameterValueError)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should contain valid message' do
|
105
|
+
@responce.to_error.message.should == @responce.error_message
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
include ResponceHelper
|
111
|
+
|
112
|
+
it 'should define singleton methods for each instance' do
|
113
|
+
success = successful_responce
|
114
|
+
failure = failure_responce
|
115
|
+
success.request_id.should_not == failure.request_id
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe SimpleQS do
|
3
|
+
it 'should be able to set and retrieve access key id' do
|
4
|
+
SimpleQS.access_key_id = ENV['AWS_ACCESS_KEY_ID']
|
5
|
+
SimpleQS.access_key_id.should == ENV['AWS_ACCESS_KEY_ID']
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should be able to set and retrieve secret access key' do
|
9
|
+
SimpleQS.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
|
10
|
+
SimpleQS.secret_access_key.should == ENV['AWS_SECRET_ACCESS_KEY']
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should be able to set and retrieve account id' do
|
14
|
+
SimpleQS.account_id = ENV['AWS_ACCOUNT_ID']
|
15
|
+
SimpleQS.account_id.should == ENV['AWS_ACCOUNT_ID'].gsub(/[^0-9]/, '')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should have default host' do
|
19
|
+
SimpleQS.host.should == 'sqs.us-east-1.amazonaws.com'
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should return valid us-west-1 host' do
|
23
|
+
SimpleQS.host = :us_west_1
|
24
|
+
SimpleQS.host.should == 'sqs.us-west-1.amazonaws.com'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should return valid eu-west-1 host' do
|
28
|
+
SimpleQS.host = :eu_west_1
|
29
|
+
SimpleQS.host.should == 'sqs.eu-west-1.amazonaws.com'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should return valid ap-southeast-1 host' do
|
33
|
+
SimpleQS.host = :ap_southeast_1
|
34
|
+
SimpleQS.host.should == 'sqs.ap-southeast-1.amazonaws.com'
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
2
|
+
require 'rubygems'
|
3
|
+
require 'spec'
|
4
|
+
require 'lib/simple_qs'
|
5
|
+
|
6
|
+
unless ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY'] && ENV['AWS_ACCOUNT_ID']
|
7
|
+
abort "Please set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_ACCOUNT_ID environment variables"
|
8
|
+
end
|
9
|
+
|
10
|
+
SimpleQS.access_key_id = ENV['AWS_ACCESS_KEY_ID']
|
11
|
+
SimpleQS.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
|
12
|
+
SimpleQS.account_id = ENV['AWS_ACCOUNT_ID']
|
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: em-amazon-sqs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- jeff durand
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-12 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ruby-hmac
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: xml-simple
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: em-http-request
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: addressable
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: xml-simple
|
61
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
type: :runtime
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: em-http-request
|
72
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
type: :runtime
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: addressable
|
83
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "0"
|
89
|
+
type: :runtime
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *id007
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: ruby-hmac
|
94
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "0"
|
100
|
+
type: :runtime
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: *id008
|
103
|
+
description: "Async amazon simple queue service "
|
104
|
+
email: jeff.durand@gmail.com
|
105
|
+
executables: []
|
106
|
+
|
107
|
+
extensions: []
|
108
|
+
|
109
|
+
extra_rdoc_files:
|
110
|
+
- LICENSE
|
111
|
+
- README.md
|
112
|
+
files:
|
113
|
+
- CHANGELOG.md
|
114
|
+
- Gemfile
|
115
|
+
- Gemfile.lock
|
116
|
+
- LICENSE
|
117
|
+
- README.md
|
118
|
+
- Rakefile
|
119
|
+
- TODO.md
|
120
|
+
- VERSION
|
121
|
+
- example/client.rb
|
122
|
+
- example/server.rb
|
123
|
+
- lib/simple_qs.rb
|
124
|
+
- lib/simple_qs/message.rb
|
125
|
+
- lib/simple_qs/queue.rb
|
126
|
+
- lib/simple_qs/request.rb
|
127
|
+
- lib/simple_qs/request/base.rb
|
128
|
+
- lib/simple_qs/request/get.rb
|
129
|
+
- lib/simple_qs/request/post.rb
|
130
|
+
- lib/simple_qs/responce.rb
|
131
|
+
- lib/simple_qs/responce/exceptions.rb
|
132
|
+
- lib/simple_qs/responce/failure_builder.rb
|
133
|
+
- lib/simple_qs/responce/successful_builder.rb
|
134
|
+
- lib/version.rb
|
135
|
+
- simple_qs.gemspec
|
136
|
+
- spec/simple_qs/message_spec.rb
|
137
|
+
- spec/simple_qs/queue_spec.rb
|
138
|
+
- spec/simple_qs/request_spec.rb
|
139
|
+
- spec/simple_qs/responce_spec.rb
|
140
|
+
- spec/simple_qs_spec.rb
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
homepage: https://github.com/johnnyiller/SimpleQS
|
143
|
+
licenses: []
|
144
|
+
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: "0"
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
none: false
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: "0"
|
162
|
+
requirements: []
|
163
|
+
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 1.7.2
|
166
|
+
signing_key:
|
167
|
+
specification_version: 3
|
168
|
+
summary: Asyncronous amazon simple queue service
|
169
|
+
test_files: []
|
170
|
+
|