Module: Textr
- Defined in:
- lib/textr.rb,
lib/textr/version.rb,
lib/textr/rake/tasks.rb,
lib/textr/extends_textr.rb
Defined Under Namespace
Modules: ExtendsTextr, Rake
Constant Summary
collapse
- VERSION =
"0.1.0"
- @@config =
File.exists?('config/textr_smtp.yml') ? YAML.load(ERB.new(File.read(('config/textr_smtp.yml'))).result)[Rails.env].symbolize_keys : false
- @@carriers =
{
:att => 'txt.att.net',
:alltel => 'message.alltel.com',
:boost => 'myboostmobile.com',
:cellone => 'mobile.celloneusa.com',
:metropcs => 'mymetropcs.com',
:nextel => 'messaging.nextel.com',
:rogers => 'pcs.rogers.com',
:sprint => 'messaging.sprintpcs.com',
:tmobile => 'tmomail.net',
:uscellular => 'email.uscc.net',
:verizon => 'vtext.com',
:virgin => 'vmobl.com'
}
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.extended(base) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/textr.rb', line 40
def self.extended(base)
unless base.respond_to?(:textr_options)
base.class_eval do
attr_accessor :phone
end
end
end
|
.send_sms(options = {}) ⇒ Object
69
70
71
72
73
|
# File 'lib/textr.rb', line 69
def self.send_sms( options={} )
sms = Object.new
sms.extend Textr
sms.send_sms(options)
end
|
Instance Method Details
#number_from_options ⇒ Object
75
76
77
78
79
80
|
# File 'lib/textr.rb', line 75
def number_from_options
if respond_to?(:textr_options)
phone = textr_options[:phone_field]
end
send(phone)
end
|
#send_sms(options = {}) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/textr.rb', line 56
def send_sms( options={} )
number = options[:number] || self.number_from_options
raise "#{self.class.to_s}" if number.blank?
raise ':carrier required' if options[:carrier].nil?
raise ':body required' if options[:body].nil?
Pony.mail({
:to => txtable_address({:carrier => options[:carrier], :number => number}),
:subject => options[:subject],
:body => options[:body]
}.merge(smtp_options))
end
|
#smtp_options ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/textr.rb', line 10
def smtp_options
@@config ? { :from => @@config[:from],
:via => @@config[:protocol].to_sym,
:via_options => {
:address => @@config[:address],
:port => @@config[:port],
:enable_starttls_auto => @@config[:ssl],
:user_name => @@config[:username],
:password => @@config[:password],
:authentication => @@config[:authentication],
:domain => @@config[:domain]
}
} : { }
end
|
#txtable_address(options = {}) ⇒ Object
48
49
50
|
# File 'lib/textr.rb', line 48
def txtable_address( options={} )
"#{options[:number].gsub(/\D/, "")[-10..-1]}@#{@@carriers[options[:carrier].to_sym]}"
end
|