Sha256: 660d9a82223c1b3417655bccf9434626e09ff05201d5b225cc6403b509565e6d

Contents?: true

Size: 785 Bytes

Versions: 2

Compression:

Stored size: 785 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)
      message = message(text).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)
      {
        APNS: notification(text).to_json
      }
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aws_sns_manager-0.0.2.pre.alpha.pre.18 lib/aws_sns_manager/client.rb
aws_sns_manager-0.0.1.pre.alpha.pre.16 lib/aws_sns_manager/client.rb