diff options
| -rw-r--r-- | README.rdoc | 17 | ||||
| -rw-r--r-- | lib/sms_fu.rb | 12 | ||||
| -rw-r--r-- | lib/sms_notifier.rb | 6 |
3 files changed, 19 insertions, 16 deletions
diff --git a/README.rdoc b/README.rdoc index 338f8c5..08680cd 100644 --- a/README.rdoc +++ b/README.rdoc @@ -42,18 +42,23 @@ That's it! Now you're good to go. * <b>Check sms_fu.yml for a complete list of supported carriers, including international carriers as well.</b> - - deliver_sms("5558675309","at&t","your message here") - + + deliver_sms("5558675309","at&t","message") + +* If you want to set a custom from e-mail per SMS message, you can do so + by doing the following. + + deliver_sms("5558675309","at&t","message", :from => "bob@test.com") + * You can set the maximum length of the SMS message, which is not set by default. Most phones can only accept 128 characters. To do this just specify the limit option. - - deliver_sms("5558675309","at&t","your message here", :limit => 128) + + deliver_sms("5558675309","at&t","message", :limit => 128) * You can retrieve just the formatted address to use in your own mailer. get_sms_address("5558675309","at&t") # => "5558675309@txt.att.net" - + Copyright (c) 2008 Brendan G. Lim, Intridea, Inc., released under the MIT license diff --git a/lib/sms_fu.rb b/lib/sms_fu.rb index 9533341..2aa2dea 100644 --- a/lib/sms_fu.rb +++ b/lib/sms_fu.rb @@ -23,22 +23,23 @@ require 'sms_notifier' module SMSFu RAILS_CONFIG_ROOT = defined?(RAILS_ROOT) ? "#{RAILS_ROOT}/config" : "#{File.dirname(__FILE__)}/../templates" unless defined?(RAILS_CONFIG_ROOT) - @config ||= YAML::load(File.open("#{RAILS_CONFIG_ROOT}/sms_fu.yml")) - @@carriers ||= @config['carriers'] + @config ||= YAML::load(File.open("#{RAILS_CONFIG_ROOT}/sms_fu.yml")) + @@carriers ||= @config['carriers'] + @@from_address = @config['config']['from_address'] def self.carriers @@carriers.dup end def deliver_sms(number,carrier,message,options={}) - number = format_number(number) - raise SMSFuException.new("Cannot deliver an empty message to #{number}") if message.nil? or message.empty? + raise SMSFuException.new("Cannot deliver an empty message to #{format_number(number)}") if message.nil? or message.empty? options[:limit] ||= message.length + options[:from] ||= @@from_address message = message[0..options[:limit]-1] sms_email = determine_sms_email(format_number(number),carrier) - SmsNotifier.deliver_sms_message(sms_email,message) + SmsNotifier.deliver_sms_message(sms_email,message,options[:from]) rescue SMSFuException => exception raise exception end @@ -53,7 +54,6 @@ module SMSFu def format_number(number) pre_formatted = number.gsub("-","").strip formatted = (pre_formatted.length == 11 && pre_formatted[0,1] == "1") ? pre_formatted[1..pre_formatted.length] : pre_formatted - return is_valid?(formatted) ? formatted : (raise SMSFuException.new("Phone number (#{number}) is not formatted correctly")) end diff --git a/lib/sms_notifier.rb b/lib/sms_notifier.rb index 1dff814..5d960c6 100644 --- a/lib/sms_notifier.rb +++ b/lib/sms_notifier.rb @@ -22,13 +22,11 @@ require 'yaml' class SmsNotifier < ActionMailer::Base @config = YAML::load(File.open("#{RAILS_ROOT}/config/sms_fu.yml")) - @@from_address = @config['config']['from_address'] - cattr_accessor :from_address - def sms_message(recipient, message) + def sms_message(recipient, message, sender_email) content_type "text/plain" recipients recipient - from from_address + from sender_email body['message'] = message end |
