Sha256: 9b2f167f610776001dcded1febddd446cb08dc292725408f64ec1e2e2f731b4d

Contents?: true

Size: 1.25 KB

Versions: 40

Compression:

Stored size: 1.25 KB

Contents

class Agilibox::SMS::Strategies::AmazonSNS < Agilibox::SMS::Strategies::Base
  class << self
    attr_writer :sns_region

    def sns_region
      @sns_region ||= (ENV["SNS_REGION"] || ENV["AWS_REGION"])
    end

    attr_writer :sns_access_key_id

    def sns_access_key_id
      @sns_access_key_id ||= (ENV["SNS_ACCESS_KEY_ID"] || ENV["AWS_ACCESS_KEY_ID"])
    end

    attr_writer :sns_secret_access_key

    def sns_secret_access_key
      @sns_secret_access_key ||= (ENV["SNS_SECRET_ACCESS_KEY"] || ENV["AWS_SECRET_ACCESS_KEY"])
    end
  end # class << self

  def client
    @client ||= Aws::SNS::Client.new(
      :region            => self.class.sns_region,
      :access_key_id     => self.class.sns_access_key_id,
      :secret_access_key => self.class.sns_secret_access_key,
    )
  end

  private

  def call
    from = data[:from] || Agilibox::SMS.default_from

    client.publish(
      :phone_number       => data[:to],
      :message            => data[:body],
      :message_attributes => {
        "AWS.SNS.SMS.SenderID" => {
          :data_type    => "String",
          :string_value => from,
        },
        "AWS.SNS.SMS.SMSType"  => {
          :data_type    => "String",
          :string_value => "Transactional",
        },
      },
    )
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
agilibox-1.7.4 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.7.3 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.7.2 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.7.1 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.7.0 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.6.2 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.6.1 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.6.0 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.5.13 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.5.12 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.5.11 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.5.10 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.5.9 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.5.8 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.5.7 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.5.6 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.5.5 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.5.4 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.5.3 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.5.2 app/sms/agilibox/sms/strategies/amazon_sns.rb