Class: ActionPushNative::Service::Apns

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

Defined Under Namespace

Classes: ApnoticLegacyConverter, HttpxSession, TokenProvider

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Apns

Returns a new instance of Apns.



8
9
10
# File 'lib/action_push_native/service/apns.rb', line 8

def initialize(config)
  @config = config
end

Instance Method Details

#push(notification) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/action_push_native/service/apns.rb', line 12

def push(notification)
  notification.apple_data = ApnoticLegacyConverter.convert(notification.apple_data) if notification.apple_data.present?

  headers, payload = headers_from(notification), payload_from(notification)
  Rails.logger.info("Pushing APNs notification: #{headers[:"apns-id"]}")
  response = httpx_session.post("3/device/#{notification.token}", json: payload, headers: headers)
  handle_error(response) if response.error
end