class EventMachine::ApnManager::Client

Constants

PORT
PRODUCTION_GATEWAY
SANDBOX_GATEWAY
TEST_GATEWAY

Attributes

cert[R]
close_callback[R]
connection[R]
environment[R]
error_callback[R]
gateway[R]
open_callback[R]
port[R]

Public Class Methods

connect(options = {}) click to toggle source

A convenience method for creating and connecting.

# File lib/em_apn_manager/client.rb, line 16
def self.connect(options = {})
  new(options).tap do |client|
    client.connect
  end
end
new(options = {}) click to toggle source
# File lib/em_apn_manager/client.rb, line 22
def initialize(options = {})
  @cert = options[:cert]
  @port = options[:port] || PORT
  @environment = options[:env] || "development"
  @gateway = options[:gateway]
  @gateway ||=  case @environment
                when "test"
                  TEST_GATEWAY
                when "development"
                  SANDBOX_GATEWAY
                when "production"
                  PRODUCTION_GATEWAY
                else
                  TEST_GATEWAY
                end
  @connection = nil
end

Public Instance Methods

connect() click to toggle source
# File lib/em_apn_manager/client.rb, line 40
def connect
  @connection = EM.connect(gateway, port, Connection, self)
end
connected?() click to toggle source
# File lib/em_apn_manager/client.rb, line 44
def connected?
  !connection.nil? && !connection.disconnected?
end
deliver(notification) click to toggle source
# File lib/em_apn_manager/client.rb, line 48
def deliver(notification)
  if !connected?
    puts "No connection."
    return
  end
  notification.validate!
  log(notification)
  connection.send_data(notification.data)
end
log(notification) click to toggle source
# File lib/em_apn_manager/client.rb, line 70
def log(notification)
  EM::ApnManager.logger.info("TOKEN=#{notification.token} PAYLOAD=#{notification.payload.inspect}")
end
on_close(&block) click to toggle source
# File lib/em_apn_manager/client.rb, line 62
def on_close(&block)
  @close_callback = block
end
on_error(&block) click to toggle source
# File lib/em_apn_manager/client.rb, line 58
def on_error(&block)
  @error_callback = block
end
on_open(&block) click to toggle source
# File lib/em_apn_manager/client.rb, line 66
def on_open(&block)
  @open_callback = block
end