Sinatra AWS SNS Endpoint - Help needed
Hiya,
Due to the undocumen开发者_运维技巧ted nature of the Amazon SNS endpoints and how they interact with the user, I am struggling to code an endpoint in Sinatra for my application. I have some code written in PHP here, but I am struggling to convert it into a Ruby array becauserequest.env["rack.input"].read
encapsulates everything into something similar to a PHP array:
{"Message"=>"chapstick", "Subject"=>"cherry", "Signature"=>"QutYUXuqWQqiAY4PUvd+Hq+9KWSvPVwck22oV0pXkgSg0p+kZ/2Q+pS24siDPKxxHB8+ru5q6 QBqQv+RHKWobiLiupEf4UP1MQu3lnP4Z2TYWvbHVjNiO5OutcaivPrn08EIBTOMsWl2i8JmaTBXozOp4r1vheqg6k/wWDoUmd0=", "TopicArn"=>"arn:aws:sns:us-east-1:687180262489:plinklebird", "SignatureVersion"=>"1", "Timestamp"=>"2010-12-03T22:10:01.141Z", "MessageId"=>"dc8a8502-44a8-41ec-9616-1d049f00724d", "UnsubscribeURL"=>"https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:687180262489:plinklebird:99e83fd5-58a9-41bb-82bd-9920a1ee1a94", "Type"=>"Notification"}
I am not sure how to handle this, can anybody please help?
Thank you very much for your time,
Luke CarpenterA year and four months later, reflecting on this problem:
It was because I was a complete and utter noob, and I didn't know what a Hash was in Ruby at the time
In your post
block, access the contents of the hash like so:
post "/" do
puts params['Message']
halt 200
end
The message SNS sends you will be printed out to STDOUT/your terminal
精彩评论