Class: Noticed::DeliveryMethods::Ios

Inherits:
Noticed::DeliveryMethod show all
Defined in:
lib/noticed/delivery_methods/ios.rb

Instance Attribute Summary

Attributes inherited from Noticed::DeliveryMethod

#config, #event, #notification

Instance Method Summary collapse

Methods inherited from Noticed::DeliveryMethod

#evaluate_option, #fetch_constant, #perform

Methods included from ApiClient

#post_request

Instance Method Details

#deliverObject



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

def deliver
  evaluate_option(:device_tokens).each do |device_token|
    apn = Apnotic::Notification.new(device_token)
    format_notification(apn)

    connection_pool = (!!evaluate_option(:development)) ? development_pool : production_pool
    connection_pool.with do |connection|
      response = connection.push(apn)
      raise "Timeout sending iOS push notification" unless response

      if bad_token?(response) && config[:invalid_token]
        # Allow notification to cleanup invalid iOS device tokens
        notification.instance_exec(device_token, &config[:invalid_token])
      elsif !response.ok?
        raise "Request failed #{response.body}"
      end
    end
  end
end