-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(google-sheet): add new spreadsheets trigger
- Loading branch information
1 parent
41dd404
commit 9deed54
Showing
17 changed files
with
121 additions
and
7 deletions.
There are no files selected for viewing
File renamed without changes
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
packages/backend/src/apps/google-sheets/dynamic-data/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import listDrives from './list-drives'; | ||
|
||
export default [listDrives]; |
38 changes: 38 additions & 0 deletions
38
packages/backend/src/apps/google-sheets/dynamic-data/list-drives/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { IGlobalVariable, IJSONObject } from '@automatisch/types'; | ||
|
||
export default { | ||
name: 'List drives', | ||
key: 'listDrives', | ||
|
||
async run($: IGlobalVariable) { | ||
const drives: { | ||
data: IJSONObject[]; | ||
} = { | ||
data: [{ value: null, name: 'My Google Drive' }], | ||
}; | ||
|
||
const params = { | ||
pageSize: 100, | ||
pageToken: undefined as unknown as string, | ||
}; | ||
|
||
do { | ||
const { data } = await $.http.get( | ||
`https://www.googleapis.com/drive/v3/drives`, | ||
{ params } | ||
); | ||
params.pageToken = data.nextPageToken; | ||
|
||
if (data.drives) { | ||
for (const drive of data.drives) { | ||
drives.data.push({ | ||
value: drive.id, | ||
name: drive.name, | ||
}); | ||
} | ||
} | ||
} while (params.pageToken); | ||
|
||
return drives; | ||
}, | ||
}; |
File renamed without changes.
12 changes: 8 additions & 4 deletions
12
...es/backend/src/apps/google-sheet/index.ts → ...s/backend/src/apps/google-sheets/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
import defineApp from '../../helpers/define-app'; | ||
import addAuthHeader from './common/add-auth-header'; | ||
import auth from './auth'; | ||
import triggers from './triggers'; | ||
import dynamicData from './dynamic-data'; | ||
|
||
export default defineApp({ | ||
name: 'Google Sheet', | ||
key: 'google-sheet', | ||
name: 'Google Sheets', | ||
key: 'google-sheets', | ||
baseUrl: 'https://docs.google.com/spreadsheets', | ||
apiBaseUrl: 'https://sheets.googleapis.com', | ||
iconUrl: '{BASE_URL}/apps/google-sheet/assets/favicon.svg', | ||
authDocUrl: 'https://automatisch.io/docs/apps/google-sheet/connection', | ||
iconUrl: '{BASE_URL}/apps/google-sheets/assets/favicon.svg', | ||
authDocUrl: 'https://automatisch.io/docs/apps/google-sheets/connection', | ||
primaryColor: '0F9D58', | ||
supportsConnections: true, | ||
beforeRequest: [addAuthHeader], | ||
auth, | ||
triggers, | ||
dynamicData, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import newSpreadsheets from './new-spreadsheets'; | ||
|
||
export default [newSpreadsheets]; |
33 changes: 33 additions & 0 deletions
33
packages/backend/src/apps/google-sheets/triggers/new-spreadsheets/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import defineTrigger from '../../../../helpers/define-trigger'; | ||
import newSpreadsheets from './new-spreadsheets' | ||
|
||
export default defineTrigger({ | ||
name: 'New Spreadsheets', | ||
key: 'newSpreadsheets', | ||
pollInterval: 15, | ||
description: 'Triggers when you create a new spreadsheet.', | ||
arguments: [ | ||
{ | ||
label: 'Drive', | ||
key: 'driveId', | ||
type: 'dropdown' as const, | ||
required: false, | ||
description: 'The Google Drive where your spreadsheet resides. If nothing is selected, then your personal Google Drive will be used.', | ||
variables: false, | ||
source: { | ||
type: 'query', | ||
name: 'getDynamicData', | ||
arguments: [ | ||
{ | ||
name: 'key', | ||
value: 'listDrives', | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
|
||
async run($) { | ||
await newSpreadsheets($); | ||
}, | ||
}); |
33 changes: 33 additions & 0 deletions
33
packages/backend/src/apps/google-sheets/triggers/new-spreadsheets/new-spreadsheets.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { IGlobalVariable } from '@automatisch/types'; | ||
|
||
const newSpreadsheets = async ($: IGlobalVariable) => { | ||
const params = { | ||
pageToken: undefined as unknown as string, | ||
orderBy: 'createdTime desc', | ||
q: `mimeType='application/vnd.google-apps.spreadsheet'`, | ||
fields: '*', | ||
pageSize: 1000, | ||
driveId: $.step.parameters.driveId, | ||
}; | ||
|
||
do { | ||
const { data } = await $.http.get( | ||
'https://www.googleapis.com/drive/v3/files', | ||
{ params } | ||
); | ||
params.pageToken = data.nextPageToken; | ||
|
||
if (data.files?.length) { | ||
for (const file of data.files) { | ||
$.pushTriggerItem({ | ||
raw: file, | ||
meta: { | ||
internalId: file.id, | ||
}, | ||
}); | ||
} | ||
} | ||
} while (params.pageToken); | ||
}; | ||
|
||
export default newSpreadsheets; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters