Sha256: 74b02c5a8267a2c0b26f5499279bee4c465dbaa6c76e436152bf916c7135e0b1

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

module Eventboss
  class NotConfigured < StandardError; end

  class SnsClient
    def initialize(configuration)
      @configuration = configuration
    end

    def publish(payload)
      backend.publish(payload)
    end

    private

    attr_reader :configuration

    def backend
      if configured?
        options = {
          region: configuration.eventboss_region,
          credentials: ::Aws::Credentials.new(
            configuration.aws_access_key_id,
            configuration.aws_secret_access_key
          )
        }
        if configuration.aws_sns_endpoint
          options[:endpoint] = configuration.aws_sns_endpoint
        end
        Aws::SNS::Client.new(
          options
        )
      elsif configuration.raise_on_missing_configuration
        raise NotConfigured, 'Eventboss is not configured'
      else
        Mock.new
      end
    end

    def configured?
      !!(
        configuration.eventboss_region &&
        configuration.eventboss_account_id &&
        configuration.eventboss_app_name
      )
    end

    class Mock
      def publish(_)
        Eventboss.logger.info('Eventboss is not configured. Skipping message publishing!')
        return
      end
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
eventboss-1.3.1 lib/eventboss/sns_client.rb
eventboss-1.3.0 lib/eventboss/sns_client.rb
eventboss-1.2.1 lib/eventboss/sns_client.rb
eventboss-1.2.0 lib/eventboss/sns_client.rb
eventboss-1.1.3 lib/eventboss/sns_client.rb