Class: SMSFu::Client
- Inherits:
-
Object
- Object
- SMSFu::Client
- Defined in:
- lib/sms_fu/sms_fu.rb
Constant Summary collapse
- DELIVERY_METHODS =
[:action_mailer, :pony]
Instance Attribute Summary collapse
-
#delivery ⇒ Object
Returns the value of attribute delivery.
-
#pony_config ⇒ Object
Returns the value of attribute pony_config.
Class Method Summary collapse
-
.configure(opts = {}) ⇒ Object
Sets up a new SMSFu::Client.
Instance Method Summary collapse
-
#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”).
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
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
#delivery ⇒ Object
Returns the value of attribute delivery.
4 5 6 |
# File 'lib/sms_fu/sms_fu.rb', line 4 def delivery @delivery end |
#pony_config ⇒ Object
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")
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, , = {}) raise SMSFuException.new("Can't deliver blank message to #{format_number(number)}") if .nil? || .empty? limit = [:limit] || .length from = [:from] || SMSFu.from_address = [0..limit-1] email = SMSFu.sms_address(number,carrier) if @delivery == :pony Pony.mail({:to => email, :body => , :from => from}.merge!(@pony_config)) else SMSNotifier.send_sms(email, , from).deliver end end |