Module: ActionTexter

Defined in:
lib/action_texter/version.rb,
lib/action_texter/action_texter.rb

Overview

Copyright © 2014, 2015, Carousel Apps

Defined Under Namespace

Classes: Client, Message, NexmoClient, NexmoResponse, Response, TestClient, TestResponse, TwilioClient, TwilioResponse

Constant Summary collapse

VERSION =
"0.2.0"
@@delivery_observers =
[]
@@delivery_interceptors =
[]

Class Method Summary collapse

Class Method Details

.inform_interceptors(message) ⇒ Object

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

Parameters:



67
68
69
70
71
72
73
# 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) ⇒ Object

Inform all the observers about the SMS being sent

Parameters:



58
59
60
# 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) ⇒ Object

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

Parameters:

  • interceptor (Object)

    with a #delivering_sms method that will be called passing in the ActionTexter::Message



39
40
41
42
43
44
# 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) ⇒ Object

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

Parameters:

  • observer (Object)

    with a #delivered_sms method that will be called passing in the ActionTexter::Message and ActionTexter::Response



16
17
18
19
20
21
# 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) ⇒ Object

Unregister the given interceptor

Parameters:

  • interceptor (Object)

    to unregister



50
51
52
# File 'lib/action_texter/action_texter.rb', line 50

def self.unregister_interceptor(interceptor)
  @@delivery_interceptors.delete(interceptor)
end

.unregister_observer(observer) ⇒ Object

Unregister the given observer

Parameters:

  • observer (Object)

    to unregister



27
28
29
# File 'lib/action_texter/action_texter.rb', line 27

def self.unregister_observer(observer)
  @@delivery_observers.delete(observer)
end