Class: SMSFu::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/sms_fu/sms_fu.rb

Constant Summary collapse

DELIVERY_METHODS =
[:action_mailer, :pony]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.

Raises:



21
22
23
24
25
# File 'lib/sms_fu/sms_fu.rb', line 21

def initialize(opts = {})
  self.delivery     = opts[:delivery].to_sym
  self.pony_config  = opts[:pony_config]
  raise SMSFuException.new("Pony configuration required") if @delivery == :pony && @pony_config.nil?
end

Instance Attribute Details

#deliveryObject

Returns the value of attribute delivery.



4
5
6
# File 'lib/sms_fu/sms_fu.rb', line 4

def delivery
  @delivery
end

#pony_configObject

Returns the value of attribute pony_config.



4
5
6
# File 'lib/sms_fu/sms_fu.rb', line 4

def pony_config
  @pony_config
end

Class Method Details

.configure(opts = {}) ⇒ Object

Sets up a new SMSFu::Client. Allows for use of ActionMailer or Pony for e-mail delivery. Pony requires :pony_config to be defined to work properly.

  • ActionMailer 3 sms_fu = SMSFu::Client.configure(:delivery => :action_mailer)

  • Pony 1.0 sms_fu = SMSFu::Client.configure(:delivery => :pony,

    :pony_config => { :via => :sendmail })
    


17
18
19
# File 'lib/sms_fu/sms_fu.rb', line 17

def self.configure(opts = {})
  new(opts)
end

Instance Method Details

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

Delivers the SMS message in the form of an e-mail

sms_fu.deliver("1234567890","at&t","hello world")

Raises:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sms_fu/sms_fu.rb', line 37

def deliver(number, carrier, message, options = {})
  raise SMSFuException.new("Can't deliver blank message to #{format_number(number)}") if message.nil? || message.empty?

  limit   = options[:limit] || message.length
  from    = options[:from] || SMSFu.from_address
  message = message[0..limit-1]
  email   = SMSFu.sms_address(number,carrier)

  if @delivery == :pony
    Pony.mail({:to => email, :body => message, :from => from}.merge!(@pony_config))
  else
    SMSNotifier.send_sms(email, message, from).deliver
  end
end