forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
google-apps-script.drive.d.ts
266 lines (255 loc) · 10.3 KB
/
google-apps-script.drive.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
// Type definitions for Google Apps Script 2015-11-12
// Project: https://developers.google.com/apps-script/
// Definitions by: motemen <https://github.com/motemen/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="google-apps-script.types.d.ts" />
/// <reference path="google-apps-script.base.d.ts" />
declare namespace GoogleAppsScript {
export module Drive {
/**
* An enum representing classes of users who can access a file or folder, besides any individual
* users who have been explicitly given access. These properties can be accessed from
* DriveApp.Access.
*
* // Creates a folder that anyone on the Internet can read from and write to. (Domain
* // administrators can prohibit this setting for users of Google Apps for Business, Google Apps
* // for Education, or Google Apps for Your Domain.)
* var folder = DriveApp.createFolder('Shared Folder');
* folder.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.EDIT);
*/
export enum Access { ANYONE, ANYONE_WITH_LINK, DOMAIN, DOMAIN_WITH_LINK, PRIVATE }
/**
* Allows scripts to create, find, and modify files and folders in Google Drive.
*
* // Log the name of every file in the user's Drive.
* var files = DriveApp.getFiles();
* while (files.hasNext()) {
* var file = files.next();
* Logger.log(file.getName());
* }
*/
export interface DriveApp {
Access: Access
Permission: Permission
addFile(child: File): Folder;
addFolder(child: Folder): Folder;
continueFileIterator(continuationToken: string): FileIterator;
continueFolderIterator(continuationToken: string): FolderIterator;
createFile(blob: Base.BlobSource): File;
createFile(name: string, content: string): File;
createFile(name: string, content: string, mimeType: string): File;
createFolder(name: string): Folder;
getFileById(id: string): File;
getFiles(): FileIterator;
getFilesByName(name: string): FileIterator;
getFilesByType(mimeType: string): FileIterator;
getFolderById(id: string): Folder;
getFolders(): FolderIterator;
getFoldersByName(name: string): FolderIterator;
getRootFolder(): Folder;
getStorageLimit(): Integer;
getStorageUsed(): Integer;
getTrashedFiles(): FileIterator;
getTrashedFolders(): FolderIterator;
removeFile(child: File): Folder;
removeFolder(child: Folder): Folder;
searchFiles(params: string): FileIterator;
searchFolders(params: string): FolderIterator;
}
/**
* A file in Google Drive. Files can be accessed or created from DriveApp.
*
* // Trash every untitled spreadsheet that hasn't been updated in a week.
* var files = DriveApp.getFilesByName('Untitled spreadsheet');
* while (files.hasNext()) {
* var file = files.next();
* if (new Date() - file.getLastUpdated() > 7 * 24 * 60 * 60 * 1000) {
* file.setTrashed(true);
* }
* }
*/
export interface File {
addCommenter(emailAddress: string): File;
addCommenter(user: Base.User): File;
addCommenters(emailAddresses: String[]): File;
addEditor(emailAddress: string): File;
addEditor(user: Base.User): File;
addEditors(emailAddresses: String[]): File;
addViewer(emailAddress: string): File;
addViewer(user: Base.User): File;
addViewers(emailAddresses: String[]): File;
getAccess(email: string): Permission;
getAccess(user: Base.User): Permission;
getAs(contentType: string): Base.Blob;
getBlob(): Base.Blob;
getDateCreated(): Date;
getDescription(): string;
getDownloadUrl(): string;
getEditors(): User[];
getId(): string;
getLastUpdated(): Date;
getMimeType(): string;
getName(): string;
getOwner(): User;
getParents(): FolderIterator;
getSharingAccess(): Access;
getSharingPermission(): Permission;
getSize(): Integer;
getThumbnail(): Base.Blob;
getUrl(): string;
getViewers(): User[];
isShareableByEditors(): boolean;
isStarred(): boolean;
isTrashed(): boolean;
makeCopy(): File;
makeCopy(destination: Folder): File;
makeCopy(name: string): File;
makeCopy(name: string, destination: Folder): File;
removeCommenter(emailAddress: string): File;
removeCommenter(user: Base.User): File;
removeEditor(emailAddress: string): File;
removeEditor(user: Base.User): File;
removeViewer(emailAddress: string): File;
removeViewer(user: Base.User): File;
revokePermissions(user: string): File;
revokePermissions(user: Base.User): File;
setContent(content: string): File;
setDescription(description: string): File;
setName(name: string): File;
setOwner(emailAddress: string): File;
setOwner(user: Base.User): File;
setShareableByEditors(shareable: boolean): File;
setSharing(accessType: Access, permissionType: Permission): File;
setStarred(starred: boolean): File;
setTrashed(trashed: boolean): File;
}
/**
* An iterator that allows scripts to iterate over a potentially large collection of files. File
* iterators can be acccessed from DriveApp or a Folder.
*
* // Log the name of every file in the user's Drive.
* var files = DriveApp.getFiles();
* while (files.hasNext()) {
* var file = files.next();
* Logger.log(file.getName());
* }
*/
export interface FileIterator {
getContinuationToken(): string;
hasNext(): boolean;
next(): File;
}
/**
* A folder in Google Drive. Folders can be accessed or created from DriveApp.
*
* // Log the name of every folder in the user's Drive.
* var folders = DriveApp.getFolders();
* while (folders.hasNext()) {
* var folder = folders.next();
* Logger.log(folder.getName());
* }
*/
export interface Folder {
addEditor(emailAddress: string): Folder;
addEditor(user: Base.User): Folder;
addEditors(emailAddresses: String[]): Folder;
addFile(child: File): Folder;
addFolder(child: Folder): Folder;
addViewer(emailAddress: string): Folder;
addViewer(user: Base.User): Folder;
addViewers(emailAddresses: String[]): Folder;
createFile(blob: Base.BlobSource): File;
createFile(name: string, content: string): File;
createFile(name: string, content: string, mimeType: string): File;
createFolder(name: string): Folder;
getAccess(email: string): Permission;
getAccess(user: Base.User): Permission;
getDateCreated(): Date;
getDescription(): string;
getEditors(): User[];
getFiles(): FileIterator;
getFilesByName(name: string): FileIterator;
getFilesByType(mimeType: string): FileIterator;
getFolders(): FolderIterator;
getFoldersByName(name: string): FolderIterator;
getId(): string;
getLastUpdated(): Date;
getName(): string;
getOwner(): User;
getParents(): FolderIterator;
getSharingAccess(): Access;
getSharingPermission(): Permission;
getSize(): Integer;
getUrl(): string;
getViewers(): User[];
isShareableByEditors(): boolean;
isStarred(): boolean;
isTrashed(): boolean;
removeEditor(emailAddress: string): Folder;
removeEditor(user: Base.User): Folder;
removeFile(child: File): Folder;
removeFolder(child: Folder): Folder;
removeViewer(emailAddress: string): Folder;
removeViewer(user: Base.User): Folder;
revokePermissions(user: string): Folder;
revokePermissions(user: Base.User): Folder;
searchFiles(params: string): FileIterator;
searchFolders(params: string): FolderIterator;
setDescription(description: string): Folder;
setName(name: string): Folder;
setOwner(emailAddress: string): Folder;
setOwner(user: Base.User): Folder;
setShareableByEditors(shareable: boolean): Folder;
setSharing(accessType: Access, permissionType: Permission): Folder;
setStarred(starred: boolean): Folder;
setTrashed(trashed: boolean): Folder;
}
/**
* An object that allows scripts to iterate over a potentially large collection of folders. Folder
* iterators can be acccessed from DriveApp, a File, or a Folder.
*
* // Log the name of every folder in the user's Drive.
* var folders = DriveApp.getFolders();
* while (folders.hasNext()) {
* var folder = folders.next();
* Logger.log(folder.getName());
* }
*/
export interface FolderIterator {
getContinuationToken(): string;
hasNext(): boolean;
next(): Folder;
}
/**
* An enum representing the permissions granted to users who can access a file or folder, besides
* any individual users who have been explicitly given access. These properties can be accessed from
* DriveApp.Permission.
*
* // Creates a folder that anyone on the Internet can read from and write to. (Domain
* // administrators can prohibit this setting for users of Google Apps for Business, Google Apps
* // for Education, or Google Apps for Your Domain.)
* var folder = DriveApp.createFolder('Shared Folder');
* folder.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.EDIT);
*/
export enum Permission { VIEW, EDIT, COMMENT, OWNER, NONE }
/**
* A user associated with a file in Google Drive. Users can be accessed from
* File.getEditors(), Folder.getViewers(), and other methods.
*
* // Log the email address of all users who have edit access to a file.
* var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
* var editors = file.getEditors();
* for (var i = 0; i < editors.length; i++) {
* Logger.log(editors[i].getEmail());
* }
*/
export interface User {
getDomain(): string;
getEmail(): string;
getName(): string;
getPhotoUrl(): string;
getUserLoginId(): string;
}
}
}
declare var DriveApp: GoogleAppsScript.Drive.DriveApp;