Skip to content

Commit 9f9acd5

Browse files
author
Eric Koleda
committed
Address review comments.
1 parent b7d6b7e commit 9f9acd5

File tree

7 files changed

+35
-28
lines changed

7 files changed

+35
-28
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
node_modules/
22
*.log
3-
samples/**/Secrets.gs
3+
4+
# Don't commit the clasp configurations for samples.
45
samples/**/.clasp.json
6+
# Don't commit secrets files, used to hold client IDs and secrets without
7+
# needing to modify checked in code.
8+
samples/**/Secrets.gs

samples/WebApp/Callback.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<!--
2-
* Copyright 2016 Google Inc. All Rights Reserved.
2+
* Copyright 2018 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -34,7 +34,7 @@ <h1><?= title ?></h1>
3434

3535
<script>
3636
var email = '<?= email ?>';
37-
var isSignedIn = '<?= isSignedIn ?>' == 'true';
37+
var isSignedIn = '<?= isSignedIn ?>' === 'true';
3838
var error = '<?= error ?>';
3939

4040
var intercom = Intercom.getInstance();

samples/WebApp/Code.gs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
2-
* Copyright 2016 Google Inc. All Rights Reserved.
2+
* Copyright 2018 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -55,28 +55,25 @@ function signOut() {
5555
* Gets the user's GitHub profile.
5656
*/
5757
function getGitHubProfile() {
58-
var service = getGitHubService();
59-
if (!service.hasAccess()) {
60-
throw new Error('Error: Missing GitHub authorization.');
61-
}
62-
var url = 'https://api.github.com/user';
63-
var response = UrlFetchApp.fetch(url, {
64-
headers: {
65-
Authorization: 'Bearer ' + service.getAccessToken()
66-
}
67-
});
68-
return JSON.parse(response.getContentText());
58+
return getGitHubResource('user');
6959
}
7060

7161
/**
7262
* Gets the user's GitHub repos.
7363
*/
7464
function getGitHubRepos() {
65+
return getGitHubResource('user/repos');
66+
}
67+
68+
/**
69+
* Fetches the specified resource from the GitHub API.
70+
*/
71+
function getGitHubResource(resource) {
7572
var service = getGitHubService();
7673
if (!service.hasAccess()) {
7774
throw new Error('Error: Missing GitHub authorization.');
7875
}
79-
var url = 'https://api.github.com/user/repos';
76+
var url = 'https://api.github.com/' + resource;
8077
var response = UrlFetchApp.fetch(url, {
8178
headers: {
8279
Authorization: 'Bearer ' + service.getAccessToken()

samples/WebApp/JavaScript.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<!--
2-
* Copyright 2016 Google Inc. All Rights Reserved.
2+
* Copyright 2018 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,20 +17,24 @@
1717
/**
1818
* Create a wrapped version of google.script.run that
1919
* is adapted for Angular promises.
20+
* @see https://docs.angularjs.org/api/ng/service/$q
2021
*/
2122
var ScriptService = function($q) {
2223
var self = this;
2324
var promisify = function(key) {
2425
return function() {
2526
var args = arguments;
2627
return $q(function(resolve, reject) {
28+
// Call google.script.run with the specified method.
2729
google.script.run
2830
.withSuccessHandler(resolve)
2931
.withFailureHandler(reject)
32+
// Retrieve the method to run and then apply it to the arguments.
3033
[key].apply(google.script.run, args);
3134
});
3235
};
3336
};
37+
// For each method exposed in google.script.run, wrap it up in a promise.
3438
angular.forEach(google.script.run, function(_, key) {
3539
self[key] = promisify(key)
3640
});
@@ -52,7 +56,8 @@
5256
self.user = null;
5357
self.repos = null;
5458

55-
// Watch for changes to isSignedIn.
59+
// Watch for changes to the user's sign in status, and fetch their GitHub
60+
// data when they become signed in.
5661
$scope.$watch('sample.isSignedIn', function(isSignedIn) {
5762
if (isSignedIn) {
5863
script.getGitHubProfile().then(function(user) {

samples/WebApp/Page.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<!--
2-
* Copyright 2016 Google Inc. All Rights Reserved.
2+
* Copyright 2018 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -38,7 +38,7 @@
3838

3939
<script>
4040
var email = '<?= email ?>';
41-
var isSignedIn = '<?= isSignedIn ?>' == 'true';
41+
var isSignedIn = '<?= isSignedIn ?>' === 'true';
4242
</script>
4343
<?!= include('JavaScript') ?>
4444
</body>

samples/WebApp/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This sample web application connects to your GitHub account using the Apps
44
Script OAuth2 library and displays some information about the repositories you
55
own. It demonstrates some best practices for using this library in a web app.
66

7+
![Sample web app screenshot](screenshot.png)
8+
79
## Setup
810

911
You can easily setup your own copy of this sample using the
@@ -26,8 +28,7 @@ run `clasp login` before executing the commands below.
2628
GitHub developer console into those variables.
2729
1. Run the following commands:
2830
```sh
29-
clasp version "Initial version"
30-
clasp deploy 1 "Web App"
31+
clasp deploy
3132
```
3233
1. Copy the deployment ID from the command line and insert it into the
3334
following URL: `https://script.google.com/macros/s/<DEPLOYMENT_ID>/exec`.
@@ -40,8 +41,8 @@ to communicate between tabs / windows. Specifically, the callback page sends a
4041
message to the web app letting it know when the authorization flow has
4142
completed, so it can start updating its contents.
4243

43-
## AngularJS
44+
## Angular
4445

45-
This web app uses the [AngularJS 1 framework](https://angularjs.org/) to make it
46+
This web app uses the [Angular 1 framework](https://angularjs.org/) to make it
4647
easier to update the page dynamically. It's use is not required, and many
4748
other JavaScript frameworks would work just as well.

samples/WebApp/screenshot.png

32.5 KB
Loading

0 commit comments

Comments
 (0)