/// <summary> /// Subscribes to changes to a file /// Documentation https://developers.google.com/drive/v3/reference/files/watch /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Drive service.</param> /// <param name="fileId">The ID of the file.</param> /// <param name="body">A valid Drive v3 body.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>ChannelResponse</returns> public async Task <Channel> Watch(string fileId, Channel body, FilesWatchOptionalParms optional = null) { try { // Initial validation. if (_service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } if (fileId == null) { throw new ArgumentNullException(fileId); } // Building the initial request. var request = _service.Files.Watch(body, fileId); // Applying optional parameters to the request. request = (FilesResource.WatchRequest)GoogleDriveFunctionsHelper.ApplyOptionalParms(request, optional); // Requesting data. return(await request.ExecuteAsync()); } catch (Exception ex) { throw new Exception("Request Files.Watch failed.", ex); } }
/// <summary> /// Lists or searches files. /// Documentation https://developers.google.com/drive/v3/reference/files/list /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Drive service.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>FileListResponse</returns> public async Task <FileList> List(FilesListOptionalParms optional = null) { try { // Initial validation. if (_service == null) { throw new ArgumentNullException("service"); } // Building the initial request. FilesResource.ListRequest listRequest = _service.Files.List(); listRequest.Fields = "files(id, name, webViewLink)"; // Applying optional parameters to the request. listRequest = (FilesResource.ListRequest)GoogleDriveFunctionsHelper.ApplyOptionalParms(listRequest, optional); // Requesting data. var files = await listRequest.ExecuteAsync(); return(files); } catch (Exception ex) { throw new Exception("Request Files.List failed.", ex); } }
/// <summary> /// Permanently deletes a file owned by the user without moving it to the trash. If the file belongs to a Team Drive the user must be an organizer on the parent. If the target is a folder, all descendants owned by the user are also deleted. /// Documentation https://developers.google.com/drive/v3/reference/files/delete /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Drive service.</param> /// <param name="fileId">The ID of the file.</param> /// <param name="optional">Optional paramaters.</param> public async Task Delete(string fileId, FilesDeleteOptionalParms optional = null) { try { // Initial validation. if (_service == null) { throw new ArgumentNullException("service"); } if (fileId == null) { throw new ArgumentNullException(fileId); } // Building the initial request. var request = _service.Files.Delete(fileId); // Applying optional parameters to the request. request = (FilesResource.DeleteRequest)GoogleDriveFunctionsHelper.ApplyOptionalParms(request, optional); // Requesting data. await request.ExecuteAsync(); } catch (Exception ex) { throw new Exception("Request Files.Delete failed.", ex); } }
/// <summary> /// Creates a new file. /// Documentation https://developers.google.com/drive/v3/reference/files/create /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Drive service.</param> /// <param name="body">A valid Drive v3 body.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>FileResponse</returns> public async Task <File> Create(File body, FilesCreateOptionalParms optional = null) { try { var googleIdObject = await GenerateId(); // Initial validation. if (_service == null) { throw new ArgumentNullException("service"); } else if (body == null) { throw new ArgumentNullException("body"); } else if (googleIdObject == null) { throw new ArgumentNullException("id value is null"); } // Building the initial request. body.Id = googleIdObject.Ids[0]; var request = _service.Files.Create(body); // Applying optional parameters to the request. request = (FilesResource.CreateRequest)GoogleDriveFunctionsHelper.ApplyOptionalParms(request, optional); // Requesting data. return(await request.ExecuteAsync()); } catch (Exception ex) { throw new Exception("Request Files.Create failed.", ex); } }
/// <summary> /// Generates a set of file IDs which can be provided in create requests. /// Documentation https://developers.google.com/drive/v3/reference/files/generateIds /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Drive service.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>GeneratedIdsResponse</returns> public async Task <GeneratedIds> GenerateId(FilesGenerateIdsOptionalParms optional = null) { try { // Initial validation. if (_service == null) { throw new ArgumentNullException("service"); } // Building the initial request. var request = _service.Files.GenerateIds(); request.Count = 1; // Applying optional parameters to the request. request = (FilesResource.GenerateIdsRequest)GoogleDriveFunctionsHelper.ApplyOptionalParms(request, optional); // Requesting data. return(await request.ExecuteAsync()); } catch (Exception ex) { throw new Exception("Request Files.GenerateIds failed.", ex); } }