Class: TatangoSMS::MO
- Inherits:
-
Object
- Object
- TatangoSMS::MO
- Defined in:
- lib/tatango_sms/mo.rb
Overview
TatangoSMS::MO makes it easy to receive messages from the Tatango SMS Gateway
Example:
require 'tatango_sms/mo'
server = TatangoSMS::MO.server('0.0.0.0', '3333')
TatangoSMS::MO.receive(server, '/') do |phone_number, content|
# parse content and do something
# maybe even send a message back with TatangoSMS::MT.send(...)
end
server.run.join
Defined Under Namespace
Classes: Handler
Class Method Summary collapse
-
.receive(server, path = '/', &blk) ⇒ Object
register a block of code to receive messages.
-
.server(*args) ⇒ Object
setup a new mongrel server to accept MOs.
Class Method Details
.receive(server, path = '/', &blk) ⇒ Object
register a block of code to receive messages
expects a Mongrel::HttpServer. use MO.server or just use one you already have?
NOTE: content will be exactly what the user entered in their cell phone. if they used your keyword, it will also be in content
Example:
TatangoSMS::MO.receive(server, '/') do |phone_number, content|
puts "message from #{phone_number} was #{content}"
end
73 74 75 |
# File 'lib/tatango_sms/mo.rb', line 73 def receive(server, path = '/', &blk) server.register(path, Handler.new(&blk)) end |
.server(*args) ⇒ Object
setup a new mongrel server to accept MOs
returns a Mongrel::HttpServer
Examples:
server = Mongrel::MO.server('0.0.0.0', '3333')
# see MO::receive for how to register a block of code to receive messages
server.run # run the server
server.acceptor.join # the acceptor thread can be found here
58 59 60 |
# File 'lib/tatango_sms/mo.rb', line 58 def server(*args) Mongrel::HttpServer.new(*args) end |