Skip to content

Commit

Permalink
Adding comments to helper methods in Drive Activity v2 API quickstart.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmeredith committed Jan 16, 2019
1 parent a896f39 commit 3e5cebb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion drive/activity-v2/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright 2018 Google LLC
Copyright 2019 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
Expand Down Expand Up @@ -140,19 +140,22 @@
});
}

/** Returns a string representation of the first elements in a list. */
function truncated(array, limit = 2) {
var contents = array.slice(0, limit).join(', ');
var more = array.length > limit ? ', ...' : '';
return `[${contents}${more}]`;
}

/** Returns the name of a set property in an object, or else "unknown". */
function getOneOf(object) {
for (var key in object) {
return key;
}
return 'unknown';
}

/** Returns a time associated with an activity. */
function getTimeInfo(activity) {
if ('timestamp' in activity) {
return activity.timestamp;
Expand All @@ -163,10 +166,12 @@
return 'unknown';
}

/** Returns the type of action. */
function getActionInfo(actionDetail) {
return getOneOf(actionDetail);
}

/** Returns user information, or the type of user if not a known user. */
function getUserInfo(user) {
if ('knownUser' in user) {
var knownUser = user['knownUser'];
Expand All @@ -176,13 +181,15 @@
return getOneOf(user);
}

/** Returns actor information, or the type of actor if not a user. */
function getActorInfo(actor) {
if ('user' in actor) {
return getUserInfo(actor['user'])
}
return getOneOf(actor);
}

/** Returns the type of a target and an associated title. */
function getTargetInfo(target) {
if ('driveItem' in target) {
var title = target.driveItem.title || 'unknown';
Expand Down

0 comments on commit 3e5cebb

Please sign in to comment.