Sha256: 32d3c217798a1d2d7413f57300dc788278b68f9731f8b779810965df6c8fad4c

Contents?: true

Size: 919 Bytes

Versions: 1

Compression:

Stored size: 919 Bytes

Contents

module AwsSnsManager
  # = AwsSnsManager::Client
  class Client
    attr_accessor :client
    attr_accessor :arn

    def initialize(options = {})
      super()

      @client = Aws::SNS::Client.new(options)
    end

    def send(text = nil, options = {})
      message = message(text, options).to_json
      response = publish_rescue(message)
      !response.nil?
    end

    def publish_rescue(message)
      client.publish(
        target_arn: arn,
        message: message,
        message_structure: 'json'
      )
    end

    def message(text, options = {})
      json = notification(text, options).to_json
      {
        default: json,
        APNS: json
      }
    end

    def notification(text, options = {})
      base = {
        aps: {
          alert: text,
          sound: 'default',
          badge: 1,
          'content-available': 1
        }
      }
      base.merge(options)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aws_sns_manager-0.0.2.pre.alpha.pre.25 lib/aws_sns_manager/client.rb