Skip to content
This repository was archived by the owner on Apr 2, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@
"dependencies": {
"superagent": "1.7.2"
},
"peerDependencies": {
"@ionic-native/core": "^3.6.1",
"@ionic-native/device": "^3.6.1",
"@ionic-native/facebook": "^3.6.1",
"@ionic-native/google-plus": "^3.6.1",
"@ionic/db": "^0.1.0"
},
"devDependencies": {
"@ionic-native/core": "^3.6.1",
"@ionic-native/device": "^3.6.1",
"@ionic-native/facebook": "^3.6.1",
"@ionic-native/google-plus": "^3.6.1",
"babel-plugin-external-helpers": "^6.8.0",
"babel-preset-es2015": "^6.14.0",
"browserify": "^13.1.0",
Expand Down
6 changes: 5 additions & 1 deletion src/angular.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { Device as NativeDevice } from '@ionic-native/device';
import { Facebook } from '@ionic-native/facebook';
import { GooglePlus } from '@ionic-native/google-plus';

import { Container as DIContainer } from './di';
import { EventEmitter } from './events';
import { DeferredPromise } from './promise';
Expand All @@ -12,7 +16,7 @@ export function bootstrapAngular1() {
return; // No global angular--this is not an AngularJS project.
}

let container = new DIContainer();
let container = new DIContainer(new NativeDevice(), new Facebook(), new GooglePlus());

angular.element(document).ready(function() {
container.core.init();
Expand Down
36 changes: 31 additions & 5 deletions src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { Facebook, FacebookLoginResponse } from '@ionic-native/facebook';
import { GooglePlus } from '@ionic-native/google-plus';

import {
APIResponseErrorDetails,
AuthDependencies,
Expand Down Expand Up @@ -629,6 +632,13 @@ export abstract class NativeAuth {
* @featured
*/
export class GoogleAuth extends NativeAuth implements IGoogleAuth {
private googlePlus: GooglePlus;

constructor(deps: NativeAuthDependencies) {
super(deps);

this.googlePlus = deps.googlePlus;
}

public logout(): Promise<void> {
let deferred = new DeferredPromise<void, Error>();
Expand All @@ -639,7 +649,7 @@ export class GoogleAuth extends NativeAuth implements IGoogleAuth {
user.unstore();
user.clear();

window.plugins.googleplus.logout(() => {
this.googlePlus.logout().then( () => {
deferred.resolve();
}, (err) => {
deferred.reject(err);
Expand All @@ -655,6 +665,11 @@ export class GoogleAuth extends NativeAuth implements IGoogleAuth {
this.emitter.once('cordova:deviceready', () => {
let scope = ['profile', 'email'];

if (!this.googlePlus) {
deferred.reject(new Error('Ionic native is not installed'));
return;
}

if (!window || !window.cordova) {
deferred.reject(new Error('Cordova is missing'));
return;
Expand All @@ -678,7 +693,7 @@ export class GoogleAuth extends NativeAuth implements IGoogleAuth {
});
}

window.plugins.googleplus.login({'webClientId': authConfig.google.webClientId, 'offline': true, 'scopes': scope.join(' ')}, (success) => {
this.googlePlus.login({'webClientId': authConfig.google.webClientId, 'offline': true, 'scopes': scope.join(' ')}).then((success) => {
if (!success.serverAuthCode) {
deferred.reject(new Error('Failed to retrieve offline access token.'));
return;
Expand Down Expand Up @@ -720,6 +735,13 @@ export class GoogleAuth extends NativeAuth implements IGoogleAuth {
* @featured
*/
export class FacebookAuth extends NativeAuth implements IFacebookAuth {
private facebook: Facebook;

constructor(deps: NativeAuthDependencies) {
super(deps);

this.facebook = deps.facebook;
}

public logout(): Promise<void> {
let deferred = new DeferredPromise<void, Error>();
Expand All @@ -731,8 +753,7 @@ export class FacebookAuth extends NativeAuth implements IFacebookAuth {
user.clear();

// Clear the facebook auth.

window.facebookConnectPlugin.logout(() => {
this.facebook.logout().then( () => {
deferred.resolve();
}, (err) => {
deferred.reject(err);
Expand All @@ -755,6 +776,11 @@ export class FacebookAuth extends NativeAuth implements IFacebookAuth {
}

this.emitter.once('cordova:deviceready', () => {
if (!this.facebook) {
deferred.reject(new Error('Ionic native is not installed'));
return;
}

if (!window || !window.cordova) {
deferred.reject(new Error('Cordova is missing.'));
return;
Expand All @@ -765,7 +791,7 @@ export class FacebookAuth extends NativeAuth implements IFacebookAuth {
return;
}

window.facebookConnectPlugin.login(scope, (r: any) => {
this.facebook.login(scope).then((r: FacebookLoginResponse) => {
scope.splice(scope.indexOf('public_profile'), 1);
const request_object = {
'app_id': this.config.get('app_id'),
Expand Down
11 changes: 9 additions & 2 deletions src/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import { Facebook } from '@ionic-native/facebook';
import { GooglePlus } from '@ionic-native/google-plus';
import { Device as NativeDevice } from '@ionic-native/device';
import { IonicDBOptions } from '@ionic/db';

/**
* @hidden
*/
Expand Down Expand Up @@ -275,15 +280,15 @@ export interface DeviceIsConnectedToNetworkOptions {
* @hidden
*/
export interface DeviceDependencies {
nativeDevice: any;
nativeDevice: NativeDevice;
emitter: IEventEmitter;
}

/**
* @hidden
*/
export interface IDevice {
native: any;
native: NativeDevice;
type: string;

isAndroid(): boolean;
Expand Down Expand Up @@ -828,6 +833,8 @@ export interface NativeAuthDependencies {
storage: IStorage<string>;
tokenContext: ICombinedTokenContext;
emitter: IEventEmitter;
facebook: Facebook;
googlePlus: GooglePlus;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/device.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Device as NativeDevice } from '@ionic-native/device';

import {
DeviceDependencies,
DeviceIsConnectedToNetworkOptions,
Expand All @@ -12,9 +14,7 @@ declare var navigator: any;
* @hidden
*/
export class Device implements IDevice {

public native: any;

public native: NativeDevice;
public type: string;

/**
Expand Down
17 changes: 13 additions & 4 deletions src/di.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import { Device as NativeDevice } from '@ionic-native/device';
import { Facebook } from '@ionic-native/facebook';
import { GooglePlus } from '@ionic-native/google-plus';
import { IonicDBOptions } from '@ionic/db';

import {
AppStatus,
IAuth,
Expand Down Expand Up @@ -78,6 +83,7 @@ function cache<T>(target: any, propertyKey: string, descriptor: TypedPropertyDes
* @hidden
*/
export class Container {
constructor(private nativeDevice: NativeDevice, private facebook: Facebook, private googlePlus: GooglePlus) { }

@cache
public get appStatus(): AppStatus {
Expand Down Expand Up @@ -161,8 +167,7 @@ export class Container {

@cache
public get device(): IDevice {
const cordovaDevice = (window as any).device;
return new Device({'nativeDevice': cordovaDevice, 'emitter': this.eventEmitter});
return new Device({'nativeDevice': this.nativeDevice, 'emitter': this.eventEmitter});
}

@cache
Expand Down Expand Up @@ -225,7 +230,9 @@ export class Container {
'userService': this.singleUserService,
'storage': new Storage<string>({'strategy': this.localStorageStrategy}),
'tokenContext': this.authTokenContext,
'emitter': this.eventEmitter
'emitter': this.eventEmitter,
'facebook': this.facebook,
'googlePlus': this.googlePlus
});
}

Expand All @@ -237,7 +244,9 @@ export class Container {
'userService': this.singleUserService,
'storage': new Storage<string>({'strategy': this.localStorageStrategy}),
'tokenContext': this.authTokenContext,
'emitter': this.eventEmitter
'emitter': this.eventEmitter,
'facebook': this.facebook,
'googlePlus': this.googlePlus
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/insights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class Insights implements IInsights {
* @private
*/
protected shouldSubmit(): boolean {
return this.batch.length >= this.options.submitCount;
return this.batch.length >= (this.options.submitCount || 0);
}

/**
Expand Down