mitchellh-rsqs 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +30 -0
- data/README.textile +81 -0
- data/Rakefile +4 -0
- data/lib/rsqs.rb +10 -0
- data/lib/rsqs/exception.rb +11 -0
- data/lib/rsqs/message.rb +17 -0
- data/lib/rsqs/queue.rb +49 -0
- data/lib/rsqs/request.rb +71 -0
- data/lib/rsqs/version.rb +9 -0
- data/rsqs.gemspec +17 -0
- metadata +66 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.textile
|
5
|
+
Rakefile
|
6
|
+
config/hoe.rb
|
7
|
+
config/requirements.rb
|
8
|
+
lib/rsqs.rb
|
9
|
+
lib/rsqs/version.rb
|
10
|
+
lib/rsqs/request.rb
|
11
|
+
lib/rsqs/queue.rb
|
12
|
+
lib/rsqs/message.rb
|
13
|
+
lib/rsqs/exception.rb
|
14
|
+
script/console
|
15
|
+
script/destroy
|
16
|
+
script/generate
|
17
|
+
script/txt2html
|
18
|
+
setup.rb
|
19
|
+
spec/rsqs_spec.rb
|
20
|
+
spec/spec.opts
|
21
|
+
spec/spec_helper.rb
|
22
|
+
tasks/deployment.rake
|
23
|
+
tasks/environment.rake
|
24
|
+
tasks/rspec.rake
|
25
|
+
tasks/website.rake
|
26
|
+
website/index.html
|
27
|
+
website/index.txt
|
28
|
+
website/javascripts/rounded_corners_lite.inc.js
|
29
|
+
website/stylesheets/screen.css
|
30
|
+
website/template.html.erb
|
data/README.textile
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
h1. RSQS
|
2
|
+
|
3
|
+
h2. Description
|
4
|
+
|
5
|
+
A ruby implementation of the Amazon SQS API.
|
6
|
+
|
7
|
+
h2. Installation
|
8
|
+
|
9
|
+
sudo gem install rsqs
|
10
|
+
|
11
|
+
h2. Pre-Requirements
|
12
|
+
|
13
|
+
First, RSQS expects that you have the following environmental variables set:
|
14
|
+
|
15
|
+
# AMAZON_ACCESS_KEY - Your amazon web services access key which you can
|
16
|
+
find under "Access Identifiers" in your AWS account.
|
17
|
+
# AMAZON_SECRET_ACCESS_KEY - Your AWS secret access key which is found in
|
18
|
+
in the same place as the access key.
|
19
|
+
|
20
|
+
The easiest way to do this is to setup a file in your home directory and add
|
21
|
+
the following lines:
|
22
|
+
|
23
|
+
export AMAZON_ACCESS_KEY=1848101948W18189491
|
24
|
+
export AMAZON_SECRET_ACCESS_KEY=10198DKLDSL101/W31019D/10X
|
25
|
+
|
26
|
+
And then, assuming this file was called ".amazon_keys" you can load them:
|
27
|
+
|
28
|
+
source ~/.amazon_keys
|
29
|
+
|
30
|
+
h2. Usage
|
31
|
+
|
32
|
+
h3. Creating a New Queue
|
33
|
+
|
34
|
+
q = RSQS::Queue.create :new_queue
|
35
|
+
|
36
|
+
h3. Putting New Messages
|
37
|
+
|
38
|
+
Note: This will assume that :new_queue exists to save you requests to
|
39
|
+
SQS service. A QueueDoesNotExistError will be raised if the
|
40
|
+
queue doesn't exist.
|
41
|
+
|
42
|
+
RSQS::Queue.find :new_queue { send_message 'My New Message' }
|
43
|
+
|
44
|
+
OR
|
45
|
+
|
46
|
+
q = RSQS::Queue.find :new_queue
|
47
|
+
q.send_message 'My New Message'
|
48
|
+
|
49
|
+
NOTE: If you want RSQS to automatically create queues which do not exist,
|
50
|
+
use the find_or_create method instead!
|
51
|
+
|
52
|
+
h3. Getting Messages
|
53
|
+
|
54
|
+
q = RSQS::Queue.find :new_queue
|
55
|
+
m = q.receive
|
56
|
+
m # <RSQS::Message>
|
57
|
+
|
58
|
+
h2. License
|
59
|
+
|
60
|
+
(The MIT License)
|
61
|
+
|
62
|
+
Copyright (c) 2008 FIX
|
63
|
+
|
64
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
65
|
+
a copy of this software and associated documentation files (the
|
66
|
+
'Software'), to deal in the Software without restriction, including
|
67
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
68
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
69
|
+
permit persons to whom the Software is furnished to do so, subject to
|
70
|
+
the following conditions:
|
71
|
+
|
72
|
+
The above copyright notice and this permission notice shall be
|
73
|
+
included in all copies or substantial portions of the Software.
|
74
|
+
|
75
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
76
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
77
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
78
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
79
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
80
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
81
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/rsqs.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rexml/document'
|
6
|
+
require 'rsqs/exception'
|
7
|
+
require 'rsqs/message'
|
8
|
+
require 'rsqs/queue'
|
9
|
+
require 'rsqs/request'
|
10
|
+
require 'rsqs/version'
|
data/lib/rsqs/message.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module RSQS
|
2
|
+
class Message
|
3
|
+
attr_reader :id, :receipt, :body
|
4
|
+
|
5
|
+
def initialize(xml, parent)
|
6
|
+
@id = REXML::XPath.first(xml, '//ReceiveMessageResponse/ReceiveMessageResult/Message/MessageId').text
|
7
|
+
@receipt = REXML::XPath.first(xml, '//ReceiveMessageResponse/ReceiveMessageResult/Message/ReceiptHandle').text
|
8
|
+
@body = REXML::XPath.first(xml, '//ReceiveMessageResponse/ReceiveMessageResult/Message/Body').text
|
9
|
+
|
10
|
+
@parent = parent
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete
|
14
|
+
@parent.delete_message @receipt
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/rsqs/queue.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module RSQS
|
2
|
+
# = Queue
|
3
|
+
# The queue object is used to manage an entire queue within SQS.
|
4
|
+
class Queue
|
5
|
+
class <<self
|
6
|
+
def create(name)
|
7
|
+
Request.send('CreateQueue', {
|
8
|
+
'QueueName' => name,
|
9
|
+
'DefaultVisibilityTimeout' => '30'
|
10
|
+
})
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(name)
|
15
|
+
@name = name
|
16
|
+
end
|
17
|
+
|
18
|
+
def receive(max_number = nil, visibility = nil)
|
19
|
+
args = {}
|
20
|
+
args['MaxNumberOfMessages'] = max_number unless max_number.nil?
|
21
|
+
args['VisibilityTimeout'] = visibility unless visibility.nil?
|
22
|
+
|
23
|
+
response = send_request('ReceiveMessage', args)
|
24
|
+
|
25
|
+
# Parse the response
|
26
|
+
return nil unless REXML::XPath.first(response, '//ReceiveMessageResponse/ReceiveMessageResult').has_elements?
|
27
|
+
return Message.new(response, self)
|
28
|
+
end
|
29
|
+
|
30
|
+
def send(message)
|
31
|
+
send_request('SendMessage', { 'MessageBody' => message })
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete
|
35
|
+
send_request('DeleteQueue')
|
36
|
+
end
|
37
|
+
|
38
|
+
def delete_message(receipt)
|
39
|
+
send_request('DeleteMessage', { 'ReceiptHandle' => receipt })
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def send_request(action, args = {})
|
44
|
+
Request.send(action, args.merge({
|
45
|
+
'QueueURL' => @name
|
46
|
+
}))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/rsqs/request.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'base64'
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'cgi'
|
6
|
+
|
7
|
+
module RSQS
|
8
|
+
class Request
|
9
|
+
SQS_VERSION = '2008-01-01'
|
10
|
+
|
11
|
+
class <<self
|
12
|
+
def send(action, extras = {})
|
13
|
+
query = {
|
14
|
+
'Action' => action,
|
15
|
+
'SignatureVersion' => '1',
|
16
|
+
'Timestamp' => time_arg,
|
17
|
+
'AWSAccessKeyId' => amazon_access_key,
|
18
|
+
'Version' => SQS_VERSION
|
19
|
+
}
|
20
|
+
|
21
|
+
query.merge!(extras)
|
22
|
+
|
23
|
+
queue_url = 'http://queue.amazonaws.com/'
|
24
|
+
if query.has_key?('QueueURL')
|
25
|
+
queue_url += query.delete('QueueURL')
|
26
|
+
end
|
27
|
+
|
28
|
+
query['Signature'] = sign(query)
|
29
|
+
|
30
|
+
result = Net::HTTP.post_form(URI.parse(queue_url), query)
|
31
|
+
result = REXML::Document.new result.body
|
32
|
+
|
33
|
+
# If we got an error as the response, raise exception
|
34
|
+
if result.root.name == 'ErrorResponse'
|
35
|
+
raise SQSException.new(
|
36
|
+
REXML::XPath.first(result, '//ErrorResponse/Error/Code').text.strip,
|
37
|
+
REXML::XPath.first(result, '//ErrorResponse/Error/Message').text.strip)
|
38
|
+
end
|
39
|
+
|
40
|
+
result
|
41
|
+
end
|
42
|
+
|
43
|
+
# Creates the signature parameter for the SQS request. query should
|
44
|
+
# be a hash with the parameters that are going in the request.
|
45
|
+
def sign(query)
|
46
|
+
# Get the signature for the request:
|
47
|
+
# 1. Sort by keys alphabetically. (Downcase is required or uppercase comes before lowercase)
|
48
|
+
# 2. HMAC-Sha1 digest the string
|
49
|
+
# 3. Base64 encode.
|
50
|
+
digest_string = query.sort { |a,b| a[0].downcase <=> b[0].downcase }.to_a.flatten.collect { |x| x.to_s }.join('')
|
51
|
+
digest_string = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), amazon_secret_access_key, digest_string).to_s
|
52
|
+
|
53
|
+
Base64.encode64(digest_string).strip
|
54
|
+
end
|
55
|
+
|
56
|
+
def time_arg
|
57
|
+
Time.now.gmtime.strftime('%Y-%m-%dT%H:%M:%S.000Z')
|
58
|
+
end
|
59
|
+
|
60
|
+
def amazon_secret_access_key
|
61
|
+
raise ArgumentError.new('You need to set your AMAZON_SECRET_ACCESS_KEY environmental variable.') if ENV['AMAZON_SECRET_ACCESS_KEY'].nil?
|
62
|
+
ENV['AMAZON_SECRET_ACCESS_KEY']
|
63
|
+
end
|
64
|
+
|
65
|
+
def amazon_access_key
|
66
|
+
raise ArgumentError.new('You need to set your AMAZON_ACCESS_KEY environmental variable.') if ENV['AMAZON_ACCESS_KEY'].nil?
|
67
|
+
ENV['AMAZON_ACCESS_KEY']
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/rsqs/version.rb
ADDED
data/rsqs.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "rsqs"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.date = "2008-06-08"
|
5
|
+
s.summary = "A pure ruby gem to control an RSQS queue."
|
6
|
+
s.email = "mitchell.hashimoto@gmail.com"
|
7
|
+
s.homepage = "http://github.com/mitchellh/rsqs"
|
8
|
+
s.description = "RSQS is a pure ruby library to control Amazon SQS."
|
9
|
+
s.has_rdoc = false
|
10
|
+
s.authors = ["Mitchell Hashimoto"]
|
11
|
+
s.files = ["History.txt", "Manifest.txt", "README.textile", "Rakefile", "rsqs.gemspec", "lib/rsqs.rb", "lib/rsqs/exception.rb",
|
12
|
+
"lib/rsqs/message.rb", "lib/rsqs/queue.rb", "lib/rsqs/request.rb", "lib/rsqs/version.rb"]
|
13
|
+
#s.test_files = ["test/test_actor.rb", "test/test_blob.rb", "test/test_commit.rb", "test/test_config.rb", "test/test_diff.rb", "test/test_git.rb", "test/test_head.rb", "test/test_real.rb", "test/test_reality.rb", "test/test_repo.rb", "test/test_tag.rb", "test/test_tree.rb"]
|
14
|
+
s.rdoc_options = ["--main", "README.textile"]
|
15
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.textile"]
|
16
|
+
#s .add_dependency("mime-types", ["> 0.0.0"])
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mitchellh-rsqs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mitchell Hashimoto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-08 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: RSQS is a pure ruby library to control Amazon SQS.
|
17
|
+
email: mitchell.hashimoto@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- History.txt
|
24
|
+
- Manifest.txt
|
25
|
+
- README.textile
|
26
|
+
files:
|
27
|
+
- History.txt
|
28
|
+
- Manifest.txt
|
29
|
+
- README.textile
|
30
|
+
- Rakefile
|
31
|
+
- rsqs.gemspec
|
32
|
+
- lib/rsqs.rb
|
33
|
+
- lib/rsqs/exception.rb
|
34
|
+
- lib/rsqs/message.rb
|
35
|
+
- lib/rsqs/queue.rb
|
36
|
+
- lib/rsqs/request.rb
|
37
|
+
- lib/rsqs/version.rb
|
38
|
+
has_rdoc: false
|
39
|
+
homepage: http://github.com/mitchellh/rsqs
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options:
|
42
|
+
- --main
|
43
|
+
- README.textile
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.0.1
|
62
|
+
signing_key:
|
63
|
+
specification_version: 2
|
64
|
+
summary: A pure ruby gem to control an RSQS queue.
|
65
|
+
test_files: []
|
66
|
+
|