class Telesms::Outgoing

This class represents an outgoing message.

Attributes

from[RW]

@return [String] The FROM address.

message[RW]

@return [String] The message body being sent.

provider[RW]

@return [String] The provider for the number.

to[RW]

@return [String] The TO address (will be concatinated with a provider).

Public Class Methods

deliver(from, to, provider, message) click to toggle source

This method creates a new outgoing message and sends it.

@param [String] from

The FROM address.

@param [String] to

The TO address.

@param [String] provider

The provider name.

@param [String] message

The message being sent.

@return [Mail]

# File lib/telesms/outgoing.rb, line 37
def self.deliver(from, to, provider, message)
  self.new(from, to, provider, message).deliver
end
new(from, to, provider, message) click to toggle source

This method creates a new outgoing message.

@param [String] from

The FROM address.

@param [String] to

The TO address.

@param [String] provider

The provider name.

@param [String] message

The message being sent.

@return [Outgoing]

# File lib/telesms/outgoing.rb, line 56
def initialize(from, to, provider, message)
  @from     = from
  @to       = to
  @provider = provider
  @message  = message
end

Public Instance Methods

deliver() click to toggle source

This method sends an email message disguised as an SMS message.

@return [Mail]

# File lib/telesms/outgoing.rb, line 66
def deliver
  Mail.new(from: from, to: formatted_to, body: sanitized_message).deliver!
end
formatted_to() click to toggle source

This method formats the TO address to include the provider.

@return [String]

# File lib/telesms/outgoing.rb, line 73
def formatted_to
  "#{to}@#{Base.gateways[@provider][:sms]}" rescue raise "Invalid provider"
end
sanitized_message() click to toggle source

This method sanitizes the message body.

@return [String]

# File lib/telesms/outgoing.rb, line 80
def sanitized_message
  message.to_s[0,140]
end