@@ -94,16 +94,16 @@ function listDriveActivity(auth) {
9494 const params = {
9595 'pageSize' : 10 ,
9696 } ;
97- service . activity . query ( { requestBody :params } , ( err , res ) => {
97+ service . activity . query ( { requestBody : params } , ( err , res ) => {
9898 if ( err ) return console . error ( 'The API returned an error: ' + err ) ;
9999 const activities = res . data . activities ;
100100 if ( activities ) {
101101 console . log ( 'Recent activity:' ) ;
102102 activities . forEach ( ( activity ) => {
103- var time = getTimeInfo ( activity ) ;
104- var action = getActionInfo ( activity [ 'primaryActionDetail' ] ) ;
105- var actors = activity . actors . map ( getActorInfo ) ;
106- var targets = activity . targets . map ( getTargetInfo ) ;
103+ const time = getTimeInfo ( activity ) ;
104+ const action = getActionInfo ( activity [ 'primaryActionDetail' ] ) ;
105+ const actors = activity . actors . map ( getActorInfo ) ;
106+ const targets = activity . targets . map ( getTargetInfo ) ;
107107 console . log ( `${ time } : ${ truncated ( actors ) } , ${ action } , ` +
108108 `${ truncated ( targets ) } ` ) ;
109109 } ) ;
@@ -113,22 +113,40 @@ function listDriveActivity(auth) {
113113 } ) ;
114114}
115115
116- /** Returns a string representation of the first elements in a list. */
116+ /**
117+ * Returns a string representation of the first elements in a list.
118+ *
119+ * @param {Array<Object> } array The array to convert to a short string.
120+ * @param {number } limit The number of elements to show before truncating.
121+ * @return {string }
122+ */
117123function truncated ( array , limit = 2 ) {
118- var contents = array . slice ( 0 , limit ) . join ( ', ' ) ;
119- var more = array . length > limit ? ', ...' : '' ;
124+ const contents = array . slice ( 0 , limit ) . join ( ', ' ) ;
125+ const more = array . length > limit ? ', ...' : '' ;
120126 return `[${ contents } ${ more } ]` ;
121127}
122128
123- /** Returns the name of a set property in an object, or else "unknown". */
129+ /**
130+ * Returns the name of a set property in an object, or else "unknown".
131+ *
132+ * @param {Object } object The object in which to find the set property.
133+ * @return {string }
134+ */
124135function getOneOf ( object ) {
125- for ( var key in object ) {
126- return key ;
136+ for ( const key in object ) {
137+ if ( object . hasOwnProperty ( key ) ) {
138+ return key ;
139+ }
127140 }
128141 return 'unknown' ;
129142}
130143
131- /** Returns a time associated with an activity. */
144+ /**
145+ * Returns a time associated with an activity.
146+ *
147+ * @param {Object } activity The DriveActivity from which to extract a time.
148+ * @return {string }
149+ */
132150function getTimeInfo ( activity ) {
133151 if ( 'timestamp' in activity ) {
134152 return activity . timestamp ;
@@ -139,42 +157,62 @@ function getTimeInfo(activity) {
139157 return 'unknown' ;
140158}
141159
142- /** Returns the type of action. */
160+ /**
161+ * Returns the type of action.
162+ *
163+ * @param {Object } actionDetail The ActionDetail to summarize.
164+ * @return {string }
165+ */
143166function getActionInfo ( actionDetail ) {
144167 return getOneOf ( actionDetail ) ;
145168}
146169
147- /** Returns user information, or the type of user if not a known user. */
170+ /**
171+ * Returns user information, or the type of user if not a known user.
172+ *
173+ * @param {Object } user The User to summarize.
174+ * @return {string }
175+ */
148176function getUserInfo ( user ) {
149177 if ( 'knownUser' in user ) {
150- var knownUser = user [ 'knownUser' ] ;
151- var isMe = knownUser [ 'isCurrentUser' ] || false ;
178+ const knownUser = user [ 'knownUser' ] ;
179+ const isMe = knownUser [ 'isCurrentUser' ] || false ;
152180 return isMe ? 'people/me' : knownUser [ 'personName' ] ;
153181 }
154182 return getOneOf ( user ) ;
155183}
156184
157- /** Returns actor information, or the type of actor if not a user. */
185+ /**
186+ * Returns actor information, or the type of actor if not a user.
187+ *
188+ * @param {Object } actor The Actor to summarize.
189+ * @return {string }
190+ */
158191function getActorInfo ( actor ) {
159192 if ( 'user' in actor ) {
160- return getUserInfo ( actor [ 'user' ] )
193+ return getUserInfo ( actor [ 'user' ] ) ;
161194 }
162195 return getOneOf ( actor ) ;
163196}
164197
165- /** Returns the type of a target and an associated title. */
198+ /**
199+ * Returns the type of a target and an associated title.
200+ *
201+ * @param {Object } target The Target to summarize.
202+ * @return {string }
203+ */
166204function getTargetInfo ( target ) {
167205 if ( 'driveItem' in target ) {
168- var title = target . driveItem . title || 'unknown' ;
206+ const title = target . driveItem . title || 'unknown' ;
169207 return `driveItem:"${ title } "` ;
170208 }
171209 if ( 'teamDrive' in target ) {
172- var title = target . teamDrive . title || 'unknown' ;
210+ const title = target . teamDrive . title || 'unknown' ;
173211 return `teamDrive:"${ title } "` ;
174212 }
175213 if ( 'fileComment' in target ) {
176- var parent = target . fileComment . parent || { } ;
177- var title = parent . title || 'unknown' ;
214+ const parent = target . fileComment . parent || { } ;
215+ const title = parent . title || 'unknown' ;
178216 return `fileComment:"${ title } "` ;
179217 }
180218 return `${ getOneOf ( target ) } :unknown` ;
0 commit comments