Sha256: 8c71784f845379820c24c709d04f524aed29b51343989093846fd8b86c6455cf

Contents?: true

Size: 1.24 KB

Versions: 6

Compression:

Stored size: 1.24 KB

Contents

require 'json'

module Moromi
  module Aws
    module Sns
      module Message
        class Parameter
          # @param [Moromi::Aws::Sns::Message::Apns] apns
          # @param [Moromi::Aws::Sns::Message::Fcm] gcm
          def initialize(apns: nil, gcm: nil)
            @apns = apns
            @gcm = gcm
          end

          def to_hash
            {
              klass_name: self.class.name,
              apns: {name: @apns&.class&.name, data: @apns&.to_hash},
              gcm: {name: @gcm&.class&.name, data: @gcm&.to_hash}
            }
          end

          def to_json
            {
              'default': '',
              'APNS_SANDBOX': @apns&.to_message_json,
              'APNS': @apns&.to_message_json,
              'GCM': @gcm&.to_message_json
            }.compact.to_json
          end

          def self.build_from_hash(hash)
            apns_klass = hash.dig(:apns, :name)&.safe_constantize
            apns = apns_klass&.build_from_hash(hash.dig(:apns, :data).deep_symbolize_keys)

            gcm_klass = hash.dig(:gcm, :name)&.safe_constantize
            gcm = gcm_klass&.build_from_hash(hash.dig(:gcm, :data).deep_symbolize_keys)

            new(apns: apns, gcm: gcm)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
moromi-aws-sns-0.15.0 lib/moromi/aws/sns/message/parameter.rb
moromi-aws-sns-0.14.0 lib/moromi/aws/sns/message/parameter.rb
moromi-aws-sns-0.13.0 lib/moromi/aws/sns/message/parameter.rb
moromi-aws-sns-0.12.0 lib/moromi/aws/sns/message/parameter.rb
moromi-aws-sns-0.11.0 lib/moromi/aws/sns/message/parameter.rb
moromi-aws-sns-0.10.0 lib/moromi/aws/sns/message/parameter.rb