Skip to content

Commit d19dff5

Browse files
committedJul 31, 2023
refactor(result): standardize result
1 parent 676b683 commit d19dff5

File tree

6 files changed

+84
-59
lines changed

6 files changed

+84
-59
lines changed
 

‎.github/workflows/main.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: cordova-plugin-googleplus-standard
4+
on: push
5+
6+
jobs:
7+
publish:
8+
runs-on: ubuntu-latest
9+
if: startsWith(github.ref, 'refs/tags/v')
10+
steps:
11+
- uses: actions/checkout@v1
12+
- uses: actions/setup-node@v1
13+
with:
14+
node-version: '18.x'
15+
- run: yarn
16+
- run: yarn build
17+
- uses: JS-DevTools/npm-publish@v1
18+
with:
19+
token: ${{ secrets.NPM_TOKEN }}

‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
22
.DS_Store
33
*.iml
4-
npm-debug.log
4+
npm-debug.log
5+
node_modules/

‎README.md

+26-30
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@
44
[![Downloads][downloads-image]][npm-url]
55
[![Twitter Follow][twitter-image]][twitter-url]
66

7-
[build-status]:https://travis-ci.org/EddyVerbruggen/cordova-plugin-googleplus.svg?branch=master
8-
[build-url]:https://travis-ci.org/EddyVerbruggen/cordova-plugin-googleplus
9-
[npm-image]:http://img.shields.io/npm/v/cordova-plugin-googleplus.svg
10-
[npm-url]:https://npmjs.org/package/cordova-plugin-googleplus
11-
[downloads-image]:http://img.shields.io/npm/dm/cordova-plugin-googleplus.svg
12-
[twitter-image]:https://img.shields.io/twitter/follow/eddyverbruggen.svg?style=social&label=Follow%20me
13-
[twitter-url]:https://twitter.com/eddyverbruggen
7+
[npm-image]:http://img.shields.io/npm/v/cordova-plugin-googleplus-standard.svg
8+
[npm-url]:https://npmjs.org/package/cordova-plugin-googleplus-standard
9+
[downloads-image]:http://img.shields.io/npm/dm/cordova-plugin-googleplus-standard.svg
1410

1511
> ⚠️ From plugin version 6.0.0 the minimum required cordova-ios version is 4.5.0. Need to use a lower cordova-ios version? Use plugin version 5.3.2 or lower.
1612
@@ -40,15 +36,15 @@ This plugin only wraps access to the Google Sign-In API. Further API access shou
4036

4137
Android
4238

43-
<img src="https://raw.githubusercontent.com/EddyVerbruggen/cordova-plugin-googleplus/master/screenshots/Android1.png" width="235" height="400"/>&nbsp;
44-
<img src="https://raw.githubusercontent.com/EddyVerbruggen/cordova-plugin-googleplus/master/screenshots/Android2.png" width="235" height="400"/>&nbsp;
45-
<img src="https://raw.githubusercontent.com/EddyVerbruggen/cordova-plugin-googleplus/master/screenshots/Android3.png" width="235" height="400"/>
39+
<img src="https://raw.githubusercontent.com/recifra/cordova-plugin-googleplus/master/screenshots/Android1.png" width="235" height="400"/>&nbsp;
40+
<img src="https://raw.githubusercontent.com/recifra/cordova-plugin-googleplus/master/screenshots/Android2.png" width="235" height="400"/>&nbsp;
41+
<img src="https://raw.githubusercontent.com/recifra/cordova-plugin-googleplus/master/screenshots/Android3.png" width="235" height="400"/>
4642

4743
iOS
4844

49-
<img src="https://raw.githubusercontent.com/EddyVerbruggen/cordova-plugin-googleplus/master/screenshots/iOS1.png" width="235" height="417"/>&nbsp;
50-
<img src="https://raw.githubusercontent.com/EddyVerbruggen/cordova-plugin-googleplus/master/screenshots/iOS2.png" width="235" height="417"/>&nbsp;
51-
<img src="https://raw.githubusercontent.com/EddyVerbruggen/cordova-plugin-googleplus/master/screenshots/iOS3.png" width="235" height="417"/>&nbsp;
45+
<img src="https://raw.githubusercontent.com/recifra/cordova-plugin-googleplus/master/screenshots/iOS1.png" width="235" height="417"/>&nbsp;
46+
<img src="https://raw.githubusercontent.com/recifra/cordova-plugin-googleplus/master/screenshots/iOS2.png" width="235" height="417"/>&nbsp;
47+
<img src="https://raw.githubusercontent.com/recifra/cordova-plugin-googleplus/master/screenshots/iOS3.png" width="235" height="417"/>&nbsp;
5248

5349
## 3. Google API setup
5450
To communicate with Google you need to do some tedious setup, sorry.
@@ -114,15 +110,15 @@ This plugin is compatible with:
114110

115111
Here's how it works (backup your project first!):
116112

117-
Using the Cordova CLI and [npm](https://www.npmjs.com/package/cordova-plugin-googleplus):
113+
Using the Cordova CLI and [npm](https://www.npmjs.com/package/cordova-plugin-googleplus-standard):
118114
```
119-
$ cordova plugin add cordova-plugin-googleplus --save --variable REVERSED_CLIENT_ID=myreversedclientid --variable WEB_APPLICATION_CLIENT_ID=mywebapplicationclientid
115+
$ cordova plugin add cordova-plugin-googleplus-standard --save --variable REVERSED_CLIENT_ID=myreversedclientid --variable WEB_APPLICATION_CLIENT_ID=mywebapplicationclientid
120116
$ cordova prepare
121117
```
122118

123-
Using the Cordova CLI to fetch the latest version from GitHub:
119+
Using the Cordova CLI to fetch the latest version from GitHub (not recommended):
124120
```
125-
$ cordova plugin add https://github.com/EddyVerbruggen/cordova-plugin-googleplus --save --variable REVERSED_CLIENT_ID=myreversedclientid --variable WEB_APPLICATION_CLIENT_ID=mywebapplicationclientid
121+
$ cordova plugin add https://github.com/recifra/cordova-plugin-googleplus --save --variable REVERSED_CLIENT_ID=myreversedclientid --variable WEB_APPLICATION_CLIENT_ID=mywebapplicationclientid
126122
$ cordova prepare
127123
```
128124

@@ -155,15 +151,15 @@ Add this to your config.xml:
155151

156152
For the (stable) NPM Version:
157153
```xml
158-
<plugin name="cordova-plugin-googleplus" source="npm">
154+
<plugin name="cordova-plugin-googleplus-standard" source="npm">
159155
<variable name="REVERSED_CLIENT_ID" value="myreversedclientid" />
160156
<variable name="WEB_APPLICATION_CLIENT_ID" value="mywebapplicationclientid" />
161157
</plugin>
162158
```
163159

164160
For the latest version from Git (not recommended):
165161
```xml
166-
<plugin spec="https://github.com/EddyVerbruggen/cordova-plugin-googleplus.git" source="git">
162+
<plugin spec="https://github.com/recifra/cordova-plugin-googleplus.git" source="git">
167163
<variable name="REVERSED_CLIENT_ID" value="myreversedclientid" />
168164
<variable name="WEB_APPLICATION_CLIENT_ID" value="mywebapplicationclientid" />
169165
<plugin>
@@ -221,18 +217,18 @@ window.plugins.googleplus.login(
221217
'webClientId': 'client id of the web app/server side', // optional clientId of your Web application from Credentials settings of your project - On Android, this MUST be included to get an idToken. On iOS, it is not required.
222218
'offline': true // optional, but requires the webClientId - if set to true the plugin will also return a serverAuthCode, which can be used to grant offline access to a non-Google server
223219
},
224-
function (obj) {
225-
alert(JSON.stringify(obj)); // do something useful instead of alerting
220+
function (json) {
221+
alert(json); // do something useful instead of alerting
226222
},
227-
function (msg) {
228-
alert('error: ' + msg);
223+
function (json) {
224+
alert('error: ' + json);
229225
}
230226
);
231227
```
232228

233-
The success callback (second argument) gets a JSON object with the following contents, with example data of my Google account:
229+
The success callback (second argument) gets a JSON string with the following contents, with example data of my Google account:
234230
```javascript
235-
obj.email // 'eddyverbruggen@gmail.com'
231+
obj.email // 'recifra@gmail.com'
236232
obj.userId // user id
237233
obj.displayName // 'Eddy Verbruggen'
238234
obj.familyName // 'Verbruggen'
@@ -245,16 +241,16 @@ The success callback (second argument) gets a JSON object with the following con
245241

246242
Additional user information is available by use case. Add the scopes needed to the scopes option then return the info to the result object being created in the `handleSignInResult` and `didSignInForUser` functions on Android and iOS, respectively.
247243

248-
On Android, the error callback (third argument) receives an error status code if authentication was not successful. A description of those status codes can be found on Google's android developer website at [GoogleSignInStatusCodes](https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInStatusCodes).
244+
On Android, the error callback (third argument) receives an JSON string with error status and code into message if authentication was not successful. A description of those status codes can be found on Google's android developer website at [GoogleSignInStatusCodes](https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInStatusCodes).
249245

250246
On iOS, the error callback will include an [NSError localizedDescription](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSError_Class/).
251247

252248
### logout
253249
This will clear the OAuth2 token.
254250
``` javascript
255251
window.plugins.googleplus.logout(
256-
function (msg) {
257-
alert(msg); // do something useful instead of alerting
252+
function (json) {
253+
alert(json); // do something useful instead of alerting
258254
}
259255
);
260256
```
@@ -263,8 +259,8 @@ window.plugins.googleplus.logout(
263259
This will clear the OAuth2 token, forget which account was used to login, and disconnect that account from the app. This will require the user to allow the app access again next time they sign in. Be aware that this effect is not always instantaneous. It can take time to completely disconnect.
264260
``` javascript
265261
window.plugins.googleplus.disconnect(
266-
function (msg) {
267-
alert(msg); // do something useful instead of alerting
262+
function (json) {
263+
alert(json); // do something useful instead of alerting
268264
}
269265
);
270266
```

‎package.json

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
2-
"version": "8.5.2",
3-
"name": "cordova-plugin-googleplus",
2+
"version": "9.0.0",
3+
"name": "cordova-plugin-googleplus-standard",
44
"cordova_name": "Google SignIn",
55
"description": "Use your Google account to authenticate with the app.",
66
"license": "MIT",
77
"repository": {
88
"type": "git",
9-
"url": "https://github.com/EddyVerbruggen/cordova-plugin-googleplus.git"
9+
"url": "https://github.com/recifra/cordova-plugin-googleplus.git"
1010
},
1111
"bugs": {
12-
"url": "https://github.com/EddyVerbruggen/cordova-plugin-googleplus/issues"
12+
"url": "https://github.com/recifra/cordova-plugin-googleplus/issues"
1313
},
14-
"homepage": "https://github.com/EddyVerbruggen/cordova-plugin-googleplus#readme",
14+
"homepage": "https://github.com/recifra/cordova-plugin-googleplus#readme",
1515
"keywords": [
1616
"Google",
1717
"Google SignIn",
@@ -33,11 +33,5 @@
3333
],
3434
"dependencies": {
3535
"q": "*"
36-
},
37-
"engines": [
38-
{
39-
"name": "cordova",
40-
"version": ">=3.5.0"
41-
}
42-
]
36+
}
4337
}

‎src/android/GooglePlus.java

+23-16
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public boolean execute(String action, CordovaArgs args, CallbackContext callback
9999
this.savedCallbackContext = callbackContext;
100100

101101
if (ACTION_IS_AVAILABLE.equals(action)) {
102-
final boolean avail = true;
103-
savedCallbackContext.success("" + avail);
102+
final boolean available = true;
103+
savedCallbackContext.success(toStatus("success", String.valueOf(available)));
104104

105105
} else if (ACTION_LOGIN.equals(action)) {
106106
//pass args into api client build
@@ -231,7 +231,7 @@ private void trySilentLogin() {
231231
*/
232232
private void signOut() {
233233
if (this.mGoogleApiClient == null) {
234-
savedCallbackContext.error("Please use login or trySilentLogin before logging out");
234+
savedCallbackContext.error(toStatus("error", "Please use login or trySilentLogin before logging out"));
235235
return;
236236
}
237237

@@ -244,9 +244,9 @@ private void signOut() {
244244
public void onResult(Status status) {
245245
//on success, tell cordova
246246
if (status.isSuccess()) {
247-
savedCallbackContext.success("Logged user out");
247+
savedCallbackContext.success(toStatus("success", "Logged user out"));
248248
} else {
249-
savedCallbackContext.error(status.getStatusCode());
249+
savedCallbackContext.error(toStatus("error", String.valueOf(status.getStatusCode())));
250250
}
251251
}
252252
}
@@ -259,7 +259,7 @@ public void onResult(Status status) {
259259
*/
260260
private void disconnect() {
261261
if (this.mGoogleApiClient == null) {
262-
savedCallbackContext.error("Please use login or trySilentLogin before disconnecting");
262+
savedCallbackContext.error(toStatus("error", "Please use login or trySilentLogin before disconnecting"));
263263
return;
264264
}
265265

@@ -271,9 +271,9 @@ private void disconnect() {
271271
@Override
272272
public void onResult(Status status) {
273273
if (status.isSuccess()) {
274-
savedCallbackContext.success("Disconnected user");
274+
savedCallbackContext.success(toStatus("success", "Disconnected user"));
275275
} else {
276-
savedCallbackContext.error(status.getStatusCode());
276+
savedCallbackContext.error(toStatus("error", String.valueOf(status.getStatusCode())));
277277
}
278278
}
279279
}
@@ -289,7 +289,7 @@ public void onResult(Status status) {
289289
@Override
290290
public void onConnectionFailed(ConnectionResult result) {
291291
Log.i(TAG, "Unresolvable failure in connecting to Google APIs");
292-
savedCallbackContext.error(result.getErrorCode());
292+
savedCallbackContext.error(toStatus("error", String.valueOf(result.getErrorCode())));
293293
}
294294

295295

@@ -312,12 +312,12 @@ public void onConnectionFailed(ConnectionResult result) {
312312
*/
313313
private void handleSignInResult(final GoogleSignInResult signInResult) {
314314
if (this.mGoogleApiClient == null) {
315-
savedCallbackContext.error("GoogleApiClient was never initialized");
315+
savedCallbackContext.error(toStatus("error", "GoogleApiClient was never initialized"));
316316
return;
317317
}
318318

319319
if (signInResult == null) {
320-
savedCallbackContext.error("SignInResult is null");
320+
savedCallbackContext.error(toStatus("error", "SignInResult is null"));
321321
return;
322322
}
323323

@@ -327,7 +327,7 @@ private void handleSignInResult(final GoogleSignInResult signInResult) {
327327
Log.i(TAG, "Wasn't signed in");
328328

329329
//Return the status code to be handled client side
330-
savedCallbackContext.error(signInResult.getStatus().getStatusCode());
330+
savedCallbackContext.error(toStatus("error", String.valueOf(signInResult.getStatus().getStatusCode())));
331331
} else {
332332
new AsyncTask<Void, Void, Void>() {
333333
@Override
@@ -349,9 +349,9 @@ protected Void doInBackground(Void... params) {
349349
result.put("familyName", acct.getFamilyName());
350350
result.put("givenName", acct.getGivenName());
351351
result.put("imageUrl", acct.getPhotoUrl());
352-
savedCallbackContext.success(result);
352+
savedCallbackContext.success(result.toString());
353353
} catch (Exception e) {
354-
savedCallbackContext.error("Trouble obtaining result, error: " + e.getMessage());
354+
savedCallbackContext.error(toStatus("error", "Trouble obtaining result, error: " + e.getMessage()));
355355
}
356356
return null;
357357
}
@@ -383,11 +383,11 @@ private void getSigningCertificateFingerprint() {
383383
// strip the last ':'
384384
strResult = strResult.substring(0, strResult.length()-1);
385385
strResult = strResult.toUpperCase();
386-
this.savedCallbackContext.success(strResult);
386+
this.savedCallbackContext.success(toStatus("success", strResult));
387387

388388
} catch (Exception e) {
389389
e.printStackTrace();
390-
savedCallbackContext.error(e.getMessage());
390+
savedCallbackContext.error(toStatus("error", e.getMessage()));
391391
}
392392
}
393393

@@ -448,4 +448,11 @@ public static String fromStream(InputStream is) throws IOException {
448448
reader.close();
449449
return sb.toString();
450450
}
451+
452+
public static String toStatus(String status, String message) {
453+
JSONObject jsonResponse = new JSONObject();
454+
jsonResponse.put("status", status);
455+
jsonResponse.put("message", message);
456+
return jsonResponse.toString();
457+
}
451458
}

‎yarn.lock

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
q@*:
6+
version "1.5.1"
7+
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
8+
integrity sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw==

0 commit comments

Comments
 (0)
Please sign in to comment.