Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

wip added support for sending messages. need error handling.

  • Loading branch information...
commit 85fba6d7e35f2cb6413ff84baa134c2eac344e24 1 parent 89b3702
Leon Gersing authored
View
6 lib/sqs.rb
@@ -35,7 +35,11 @@ def set_queue_attributes(options={})
end
def send_message(options={})
- raise "Not Implemented Yet."
+ raise "no object(:message) or string(:message_body) specified" unless (options[:message] || options[:message_body])
+ options.merge!( :message_body => options.delete(:message).body ) if options[:message]
+ body = options[:message_body]
+
+ call_amazon(options){ |req| SQSSendMessageResponse.parse(body, req.response) }
end
def add_permission(options={})
View
19 lib/sqs_send_message_response.rb
@@ -0,0 +1,19 @@
+require 'nokogiri'
+require 'json'
+require 'base64'
+require 'ostruct'
+
+class SQSSendMessageResponse
+ attr_accessor :body, :md5_of_body, :message_id, :receipt_handle
+
+ def self.parse(original_body, xml)
+ doc = Nokogiri::XML(xml)
+ message = SQSMessage.new
+ doc.search("SendMessageResult").each do |message_element|
+ message.body = original_body || ""
+ message.md5_of_body = message_element.at("MD5OfMessageBody").text.strip
+ message.message_id = message_element.at("MessageId").text.strip
+ end
+ message
+ end
+end
View
2  spec/fixtures/send_message.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<SendMessageResponse><SendMessageResult><MD5OfMessageBody>fafb00f5732ab283681e124bf8747ed1</MD5OfMessageBody><MessageId>5fea7756-0ea4-451a-a703-a558b933e274</MessageId></SendMessageResult><ResponseMetadata><RequestId>27daac76-34dd-47df-bd01-1f6e873584a0</RequestId></ResponseMetadata></SendMessageResponse>
View
31 spec/sqs_spec.rb
@@ -60,7 +60,36 @@ def initialize
end
it "set_queue_attributes"
- it "send_message"
+ context "putting a message on the queue" do
+ it "send_message with SQSMessage object" do
+ msg = SQSMessage.new
+ msg.body = "foo"
+ client.send_message(
+ :queue => queue,
+ :message => msg,
+ :callbacks => {
+ :success => lambda { |sqs_message_obj|
+ sqs_message_obj.body.should == "foo"
+ sqs_message_obj.md5_of_body.should_not be_nil
+ }
+ }
+ )
+ EM::HttpRequest.succeed(EM::MockResponse.new(xml_fixture(:send_message)))
+ end
+ it "send_message with message body" do
+ client.send_message(
+ :queue => queue,
+ :message_body => "foo",
+ :callbacks => {
+ :success => lambda { |sqs_message_obj|
+ sqs_message_obj.body.should == "foo"
+ sqs_message_obj.md5_of_body.should_not be_nil
+ }
+ }
+ )
+ EM::HttpRequest.succeed(EM::MockResponse.new(xml_fixture(:send_message)))
+ end
+ end
it "creates a queue" do
client.create_queue(
View
1  sqs_async.rb
@@ -8,5 +8,6 @@
require 'sqs_message'
require 'sqs_queue'
require 'sqs_permission'
+require 'sqs_send_message_response'
require 'core_ext/hash'
Please sign in to comment.
Something went wrong with that request. Please try again.