Sha256: 2087a5f8495f35a4fc2d16f2aa6cc152d259c875da238393ff580c4234078d42

Contents?: true

Size: 1.17 KB

Versions: 15

Compression:

Stored size: 1.17 KB

Contents

class BMC::SMS::Strategies::Amazon
  attr_reader :region, :access_key_id, :secret_access_key

  # rubocop:disable Layout/LineLength
  def initialize(region: nil, access_key_id: nil, secret_access_key: nil)
    @region            = region            || ENV["SNS_REGION"]            || ENV["AWS_REGION"]
    @access_key_id     = access_key_id     || ENV["SNS_ACCESS_KEY_ID"]     || ENV["AWS_ACCESS_KEY_ID"]
    @secret_access_key = secret_access_key || ENV["SNS_SECRET_ACCESS_KEY"] || ENV["AWS_SECRET_ACCESS_KEY"]
  end
  # rubocop:enable Layout/LineLength

  def client
    @client ||= Aws::SNS::Client.new(
      :region            => region,
      :access_key_id     => access_key_id,
      :secret_access_key => secret_access_key,
    )
  end

  def call(data)
    from = data[:from] || BMC::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

15 entries across 15 versions & 1 rubygems

Version Path
bmc-1.5.1 app/sms/bmc/sms/strategies/amazon.rb
bmc-1.5.0 app/sms/bmc/sms/strategies/amazon.rb
bmc-1.4.3 app/sms/bmc/sms/strategies/amazon.rb
bmc-1.4.2 app/sms/bmc/sms/strategies/amazon.rb
bmc-1.4.1 app/sms/bmc/sms/strategies/amazon.rb
bmc-1.4.0 app/sms/bmc/sms/strategies/amazon.rb
bmc-1.3.5 app/sms/bmc/sms/strategies/amazon.rb
bmc-1.3.4 app/sms/bmc/sms/strategies/amazon.rb
bmc-1.3.3 app/sms/bmc/sms/strategies/amazon.rb
bmc-1.3.2 app/sms/bmc/sms/strategies/amazon.rb
bmc-1.3.1 app/sms/bmc/sms/strategies/amazon.rb
bmc-1.3.0 app/sms/bmc/sms/strategies/amazon.rb
bmc-1.2.1 app/sms/bmc/sms/strategies/amazon.rb
bmc-1.2.0 app/sms/bmc/sms/strategies/amazon.rb
bmc-1.1.0 app/sms/bmc/sms/strategies/amazon.rb