Class: Pling::APN::Gateway
Overview
Pling gateway to communicate with Apple's Push Notification service.
This gateway handles these device types:
:apple, :apn, :ios, :ipad, :iphone, :ipod
Configure it by providing the path to your certificate:
Pling::APN::Gateway.new({
:certificate => '/path/to/certificate.pem', # Required
:host => 'gateway.sandbox.push.apple.com' # Optional
})
Instance Method Summary (collapse)
-
- (Object) deliver!(message, device)
Sends the given message to the given device without using the middleware.
-
- (Gateway) initialize(configuration)
constructor
Initializes a new gateway to Apple's Push Notification service.
-
- (Object) setup!
Establishes a new connection if connection is not available or closed.
Methods inherited from Gateway
#deliver, discover, handled_types, handles, #handles?, #teardown!
Constructor Details
- (Gateway) initialize(configuration)
Initializes a new gateway to Apple's Push Notification service
30 31 32 33 34 |
# File 'lib/pling/apn/gateway.rb', line 30 def initialize(configuration) super require_configuration(:certificate) setup! end |
Instance Method Details
- (Object) deliver!(message, device)
Sends the given message to the given device without using the middleware.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pling/apn/gateway.rb', line 47 def deliver!(, device) data = { :aps => { :alert => .body, :badge => .badge && .badge.to_i, :sound => .sound }.delete_if { |_, value| value.nil? } } data.merge!(.payload) if configuration[:payload] && .payload data = data.to_json if data.bytesize > 256 raise Pling::DeliveryFailed.new( "Payload size of #{data.bytesize} exceeds allowed size of 256 bytes.", , device) end token = [device.identifier].pack('H*') connection.write([0, token.bytesize, token, data.bytesize, data].pack('cna*na*')) end |
- (Object) setup!
Establishes a new connection if connection is not available or closed
38 39 40 |
# File 'lib/pling/apn/gateway.rb', line 38 def setup! connection.reopen if connection.closed? end |