Class: SmsSafe::Interceptors::ActionTexter

Inherits:
SmsSafe::Interceptor show all
Defined in:
lib/sms_safe/interceptors/action_texter.rb

Overview

Interceptor class for ActionTexter Gem. Maps ActionTexter::Message into SmsSafe::Message and back.

Instance Method Summary collapse

Methods inherited from SmsSafe::Interceptor

#deliver_email, #discard, #email, #email_body, #email_recipient, #intercept_message!, #intercept_message?, #process_message, #redirect_phone_number, #redirect_text

Instance Method Details

#convert_message(message) ⇒ Message

Converts an ActionTexter::Message into an SmsSafe::Message

Parameters:

  • message (ActionTexter::Message)

    that is being sent by ActionTexter gem

Returns:

  • (Message)

    the message converted into our own Message class



17
18
19
# File 'lib/sms_safe/interceptors/action_texter.rb', line 17

def convert_message(message)
  SmsSafe::Message.new(from: message.from, to: message.to, text: message.text, original_message: message)
end

#delivering_sms(message) ⇒ ActionTexter::Message

This method will be called differently for each Texter Gem, it’s the one that the hook likes to call In all cases, it’s a one-liner that calls process_message in the superclass It could even be an alias, for all practical purposes

Parameters:

  • message (ActionTexter::Message)

    that is being sent by ActionTexter gem

Returns:

  • (ActionTexter::Message)

    modified message to send, or nil to cancel send



10
11
12
# File 'lib/sms_safe/interceptors/action_texter.rb', line 10

def delivering_sms(message)
  self.process_message(message)
end

#redirect(message) ⇒ ActionTexter::Message

Returns a modified version of the original message with new recipient and text,

to give back to the texter gem to send.

Parameters:

  • message (Message)

    that is being sent, unmodified

Returns:

  • (ActionTexter::Message)

    modified message to send



27
28
29
30
31
32
# File 'lib/sms_safe/interceptors/action_texter.rb', line 27

def redirect(message)
  original_message = message.original_message
  original_message.to = redirect_phone_number(message)
  original_message.text = redirect_text(message)
  original_message
end