Sha256: c7970f52a31629053c3acd19ed9179cf3ae496c41b423b15992873003da1609e

Contents?: true

Size: 1.25 KB

Versions: 3

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
        options[:credentials] = Aws::Credentials.new(access_key_id, secret_access_key) if access_key_id && secret_access_key
        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

3 entries across 3 versions & 1 rubygems

Version Path
eye-patch-1.1.0 lib/eye/notify/awssdk.rb
eye-patch-1.0.1 lib/eye/notify/awssdk.rb
eye-patch-1.0.0 lib/eye/notify/awssdk.rb