var apn = require('apn');
var util = require('util');
var BasePushNotification = require('./BasePushNotification');
connection = new apn.Connection({
  cert: '',
  key: ''
}).on('error', console.log.bind(console.log)).on('transmissionError', console.log.bind(console.log));

util.inherits(APNPushNotification, BasePushNotification);

/**
 * Create new APN Push Notification
 * @param {Object} options
 * @returns {APNPushNotification}
 * @constructor
 */
function APNPushNotification(options) {
  BasePushNotification.apply(this, arguments);

  options = extend(true, {}, {
    device: '',
    notification: {
      aps: {
        alert: "\uD83D\uDCE7 \u2709 You have a new message",
        sound: 'ping.aiff',
        badge: 1
      },
      payload: {}
    }
  }, options);

  this.device = new apn.Device(options.device);
  this.notification = new apn.Notification(options.notification);
}

/**
 * Send push notification to device
 * @returns {APNPushNotification}
 */
APNPushNotification.prototype.send = function () {
  connection.pushNotification(this.notification, this.device);
  return this;
};

module.exports = APNPushNotification;

@@ -112,166 +112,8 @@
 n');
-%0Aconnection = new apn.Connection(%7B%0A  cert: '',%0A  key: ''%0A%7D).on('error', console.log.bind(console.log)).on('transmissionError', console.log.bind(console.log));
 %0A%0Aut
@@ -384,341 +384,457 @@
 %0A%0A  
-options = extend(true, %7B%7D, %7B%0A    device: '',%0A    notification: %7B%0A      aps: %7B%0A        alert: %22%5CuD83D%5CuDCE7 %5Cu2709 You have a new message%22,%0A        sound: 'ping.aiff',%0A        badge: 1%0A      %7D,%0A      payload: %7B%7D%0A    %7D%0A  %7D, options);%0A%0A  this.device = new apn.Device(options.device);%0A  this.notification = new apn.Notification(options.n
+this.setProvider(new apn.Connection(%7B%0A    cert: '',%0A    key: ''%0A  %7D));%0A%7D%0A%0A/**%0A * Create device instance%0A * @param %7BObject%7D config%0A * @returns %7B*%7D%0A * @private%0A */%0AAPNPushNotification.prototype._createDevice = function (config) %7B%0A  return new apn.Device(config);%0A%7D;%0A%0A/**%0A * Create notification instance%0A * @param %7BObject%7D config%0A * @returns %7B*%7D%0A * @private%0A */%0AAPNPushNotification.prototype._createNotification = function (config) %7B%0A  return new apn.N
 otif
@@ -840,20 +840,28 @@
 fication
+(config
 );%0A%7D
+;
 %0A%0A/**%0A *
@@ -989,23 +989,66 @@
 %7B%0A  
-connection.push
+this%0A    .getProvider()%0A    .pushNotification(this._create
 Noti
@@ -1061,16 +1061,27 @@
 on(this.
+getConfig('
 notifica
@@ -1088,24 +1088,61 @@
 tion
+'))
 , this.
+_createDevice(this.getConfig('
 device
+'))
 );%0A
+%0A
   re

Rewrite apn push a little bit