Class: SMSnger

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

Overview

WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Class Method Summary collapse

Class Method Details

.carrier_name(key) ⇒ Object



49
50
51
# File 'lib/smsnger.rb', line 49

def self.carrier_name(key)
  carriers[key]['name']
end

.carriersObject



53
54
55
# File 'lib/smsnger.rb', line 53

def self.carriers
  @@carriers.dup
end

.deliver_sms(number, carrier, message, options = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/smsnger.rb', line 57

def self.deliver_sms(number,carrier,message,options={})
  raise SMSngerException.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)
  
  case @@mail_via
  when :sendmail
    Pony.mail(:to => sms_email, :from => options[:from], :body => message)
  when :smtp
    Pony.mail(:to => sms_email, :from => options[:from], :body => message, :via => @@mail_via, :smtp => @@smtp_settings)
  else
    raise SMSngerException.new("Unknown mail method #{@@mail_via}.")
  end
  
rescue SMSngerException => exception
  raise exception
end

.get_sms_address(number, carrier) ⇒ Object



78
79
80
81
# File 'lib/smsnger.rb', line 78

def self.get_sms_address(number,carrier)
  number = format_number(number)
  determine_sms_email(number,carrier)
end

.setup(options = {}) ⇒ Object

Raises:

  • (SMSngerExceptions)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/smsnger.rb', line 26

def self.setup(options = {})
  default_options = {
    :config => File.join(File.dirname(__FILE__),"carriers.yml"),
    :from => "[email protected]",
    :mail_via => :sendmail
  }
  default_options.merge!(options)
  
  @@mail_via ||= default_options[:mail_via]
  
  raise SMSngerExceptions.new("You must specify a :from address setting in SMSnger.setup!") unless default_options.has_key?(:from)
  @@from_address = default_options[:from]
  
  if @@mail_via == :smtp
    raise SMSngerExceptions.new("You must specify the :smtp settings in SMSnger.setup!") unless default_options.has_key?(:smtp)
    smtp_config(default_options[:smtp]) 
  end
  
  load_carriers(default_options[:config])
  
  return default_options
end