Class: ActiveSMS::Backend::AWS

Inherits:
Base
  • Object
show all
Defined in:
lib/active_sms/backend/aws.rb

Overview

ActiveSMS backend class to send sms using amazon web services

Instance Method Summary collapse

Constructor Details

#initialize(access_key:, secret_access_key:, region: "us-east-1") ⇒ AWS

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

Parameters:

  • access_key (String)

    AWS access key

  • secret_access_key (String)

    AWS secret access key

  • region (String) (defaults to: "us-east-1")

    AWS region. Full list: goo.gl/Ys5XMi



13
14
15
16
17
# 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

Instance Method Details

#send_sms(phone, text) ⇒ Object

Sends sms using amazon web services



23
24
25
26
27
28
29
30
31
# 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