@cag-group/google-api-tools
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -29,3 +29,3 @@ const google = require('googleapis') | ||
* @param {string} pageToken - optional token for reading next page | ||
* @returns {Promise} for response | ||
* @returns {Promise} Response containing calendar items (response.items) | ||
*/ | ||
@@ -53,4 +53,22 @@ getItems (calendarId, from, to, pageToken) { | ||
} | ||
/** | ||
* Calls getItems until all items has been read. | ||
* @param calendarId - ID of the calendar | ||
* @param {Date} from - From date and time | ||
* @param {Date} to - To date and time | ||
* @returns {Promise<Array.<{CalendarItem}>>} Calendar items | ||
*/ | ||
async getAllItems (calendarId, from, to) { | ||
let nextPageToken | ||
let items = [] | ||
do { | ||
const response = await this.apiAgent.calendarClient.getItems(calendarId, fromDate, toDate, nextPageToken) | ||
nextPageToken = response.nextPageToken | ||
items = items.concat(response.items) | ||
} while (nextPageToken) | ||
return items | ||
} | ||
} | ||
module.exports = CalendarClient |
{ | ||
"name": "@cag-group/google-api-tools", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Helpers related to Google APIs", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -24,19 +24,9 @@ ## Google Cloud API tools for Node.js | ||
const client = new DriveClient(key.client_email, key.private_key) | ||
const files = await client.getFilesInFolder(folderId) | ||
const response = await client.getFilesInFolder(folderId) | ||
``` | ||
example result: | ||
``` | ||
{ kind: 'drive#fileList', | ||
incompleteSearch: false, | ||
files: | ||
[ { kind: 'drive#file', | ||
id: '000000000000000000000000000000000000000000000', | ||
name: 'Walt Disney characters', | ||
mimeType: 'application/vnd.google-apps.spreadsheet' } ] } | ||
``` | ||
or get meta data for a named file in a specific folder: | ||
Get meta data for a named file in a specific folder: | ||
```javascript | ||
const files = await client.getFileMetaData(folderId, 'Walt Disney characters') | ||
const file = await client.getFileMetaData(folderId, 'Walt Disney characters') | ||
``` | ||
@@ -48,3 +38,3 @@ | ||
The helper can read calendar items in a time interval. | ||
Read calendar items within a time interval. | ||
@@ -59,4 +49,4 @@ The calendar shall be public or shared with the service account. | ||
```javascript | ||
const response = await client.getItems(calendarId, new Date('2017-09-15T00:00'), new Date('2017-09-16T00:00')) | ||
console.log(response.items) | ||
const items = await client.getAllItems(calendarId, new Date('2017-09-15T00:00'), new Date('2017-09-16T00:00')) | ||
console.log(items) | ||
``` | ||
@@ -63,0 +53,0 @@ |
Sorry, the diff of this file is not supported yet
65242
18
369
129