class Sms
Public Class Methods
delivery_method()
click to toggle source
# File lib/sms.rb, line 19 def delivery_method @@delivery_method end
delivery_method=(obj)
click to toggle source
# File lib/sms.rb, line 15 def delivery_method=(obj) @@delivery_method = obj end
inform_observers(sms)
click to toggle source
Called when delivery is taking place
@param [Sms::Message] sms
# File lib/sms.rb, line 38 def inform_observers(sms) @@delivery_notification_observers.each do |observer| observer.delivered_sms(sms) end end
receive(params)
click to toggle source
Receive an SMS
@param [Hash] params @option params [String] :from @option params [String] :to @option params [String] :text
# File lib/sms.rb, line 57 def receive(params) ActiveSupport::Notifications.instrument("receive.sms") do |payload| sms = Sms::Message.new(params) set_payload_for_sms(payload, sms) new.receive(sms) end end
register_observer(observer)
click to toggle source
The observer needs to respond to a single method delivered_sms(sms) which receives the sms that is sent.
# File lib/sms.rb, line 25 def register_observer(observer) unless @@delivery_notification_observers.include?(observer) @@delivery_notification_observers << observer end end
unregister_observer(observer)
click to toggle source
# File lib/sms.rb, line 31 def unregister_observer(observer) @@delivery_notification_observers.delete(observer) end
Public Instance Methods
receive(sms)
click to toggle source
Subclasses need to implement this method in order to handle incoming SMS. It should return the received message.
@abstract @param [Sms::Message] sms
# File lib/sms.rb, line 8 def receive(sms) raise NotImplementedError.new('Need to subclass and implement') end