module EventMachine::Smsified::ServerHandler
Does the actual handling of the incoming notifications from SMSified. Factored out to ease in testing.
Public Instance Methods
handle(method, content)
click to toggle source
Inspects the method and contents of the incoming request and handles it. @param [required, String] the HTTP method of the request @param [optional, String] the POST’ed content of the request @return [bool] true if request was handled, false if not
# File lib/em-smsified/server.rb, line 46 def handle(method, content) if is_post? method return handle_incoming_message(content) || handle_delivery_notification(content) || handle_unknown(content) end return false end
on_delivery_notification(&blk)
click to toggle source
Sets the block to call when a delivery notification arrives
# File lib/em-smsified/server.rb, line 17 def on_delivery_notification(&blk) @on_delivery_notification = blk end
on_incoming_message(&blk)
click to toggle source
Sets the block to call when an incoming message arrives
# File lib/em-smsified/server.rb, line 10 def on_incoming_message(&blk) @on_incoming_message = blk end
on_unknown(&blk)
click to toggle source
Sets the block to call when an unknown message arrives
# File lib/em-smsified/server.rb, line 24 def on_unknown(&blk) @on_unknown = blk end
trigger_on_delivery_notification(msg)
click to toggle source
# File lib/em-smsified/server.rb, line 32 def trigger_on_delivery_notification(msg) @on_delivery_notification.call(msg) if @on_delivery_notification end
trigger_on_incoming_message(msg)
click to toggle source
# File lib/em-smsified/server.rb, line 28 def trigger_on_incoming_message(msg) @on_incoming_message.call(msg) if @on_incoming_message end
trigger_on_unknown(request)
click to toggle source
# File lib/em-smsified/server.rb, line 36 def trigger_on_unknown(request) @on_unknown.call(request) if @on_unknown end
Private Instance Methods
handle_delivery_notification(content)
click to toggle source
# File lib/em-smsified/server.rb, line 64 def handle_delivery_notification(content) begin msg = EventMachine::Smsified::DeliveryInfoNotification.new(content) trigger_on_delivery_notification(msg) return true rescue end return false end
handle_incoming_message(content)
click to toggle source
# File lib/em-smsified/server.rb, line 74 def handle_incoming_message(content) begin msg = EventMachine::Smsified::IncomingMessage.new(content) trigger_on_incoming_message(msg) return true rescue end return false end
handle_unknown(content)
click to toggle source
# File lib/em-smsified/server.rb, line 59 def handle_unknown(content) trigger_on_unknown(content) return true end
is_post?(method)
click to toggle source
# File lib/em-smsified/server.rb, line 55 def is_post?(method) return method == "POST" end