Class: Noticed::DeliveryMethods::Ios

Inherits:
Base
  • Object
show all
Defined in:
lib/noticed/delivery_methods/ios.rb

Instance Attribute Summary

Attributes inherited from Base

#recipient, #record

Instance Method Summary collapse

Methods inherited from Base

#clear_recipient, deliver, deliver_by, deliver_later, #deliver_later, inherited, #initialize, param, params, #params, with

Methods included from Translation

#class_scope, #i18n_scope, #scope_translation_key, #translate

Constructor Details

This class inherits a constructor from Noticed::Base

Instance Method Details

#deliverObject

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/noticed/delivery_methods/ios.rb', line 8

def deliver
  raise ArgumentError, "bundle_identifier is missing" if bundle_identifier.blank?
  raise ArgumentError, "key_id is missing" if key_id.blank?
  raise ArgumentError, "team_id is missing" if team_id.blank?
  raise ArgumentError, "Could not find APN cert at '#{cert_path}'" unless valid_cert_path?

  device_tokens.each do |device_token|
    connection_pool.with do |connection|
      apn = Apnotic::Notification.new(device_token)
      format_notification(apn)

      response = connection.push(apn)
      raise "Timeout sending iOS push notification" unless response

      if bad_token?(response)
        # Allow notification to cleanup invalid iOS device tokens
        cleanup_invalid_token(device_token)
      elsif !response.ok?
        raise "Request failed #{response.body}"
      end
    end
  end
end