class BMO::APNS::Client

APNS Client Class

@!attribute gateway_host @!attribute gateway_port @!attribute feedback_host @!attribute feedback_port @!attribute cert_path @!attribute cert_pass

Attributes

cert_pass[R]
cert_path[R]
feedback_host[R]
feedback_port[R]
gateway_host[R]
gateway_port[R]

Public Class Methods

new(gateway_host, gateway_port, feedback_host, feedback_port, options = {}) click to toggle source

The constructor of the Client object

it will only use a ssl connection if you pass a cert_path option

@param gateway_host [String] @param gateway_port [Integer] @param feedback_host [String] @param feedback_port [Integer]

@options options [String] :cert_pass @options options [String] :cert_path path to certificate file

# File lib/bmo/apns/client.rb, line 27
def initialize(gateway_host,  gateway_port,
               feedback_host, feedback_port,
               options = {})
  @gateway_host  = gateway_host
  @gateway_port  = gateway_port
  @feedback_host = feedback_host
  @feedback_port = feedback_port
  @cert_path     = options[:cert_path]
  @cert_pass     = options[:cert_pass]
end

Public Instance Methods

feedback() click to toggle source

Get the Feedback from Apple

@return <Array> A feedback tuple contains the time

when Apple determined that the app no longer exists on the device,
and a the token of device token
# File lib/bmo/apns/client.rb, line 53
def feedback
  connection = APNS::Connection.new(@feedback_host, @feedback_port,
                                    @cert_path,     @cert_pass)
  connection.connect do |socket|
    feedback_tuples = []
    while (data = socket.read(38))
      tuple = data.unpack('N1n1H*')
      feedback_tuples << FeedbackTuple.new(tuple[0], tuple[2])
    end
    feedback_tuples
  end
end
send_notification(notification) click to toggle source

@param notification [Notification] the notification to send to Apple

# File lib/bmo/apns/client.rb, line 40
def send_notification(notification)
  connection = APNS::Connection.new(@gateway_host, @gateway_port,
                                    @cert_path,    @cert_pass)
  connection.connect do |socket|
    socket.write(notification.to_package)
  end
end