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.5.1 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.5.0 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.4.4 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.4.3 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.4.2 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.4.1 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.4.0 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.3.6 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.3.5 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.3.4 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.3.3 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.3.2 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.3.1 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.3.0 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.2.3 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.2.2 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.2.1 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.2.0 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.1.0 app/sms/agilibox/sms/strategies/amazon_sns.rb
agilibox-1.0.15 app/sms/agilibox/sms/strategies/amazon_sns.rb