Sha256: a51ec50d89c3016027b6901a5bfff8e080f8dc5276e8f89a5a24ca69352c5958

Contents?: true

Size: 1.87 KB

Versions: 4

Compression:

Stored size: 1.87 KB

Contents

module Moromi
  module Aws
    module Sns
      module Message
        class Apns < Base
          attr_reader :alert
          attr_reader :badge
          attr_reader :sound
          attr_reader :content_available
          attr_reader :mutable_content
          attr_reader :category
          attr_reader :priority
          attr_reader :type
          attr_reader :custom_data

          def initialize(alert:, badge:, sound: 'default', content_available: 1, mutable_content: 0, category: nil,
                         priority: 10, type: nil, custom_data: {})
            @alert = alert
            @badge = badge
            @sound = sound
            @content_available = content_available
            @mutable_content = mutable_content
            @category = category
            @priority = priority
            @type = type || self.class.name
            @custom_data = setup_initial_custom_data({type: @type}.merge(custom_data))
          end

          def to_hash
            {
              alert: @alert,
              badge: @badge,
              sound: @sound,
              content_available: @content_available,
              mutable_content: @mutable_content,
              category: @category,
              priority: @priority,
              type: @type,
              custom_data: @custom_data
            }
          end

          def to_message_json
            aps = to_hash
            %i[custom_data type].each { |k| aps.delete(k) }
            @custom_data.merge({aps: aps}).to_json
          end

          private

          def setup_initial_custom_data(custom_data)
            custom_data
          end

          class << self
            def build_silent_push_message(priority: 10, custom_data: {})
              new('', nil, sound: nil, content_available: 1, priority: priority, custom_data: custom_data)
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
moromi-aws-sns-0.10.0 lib/moromi/aws/sns/message/apns.rb
moromi-aws-sns-0.9.0 lib/moromi/aws/sns/message/apns.rb
moromi-aws-sns-0.8.0 lib/moromi/aws/sns/message/apns.rb
moromi-aws-sns-0.7.0 lib/moromi/aws/sns/message/apns.rb