Module: EventMachine::Smsified::ServerHandler

Included in:
Server
Defined in:
lib/em-smsified/server.rb

Overview

Does the actual handling of the incoming notifications from SMSified. Factored out to ease in testing.

Instance Method Summary collapse

Instance Method Details

#handle(method, content) ⇒ bool

Inspects the method and contents of the incoming request and handles it.

Parameters:

  • the (required, String)

    HTTP method of the request

  • the (optional, String)

    POST’ed content of the request

Returns:

  • (bool)

    true if request was handled, false if not



46
47
48
49
50
51
# 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) ⇒ Object

Sets the block to call when a delivery notification arrives



17
18
19
# File 'lib/em-smsified/server.rb', line 17

def on_delivery_notification(&blk)
  @on_delivery_notification = blk
end

#on_incoming_message(&blk) ⇒ Object

Sets the block to call when an incoming message arrives



10
11
12
# File 'lib/em-smsified/server.rb', line 10

def on_incoming_message(&blk)
  @on_incoming_message = blk
end

#on_unknown(&blk) ⇒ Object

Sets the block to call when an unknown message arrives



24
25
26
# File 'lib/em-smsified/server.rb', line 24

def on_unknown(&blk)
  @on_unknown = blk
end

#trigger_on_delivery_notification(msg) ⇒ Object



32
33
34
# 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) ⇒ Object



28
29
30
# 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) ⇒ Object



36
37
38
# File 'lib/em-smsified/server.rb', line 36

def trigger_on_unknown(request)
  @on_unknown.call(request) if @on_unknown
end