module ActionTexter

Copyright © 2014, 2015, Carousel Apps

Copyright © 2012, 2013, 2014, 2015, Carousel Apps

Constants

VERSION

Public Class Methods

inform_interceptors(message) click to toggle source

Inform all the interceptors about the SMS being sent. Any interceptor can modify the message or cancel it

@param message [ActionTexter::Message] that is being sent @returns the message that must be sent, returned by the last interceptor. This may be nil or false

# File lib/action_texter/action_texter.rb, line 67
def self.inform_interceptors(message)
  @@delivery_interceptors.each do |interceptor|
    message = interceptor.delivering_sms(message)
    break if message.blank?
  end
  message
end
inform_observers(message, response) click to toggle source

Inform all the observers about the SMS being sent

@param message [ActionTexter::Message] that is being sent @returns the list of observers

# File lib/action_texter/action_texter.rb, line 58
def self.inform_observers(message, response)
  @@delivery_observers.each { |observer| observer.delivered_sms(message, response) }
end
register_interceptor(interceptor) click to toggle source

You can register an object to be given every Message object that will be sent, before it is sent. This allows you to modify the contents of the message, or even stop it by returning false or nil.

Your object needs to respond to a single method delivering_sms(message) It must return the modified object to be sent instead, or nil

@param interceptor [Object] with a delivering_sms method that will be called passing in the ActionTexter::Message @returns the interceptor added

# File lib/action_texter/action_texter.rb, line 39
def self.register_interceptor(interceptor)
  unless @@delivery_interceptors.include?(interceptor)
    @@delivery_interceptors << interceptor
  end
  interceptor
end
register_observer(observer) click to toggle source

You can register an object to be informed of every SMS that is sent, after it is sent Your object needs to respond to a single method delivered_sms(message, response)

message will be of type ActionTexter::Message
response will be of type ActionTexter::Response

@param observer [Object] with a delivered_sms method that will be called passing in the ActionTexter::Message

and ActionTexter::Response

@returns the observer added

# File lib/action_texter/action_texter.rb, line 16
def self.register_observer(observer)
  unless @@delivery_observers.include?(observer)
    @@delivery_observers << observer
  end
  observer
end
unregister_interceptor(interceptor) click to toggle source

Unregister the given interceptor

@param interceptor [Object] to unregister @returns deleted interceptor

# File lib/action_texter/action_texter.rb, line 50
def self.unregister_interceptor(interceptor)
  @@delivery_interceptors.delete(interceptor)
end
unregister_observer(observer) click to toggle source

Unregister the given observer

@param observer [Object] to unregister @returns deleted observer

# File lib/action_texter/action_texter.rb, line 27
def self.unregister_observer(observer)
  @@delivery_observers.delete(observer)
end