module SmsSenderTwilio

Constants

VERSION

Public Class Methods

client(credentials) click to toggle source
# File lib/sms_sender_twilio.rb, line 10
def self.client(credentials)
  @client ||= Twilio::REST::Client.new credentials['account_sid'], credentials['auth_token']
  @client.http_client.adapter = :typhoeus
  return @client
end
query_sms(credentials, message_sid, options = nil) click to toggle source
# File lib/sms_sender_twilio.rb, line 35
def self.query_sms(credentials, message_sid, options = nil)
  response = client(credentials).api.account.messages(message_sid).fetch
  return_hash = {
    'status' => response.status,
    'date_created' => response.date_created,
    'date_sent' => response.date_sent,
    'date_updated' => response.date_updated,
    'error_code' => response.error_code,
    'error_message' => response.error_message,
  }
  return return_hash
end
send_sms(credentials, mobile_number, message, sender, options = nil) click to toggle source

According to documentation:

# File lib/sms_sender_twilio.rb, line 17
def self.send_sms(credentials, mobile_number, message, sender, options = nil)
  mobile_number_normalized = SmsSenderTwilio::Normalizer.normalize_number_e_164(mobile_number)
  sender_normalized = SmsSenderTwilio::Normalizer.normalize_number_e_164(sender)
  message_normalized = SmsSenderTwilio::Normalizer.normalize_message(message)
  response = client(credentials).api.account.messages.create({
    :from => sender_normalized, 
    :to => mobile_number_normalized, 
    :body => message_normalized,
  })
  if response.respond_to?(:sid)
    return { message_id: response.sid, code: 0 }
  else
    result = {error: response.error_message, code: error_code}
    raise result[:error]
    return result
  end
end
supported_methods() click to toggle source
# File lib/sms_sender_twilio.rb, line 6
def self.supported_methods 
  ['send_sms', 'query_sms']
end