Class: MoteSMS::ActionMailerTransport

Inherits:
Object
  • Object
show all
Defined in:
lib/mote_sms/transports/action_mailer_transport.rb

Overview

MoteSMS::ActionMailerTransport provides a transport implementation which can be used in development to forward SMS as e-mails. This allows to test sending SMSes to an e-mail endpoint.

Examples:

# => forwards all SMS to [email protected]
MoteSMS.transport = MoteSMS::ActionMailerTransport.new "[email protected]"

# => also accepts a Proc as recipient
MoteSMS.transport = MoteSMS::ActionMailerTransport.new ->(msg) { "#{msg.from}@example.com" }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recipient) ⇒ ActionMailerTransport

Public: Create a new ActionMailerTransport instance



32
33
34
# File 'lib/mote_sms/transports/action_mailer_transport.rb', line 32

def initialize(recipient)
  self.recipient = recipient
end

Instance Attribute Details

#recipientObject

Public: Read/change the recipient used when delivering the message. Also accepts a Proc.



29
30
31
# File 'lib/mote_sms/transports/action_mailer_transport.rb', line 29

def recipient
  @recipient
end

Instance Method Details

#deliver(message, options = {}) ⇒ Object

Public: Sends message using ActionMailer to recipient.

message - The MoteSMS::Message instance to deliver. options - The Hash with additional, transport specific options,

currently ignored.

Returns nothing.



43
44
45
46
# File 'lib/mote_sms/transports/action_mailer_transport.rb', line 43

def deliver(message, options = {})
  to = self.recipient.respond_to?(:call) ? self.recipient.call(message) : self.recipient
  ActionMailerSMSMailer.forward_sms(to, message).deliver
end