import Kinvey from 'kinvey-javascript-sdk-core';
import { KinveyError } from 'kinvey-javascript-sdk-core/es5/errors';
import { NetworkRack } from 'kinvey-javascript-sdk-core/es5/rack/rack';
import { HttpMiddleware } from 'kinvey-javascript-sdk-core/es5/rack/middleware/http';
import { PhoneGapHttpMiddleware } from './http';
import { PhoneGapPush } from './push';
import { PhoneGapPopup } from './popup';
import { PhoneGapDevice } from './device';

// Add Http middleware
const networkRack = NetworkRack.sharedInstance();
networkRack.swap(HttpMiddleware, new PhoneGapHttpMiddleware());

// Extend the Kinvey class
class PhoneGapKinvey extends Kinvey {
  static init(options) {
    if (PhoneGapDevice.isPhoneGap()) {
      const onDeviceReady = () => {
        document.removeEventListener('deviceready', onDeviceReady);

        if (typeof global.device === 'undefined') {
          throw new KinveyError('Cordova Device Plugin is not installed.',
            'Please refer to http://devcenter.kinvey.com/phonegap-v3.0/guides/push#ProjectSetUp for help with'
            + ' setting up your project.');
        }
      };

      document.addEventListener('deviceready', onDeviceReady, false);
    }

    // Initialize Kinvey
    const client = super.init(options);

    // Add Push module to Kinvey
    this.Push = new PhoneGapPush();

    // Return the client
    return client;
  }
}

// Expose some globals
global.KinveyDevice = PhoneGapDevice;
global.KinveyPopup = PhoneGapPopup;

// Export
module.exports = PhoneGapKinvey;

@@ -587,99 +587,58 @@
 %0A// 
-Extend the Kinvey class%0Aclass PhoneGapKinvey extends Kinvey %7B%0A  static init(options) %7B%0A    
+Check that the cordova device plugin is installed%0A
 if (
@@ -668,20 +668,16 @@
 ap()) %7B%0A
-    
   const 
@@ -700,20 +700,16 @@
 () =%3E %7B%0A
-    
     docu
@@ -769,20 +769,16 @@
 );%0A%0A    
- 
-   
 if (type
@@ -819,20 +819,16 @@
 %7B%0A      
-   
- 
 throw ne
@@ -884,20 +884,16 @@
 lled.',%0A
-    
         
@@ -999,20 +999,16 @@
         
-  
-  
 + ' sett
@@ -1039,28 +1039,16 @@
     
-    %7D%0A    
+%7D%0A
   %7D;%0A%0A
-    
   do
@@ -1109,22 +1109,108 @@
 false);%0A
-    %7D%0A
+%7D%0A%0A// Extend the Kinvey class%0Aclass PhoneGapKinvey extends Kinvey %7B%0A  static init(options) %7B
 %0A    // 

Check if the cordova device plugin is installed outside of init