summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrendan G. Lim2008-07-31 13:48:15 -0400
committerBrendan G. Lim2008-07-31 13:48:15 -0400
commit3912b0b91621ba1a827585f3b22c1426fc70c9e4 (patch)
tree1a49af99446b06490544835ea5dcba50aef728e4
parent09fc1fa3076082d98b61f7cdf0d10dd5abd30a1a (diff)
downloadsms-fu-3912b0b91621ba1a827585f3b22c1426fc70c9e4.tar.bz2
Adding ability to specify custom from address per mailing
-rw-r--r--README.rdoc17
-rw-r--r--lib/sms_fu.rb12
-rw-r--r--lib/sms_notifier.rb6
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