Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return parsed objects instead of JSON string from plugin #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
46 changes: 0 additions & 46 deletions hooks/browser/after_prepare.js

This file was deleted.

18 changes: 0 additions & 18 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,4 @@
<hook type="after_plugin_install" src="hooks/ios/prerequisites.js"/>
</platform>

<!-- browser -->
<platform name="browser">
<js-module src="src/browser/GooglePlusProxy.js" name="GooglePlusProxy">
<clobbers target="GooglePlus" />
</js-module>
<config-file target="config.xml" parent="/*">
<feature name="GooglePlus">
<param name="onload" value="true" />
</feature>
<access origin="https://accounts.google.com/*" />
</config-file>

<preference name="WEB_APPLICATION_CLIENT_ID" />

<!-- after_prepare hook to populate APP_ID -->
<hook type="after_prepare" src="hooks/browser/after_prepare.js" />
</platform>

</plugin>
32 changes: 4 additions & 28 deletions src/android/GooglePlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@
*/
public class GooglePlus extends CordovaPlugin implements GoogleApiClient.OnConnectionFailedListener {

public static final String ACTION_IS_AVAILABLE = "isAvailable";
public static final String ACTION_LOGIN = "login";
public static final String ACTION_TRY_SILENT_LOGIN = "trySilentLogin";
public static final String ACTION_LOGOUT = "logout";
public static final String ACTION_DISCONNECT = "disconnect";
public static final String ACTION_GET_SIGNING_CERTIFICATE_FINGERPRINT = "getSigningCertificateFingerprint";
Expand All @@ -59,7 +57,7 @@ public class GooglePlus extends CordovaPlugin implements GoogleApiClient.OnConne
private final static String FIELD_TOKEN_EXPIRES_IN = "expires_in";
private final static String VERIFY_TOKEN_URL = "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=";

//String options/config object names passed in to login and trySilentLogin
//String options/config object names passed in to login
public static final String ARGUMENT_WEB_CLIENT_ID = "webClientId";
public static final String ARGUMENT_SCOPES = "scopes";
public static final String ARGUMENT_OFFLINE_KEY = "offline";
Expand Down Expand Up @@ -98,25 +96,14 @@ public void onActivityResult(ActivityResult result) {
public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {
this.savedCallbackContext = callbackContext;

if (ACTION_IS_AVAILABLE.equals(action)) {
final boolean available = true;
savedCallbackContext.success(toStatus("success", String.valueOf(available)));

} else if (ACTION_LOGIN.equals(action)) {
if (ACTION_LOGIN.equals(action)) {
//pass args into api client build
buildGoogleApiClient(args.optJSONObject(0));

// Tries to Log the user in
Log.i(TAG, "Trying to Log in!");
signIn();

} else if (ACTION_TRY_SILENT_LOGIN.equals(action)) {
//pass args into api client build
buildGoogleApiClient(args.optJSONObject(0));

Log.i(TAG, "Trying to do silent login!");
trySilentLogin();

} else if (ACTION_LOGOUT.equals(action)) {
Log.i(TAG, "Trying to logout!");
signOut();
Expand Down Expand Up @@ -215,23 +202,12 @@ private void signIn() {
this.signInActivityLauncher.launch(signInIntent);
}

/**
* Tries to log the user in silently using existing sign in result information
*/
private void trySilentLogin() {
ConnectionResult apiConnect = mGoogleApiClient.blockingConnect();

if (apiConnect.isSuccess()) {
handleSignInResult(Auth.GoogleSignInApi.silentSignIn(this.mGoogleApiClient).await());
}
}

/**
* Signs the user out from the client
*/
private void signOut() {
if (this.mGoogleApiClient == null) {
savedCallbackContext.error(toStatus("error", "Please use login or trySilentLogin before logging out"));
savedCallbackContext.error(toStatus("error", "Please use login before logging out"));
return;
}

Expand Down Expand Up @@ -259,7 +235,7 @@ public void onResult(Status status) {
*/
private void disconnect() {
if (this.mGoogleApiClient == null) {
savedCallbackContext.error(toStatus("error", "Please use login or trySilentLogin before disconnecting"));
savedCallbackContext.error(toStatus("error", "Please use login before disconnecting"));
return;
}

Expand Down
141 changes: 0 additions & 141 deletions src/browser/GooglePlusProxy.js

This file was deleted.

22 changes: 10 additions & 12 deletions www/GooglePlus.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
function GooglePlus() {
}

GooglePlus.prototype.isAvailable = function (callback) {
cordova.exec(callback, null, "GooglePlus", "isAvailable", []);
};
function makeCbWithProcessedResult(callback) {
return function processCallback(result) {
return callback.call(this, JSON.parse(result));
}
}

GooglePlus.prototype.login = function (options, successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, "GooglePlus", "login", [options]);
};

GooglePlus.prototype.trySilentLogin = function (options, successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, "GooglePlus", "trySilentLogin", [options]);
cordova.exec(makeCbWithProcessedResult(successCallback), makeCbWithProcessedResult(errorCallback), "GooglePlus", "login", [options]);
};

GooglePlus.prototype.logout = function (successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, "GooglePlus", "logout", []);
cordova.exec(makeCbWithProcessedResult(successCallback), makeCbWithProcessedResult(errorCallback), "GooglePlus", "logout", []);
};

GooglePlus.prototype.disconnect = function (successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, "GooglePlus", "disconnect", []);
cordova.exec(makeCbWithProcessedResult(successCallback), makeCbWithProcessedResult(errorCallback), "GooglePlus", "disconnect", []);
};

GooglePlus.prototype.getSigningCertificateFingerprint = function (successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, "GooglePlus", "getSigningCertificateFingerprint", []);
cordova.exec(makeCbWithProcessedResult(successCallback), makeCbWithProcessedResult(errorCallback), "GooglePlus", "getSigningCertificateFingerprint", []);
};

GooglePlus.install = function () {
Expand All @@ -34,4 +32,4 @@ GooglePlus.install = function () {
return window.plugins.googleplus;
};

cordova.addConstructor(GooglePlus.install);
cordova.addConstructor(GooglePlus.install);
8 changes: 0 additions & 8 deletions yarn.lock

This file was deleted.