Class: BMC::SMS::Strategies::Amazon

Inherits:
Object
  • Object
show all
Defined in:
app/sms/bmc/sms/strategies/amazon.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region: nil, access_key_id: nil, secret_access_key: nil) ⇒ Amazon

Returns a new instance of Amazon.



4
5
6
7
8
# File 'app/sms/bmc/sms/strategies/amazon.rb', line 4

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

Instance Attribute Details

#access_key_idObject (readonly)

Returns the value of attribute access_key_id.



2
3
4
# File 'app/sms/bmc/sms/strategies/amazon.rb', line 2

def access_key_id
  @access_key_id
end

#regionObject (readonly)

Returns the value of attribute region.



2
3
4
# File 'app/sms/bmc/sms/strategies/amazon.rb', line 2

def region
  @region
end

#secret_access_keyObject (readonly)

Returns the value of attribute secret_access_key.



2
3
4
# File 'app/sms/bmc/sms/strategies/amazon.rb', line 2

def secret_access_key
  @secret_access_key
end

Instance Method Details

#call(data) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/sms/bmc/sms/strategies/amazon.rb', line 18

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

#clientObject



10
11
12
13
14
15
16
# File 'app/sms/bmc/sms/strategies/amazon.rb', line 10

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