class SMSEasy::Client
Public Class Methods
carrier(key)
click to toggle source
# File lib/sms/easy/easy.rb, line 57 def carrier(key) raise SMSEasyException.new("Carrier (#{key}) is not supported") unless SMSEasy::Client.carriers.has_key?(key.downcase) carriers[key] end
carrier_email(key)
click to toggle source
# File lib/sms/easy/easy.rb, line 53 def carrier_email(key) carrier(key.downcase)['value'] end
carrier_name(key)
click to toggle source
# File lib/sms/easy/easy.rb, line 49 def carrier_name(key) carrier(key)['name'] end
carriers()
click to toggle source
Returns back a list of all carriers
SMSEasy.carriers
# File lib/sms/easy/easy.rb, line 41 def carriers @@config['carriers'] end
config()
click to toggle source
# File lib/sms/easy/easy.rb, line 35 def config @@config end
configure(opts = {})
click to toggle source
# File lib/sms/easy/easy.rb, line 29 def configure(opts = {}) @@config.merge!(opts) # require 'pp' # pp @@@@config end
format_number(number)
click to toggle source
# File lib/sms/easy/easy.rb, line 69 def format_number(number) stripped = number.gsub("-","").strip formatted = (stripped.length == 11 && stripped[0,1] == "1") ? stripped[1..stripped.length] : stripped raise SMSEasyException.new("Number (#{number}) is not formatted correctly") unless valid_number?(formatted) formatted end
from_address()
click to toggle source
# File lib/sms/easy/easy.rb, line 45 def from_address @@config['from_address'] end
sms_address(number,carrier)
click to toggle source
Returns back a properly formatted SMS e-mail address
SMSEasy.sms_address("1234567890","at&t")
# File lib/sms/easy/easy.rb, line 64 def sms_address(number,carrier) raise SMSEasyException.new("Missing number or carrier") if number.nil? || carrier.nil? format_number(number) + carrier_email(carrier.downcase) end
valid_number?(number)
click to toggle source
# File lib/sms/easy/easy.rb, line 76 def valid_number?(number) number.length >= 10 && number[/^.\d+$/] end
Public Instance Methods
deliver(number, carrier, message, options = {})
click to toggle source
Delivers the SMS message in the form of an e-mail
sms-easy.deliver("1234567890","at&t","hello world")
# File lib/sms/easy/easy.rb, line 9 def deliver(number, carrier, message, options = {}) raise SMSEasyException.new("Can't deliver blank message to #{SMSEasy::Client.format_number(number)}") if message.nil? || message.empty? limit = options[:limit] || message.length from = options[:from] || SMSEasy::Client.from_address message = message[0..limit-1] email = SMSEasy::Client.sms_address(number,carrier) if @delivery == :pony Pony.mail({:to => email, :body => message, :from => from}.merge!(@pony_config)) else if ActionMailer.version.version.to_f >= 4.2 SMSEasyNotifier.send_sms(email, message, from).deliver_now else SMSEasyNotifier.send_sms(email, message, from).deliver end end end