class ActiveSMS::Backend::AWS

ActiveSMS backend class to send sms using amazon web services

Public Class Methods

new(access_key:, secret_access_key:, region: "us-east-1") click to toggle source

To use class, you need access key from AWS. Go to README for instructions on how to obtain them.

@param access_key [String] AWS access key @param secret_access_key [String] AWS secret access key @param region [String] AWS region. Full list: goo.gl/Ys5XMi

# File lib/active_sms/backend/aws.rb, line 13
def initialize(access_key:, secret_access_key:, region: "us-east-1")
  @access_key = access_key
  @secret_access_key = secret_access_key
  @region = region
end

Public Instance Methods

send_sms(phone, text) click to toggle source

Sends sms using amazon web services

@phone [String] Phone number in E.164 format @text [String] Sms text

# File lib/active_sms/backend/aws.rb, line 23
def send_sms(phone, text)
  resp = sns_client.publish(phone_number: phone, message: text)

  if resp.error.nil? && resp.message_id
    respond_with_status :success
  else
    respond_with_status :unknown_failure
  end
end

Protected Instance Methods

sns_client() click to toggle source
# File lib/active_sms/backend/aws.rb, line 35
def sns_client
  Aws::SNS::Client.new(
    access_key_id: @access_key,
    secret_access_key: @secret_access_key,
    region: @region
  )
end