Sha256: 5764431fbeb58ca68eba6ad899775c138bdf4e750834e4bf75269b220a075bf8

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true
require "aws-sdk-core"

begin
  # aws-sdk gem version 2.x includes the SES code as a sub-module
  require "aws-sdk-core/ses"
rescue LoadError
  # aws-sdk gem version 3.x includes the SES code as a separate aws-sdk-ses gem
  require "aws-sdk-ses"
end

module Eye
  class Notify
    class AWSSDK < Eye::Notify
      param :region, String
      param :access_key_id, String
      param :secret_access_key, String
      param :from, String, true

      def execute
        options = { region: "us-east-1" } # default to us-east-1
        options[:region] = region if region
        if access_key_id && secret_access_key
          options[:credentials] = Aws::Credentials.new(access_key_id, secret_access_key)
        end
        client = Aws::SES::Client.new(options)
        client.send_email(message)
      end

      def message
        { source: from,
          destination: {
            to_addresses: [contact]
          },
          message: {
            subject: {
              data: message_subject
            },
            body: {
              text: {
                data: message_body
              },
              html: {
                data: message_body
              }
            }
          }
        }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eye-patch-0.5.1 lib/eye/notify/awssdk.rb
eye-patch-0.5.0 lib/eye/notify/awssdk.rb