Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Koleda committed Aug 1, 2018
1 parent b7d6b7e commit 9f9acd5
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 28 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
node_modules/
*.log
samples/**/Secrets.gs

# Don't commit the clasp configurations for samples.
samples/**/.clasp.json
# Don't commit secrets files, used to hold client IDs and secrets without
# needing to modify checked in code.
samples/**/Secrets.gs
6 changes: 3 additions & 3 deletions samples/WebApp/Callback.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!--
* Copyright 2016 Google Inc. All Rights Reserved.
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -34,7 +34,7 @@ <h1><?= title ?></h1>

<script>
var email = '<?= email ?>';
var isSignedIn = '<?= isSignedIn ?>' == 'true';
var isSignedIn = '<?= isSignedIn ?>' === 'true';
var error = '<?= error ?>';

var intercom = Intercom.getInstance();
Expand Down
25 changes: 11 additions & 14 deletions samples/WebApp/Code.gs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Copyright 2016 Google Inc. All Rights Reserved.
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -55,28 +55,25 @@ function signOut() {
* Gets the user's GitHub profile.
*/
function getGitHubProfile() {
var service = getGitHubService();
if (!service.hasAccess()) {
throw new Error('Error: Missing GitHub authorization.');
}
var url = 'https://api.github.com/user';
var response = UrlFetchApp.fetch(url, {
headers: {
Authorization: 'Bearer ' + service.getAccessToken()
}
});
return JSON.parse(response.getContentText());
return getGitHubResource('user');
}

/**
* Gets the user's GitHub repos.
*/
function getGitHubRepos() {
return getGitHubResource('user/repos');
}

/**
* Fetches the specified resource from the GitHub API.
*/
function getGitHubResource(resource) {
var service = getGitHubService();
if (!service.hasAccess()) {
throw new Error('Error: Missing GitHub authorization.');
}
var url = 'https://api.github.com/user/repos';
var url = 'https://api.github.com/' + resource;
var response = UrlFetchApp.fetch(url, {
headers: {
Authorization: 'Bearer ' + service.getAccessToken()
Expand Down
11 changes: 8 additions & 3 deletions samples/WebApp/JavaScript.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!--
* Copyright 2016 Google Inc. All Rights Reserved.
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -17,20 +17,24 @@
/**
* Create a wrapped version of google.script.run that
* is adapted for Angular promises.
* @see https://docs.angularjs.org/api/ng/service/$q
*/
var ScriptService = function($q) {
var self = this;
var promisify = function(key) {
return function() {
var args = arguments;
return $q(function(resolve, reject) {
// Call google.script.run with the specified method.
google.script.run
.withSuccessHandler(resolve)
.withFailureHandler(reject)
// Retrieve the method to run and then apply it to the arguments.
[key].apply(google.script.run, args);
});
};
};
// For each method exposed in google.script.run, wrap it up in a promise.
angular.forEach(google.script.run, function(_, key) {
self[key] = promisify(key)
});
Expand All @@ -52,7 +56,8 @@
self.user = null;
self.repos = null;

// Watch for changes to isSignedIn.
// Watch for changes to the user's sign in status, and fetch their GitHub
// data when they become signed in.
$scope.$watch('sample.isSignedIn', function(isSignedIn) {
if (isSignedIn) {
script.getGitHubProfile().then(function(user) {
Expand Down
6 changes: 3 additions & 3 deletions samples/WebApp/Page.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!--
* Copyright 2016 Google Inc. All Rights Reserved.
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -38,7 +38,7 @@

<script>
var email = '<?= email ?>';
var isSignedIn = '<?= isSignedIn ?>' == 'true';
var isSignedIn = '<?= isSignedIn ?>' === 'true';
</script>
<?!= include('JavaScript') ?>
</body>
Expand Down
9 changes: 5 additions & 4 deletions samples/WebApp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This sample web application connects to your GitHub account using the Apps
Script OAuth2 library and displays some information about the repositories you
own. It demonstrates some best practices for using this library in a web app.

![Sample web app screenshot](screenshot.png)

## Setup

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

## AngularJS
## Angular

This web app uses the [AngularJS 1 framework](https://angularjs.org/) to make it
This web app uses the [Angular 1 framework](https://angularjs.org/) to make it
easier to update the page dynamically. It's use is not required, and many
other JavaScript frameworks would work just as well.
Binary file added samples/WebApp/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9f9acd5

Please sign in to comment.