Module: SMS
- Defined in:
- lib/sms.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
Returns the value of attribute from.
-
#secret ⇒ Object
Returns the value of attribute secret.
-
#sid ⇒ Object
Returns the value of attribute sid.
Class Method Summary collapse
Instance Attribute Details
#from ⇒ Object
Returns the value of attribute from.
5 6 7 |
# File 'lib/sms.rb', line 5 def from @from end |
#secret ⇒ Object
Returns the value of attribute secret.
5 6 7 |
# File 'lib/sms.rb', line 5 def secret @secret end |
#sid ⇒ Object
Returns the value of attribute sid.
5 6 7 |
# File 'lib/sms.rb', line 5 def sid @sid end |
Class Method Details
.text(options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sms.rb', line 7 def self.text(={}) @sid = ENV.delete('TWILIO_ID') if ENV.key?('TWILIO_ID') @secret = ENV.delete('TWILIO_SECRET') if ENV.key?('TWILIO_SECRET') @from = ENV.delete('TWILIO_PHONE') if ENV.key?('TWILIO_PHONE') @from = [:from] if .key?(:from) return false if @from.nil? or @from == '' return false unless .key?(:message) return false unless .key?(:to) url = URI.parse "https://api.twilio.com/2010-04-01/Accounts/#{@sid}/SMS/Messages" http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(url.path) request.basic_auth @sid, @secret request.set_form_data({ 'From' => @from, 'To' => [:to], 'Body' => [:message], }) response = http.start do |http| http.request(request) end response.code[0..0] == '2' # eg, 2xx end |