Class: ActionPushNative::Service::Apns::ApnoticLegacyConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/action_push_native/service/apns/apnotic_legacy_converter.rb

Overview

Converts the legacy apple_data format from the Apnotic gem to the new format expected by the APNs API.

Temporary compatibility layer: It will be removed in the next release.

Constant Summary collapse

APS_FIELDS =
i[
  alert badge sound content_available category url_args mutable_content thread_id
  target_content_id interruption_level relevance_score
  stale_date content_state timestamp event dismissal_date
].freeze
APNS_HEADERS =
i[ expiration priority topic push_type ]

Class Method Summary collapse

Class Method Details

.convert(apple_data) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/action_push_native/service/apns/apnotic_legacy_converter.rb', line 15

def self.convert(apple_data)
  apple_data.each_with_object({}) do |(key, value), converted|
    if key.in?(APS_FIELDS)
      converted[:aps] ||= {}
      converted_key = key.to_s.dasherize.to_sym
      converted[:aps][converted_key] = value
      ActionPushNative.deprecator.warn("Passing the `#{key}` field directly is deprecated. Please use `.with_apple(aps: { \"#{converted_key}\": ... })` instead.")
    elsif key.in?(APNS_HEADERS)
      converted_key = "apns-#{key.to_s.dasherize}".to_sym
      converted[converted_key] = value
      ActionPushNative.deprecator.warn("Passing the `#{key}` header directly is deprecated. Please use `.with_apple(\"#{converted_key}\": ...)` instead.")
    elsif key == :apns_collapse_id
      converted_key = key.to_s.dasherize.to_sym
      converted[converted_key] = value
      ActionPushNative.deprecator.warn("Passing the `#{key}` header directly is deprecated. Please use `.with_apple(\"#{converted_key}\": ...)` instead.")
    elsif key == :custom_payload
      converted.merge!(value)
      ActionPushNative.deprecator.warn("Passing `custom_payload` is deprecated. Please use `.with_apple(#{value})` instead.")
    else
      converted[key] = value
    end
  end
end