|
| 1 | +#'@title Retrieve the metadata for a specific file. |
| 2 | +#' |
| 3 | +#'@description \code{file_metadata} retrieves the metadata for a specific file the user |
| 4 | +#'has access to. To retrieve the metadata for all files, see \code{\link{list_files}} |
| 5 | +#' |
| 6 | +#'@param token a token, generated with \code{\link{driver_connect}}. |
| 7 | +#' |
| 8 | +#'@param file_id a file ID, as a string. This can be retrieved from the URL bar when you're accessing |
| 9 | +#'the file: for example, "https://docs.google.com/document/d/1gOxog56F2bCnxwum7VhmN3JqTX7usTYcK5X3V4QDnxg" |
| 10 | +#'has the file_id "1gOxog56F2bCnxwum7VhmN3JqTX7usTYcK5X3V4QDnxg". |
| 11 | +#' |
| 12 | +#'@param simplify whether or not to perform some (small) simplification of the returned |
| 13 | +#'list, to make it less nested, headachey and impossible to read. Set to FALSE by default. |
| 14 | +#' |
| 15 | +#'@param ... further arguments to pass to httr's GET. |
| 16 | +#' |
| 17 | +#'@seealso \code{\link{list_files}}, for requesting the metadata associated with many files. |
| 18 | +#' |
| 19 | +#'@examples |
| 20 | +#'\dontrun{ |
| 21 | +#'#Once we've authenticated and grabbed a token, we can grab the metadata for the example file: |
| 22 | +#'example_metadata <- file_metadata(token, "1gOxog56F2bCnxwum7VhmN3JqTX7usTYcK5X3V4QDnxg") |
| 23 | +#'} |
| 24 | +#'@export |
| 25 | +file_metadata <- function(token, file_id, simplify = FALSE, ...){ |
| 26 | + parameters <- paste0("files/", file_id) |
| 27 | + result <- driver_get(parameters, "file_metadata", token, ...) |
| 28 | + if(simplify){ |
| 29 | + result <- simplify_response(result) |
| 30 | + } |
| 31 | + return(result) |
| 32 | +} |
| 33 | + |
| 34 | +#'@title create an empty file, or upload a local file |
| 35 | +#' |
| 36 | +#'@importFrom httr upload_file |
| 37 | +#'@export |
| 38 | +create_file <- function(token, file_path = NULL, ...){ |
| 39 | + parameters <- "files?uploadType=media" |
| 40 | + if(is.null(file_path)){ |
| 41 | + result <- driver_post(parameters, token, ...) |
| 42 | + } else { |
| 43 | + result <- driver_post(parameters, token, body = upload_file(file_path), ...) |
| 44 | + } |
| 45 | + return(result) |
| 46 | +} |
| 47 | + |
| 48 | +update_file <- function(){ |
| 49 | + |
| 50 | +} |
| 51 | + |
| 52 | +#'@title copy a Google Drive file |
| 53 | +#'@description takes a Google Drive file and creates a copy of it, with the same |
| 54 | +#'access restrictions. |
| 55 | +#' |
| 56 | +#'@param token a token, generated with \code{\link{driver_connect}}. |
| 57 | +#' |
| 58 | +#'@param file_id the ID of the file; see \code{\link{file_metadata}} for further |
| 59 | +#'commentary. |
| 60 | +#' |
| 61 | +#'@param ... further arguments to pass to httr's POST. |
| 62 | +#' |
| 63 | +#'@return a set of metadata associated with the copy of the file, matching |
| 64 | +#'the output of \code{\link{file_metadata}}. |
| 65 | +#' |
| 66 | +#'@export |
| 67 | +copy_file <- function(token, file_id, ...){ |
| 68 | + parameters <- paste0("files/", file_id, "/copy") |
| 69 | + result <- driver_post(parameters, token, ...) |
| 70 | + return(result) |
| 71 | +} |
| 72 | + |
| 73 | +#'@title delete a Google Drive file |
| 74 | +#'@description \code{delete_file} removes a file completely, assuming the user has |
| 75 | +#'permission to do so. In the process it completely bypasses the trash bin, rendering |
| 76 | +#'the file unrecoverable by the user. |
| 77 | +#' |
| 78 | +#'@param token a token, generated with \code{\link{driver_connect}}. |
| 79 | +#' |
| 80 | +#'@param file_id the ID of the file; see \code{\link{file_metadata}} for further |
| 81 | +#'commentary. |
| 82 | +#' |
| 83 | +#'@param ... further arguments to pass to httr's DELETE. |
| 84 | +#' |
| 85 | +#'@return TRUE if the file was successfully deleted, FALSE or an error otherwise. |
| 86 | +#' |
| 87 | +#'@export |
| 88 | +delete_file <- function(token, file_id, ...){ |
| 89 | + parameters <- paste0("files/", file_id) |
| 90 | + result <- driver_delete(parameters, token) |
| 91 | + if(result$status_code %in% c(200, 202, 204)){ |
| 92 | + return(TRUE) |
| 93 | + } else { |
| 94 | + return(FALSE) |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +#'@title Retrieve the metadata for all files |
| 99 | +#' |
| 100 | +#'@description \code{list_files} allows an authenticated user to retrieve the metadata |
| 101 | +#'associated with each file they have access to. For the metadata for a single file, see |
| 102 | +#'\code{\link{get_file_metadata}}. |
| 103 | +#' |
| 104 | +#'@param token a token, generated with \code{\link{driver_connect}}. |
| 105 | +#' |
| 106 | +#'@param max_results the maximum number of results to return; any number between 1 and 1000. |
| 107 | +#'Set to 100 by default. |
| 108 | +#' |
| 109 | +#'@param page_token in the event that the requested files are split over multiple pages, |
| 110 | +#'each object returned from \code{list_files} will contain an element named "nextPageToken". |
| 111 | +#'Plugging this into the \code{page_token} parameter provides for query continuation. |
| 112 | +#' |
| 113 | +#'@param simplify whether or not to perform some (small) simplification of the returned |
| 114 | +#'list, to make it less nested, headachey and impossible to read. Set to FALSE by default. |
| 115 | +#' |
| 116 | +#'@param ... further arguments to pass to httr's GET. |
| 117 | +#' |
| 118 | +#'@export |
| 119 | +list_files <- function(token, max_results = 100, page_token = NULL, simplify = FALSE, ...){ |
| 120 | + parameters <- paste0("files?", "maxResults=", max_results) |
| 121 | + if(!is.null(page_token)){ |
| 122 | + parameters <- paste0(parameters, "&pageToken=", page_token) |
| 123 | + } |
| 124 | + result <- driver_get(parameters, "file_list", token, ...) |
| 125 | + if(simplify){ |
| 126 | + result <- simplify_response(result) |
| 127 | + } |
| 128 | + return(result) |
| 129 | +} |
| 130 | + |
| 131 | +update_file_time <- function(){ |
| 132 | + |
| 133 | +} |
| 134 | + |
| 135 | +trash_file <- function(){ |
| 136 | + |
| 137 | +} |
| 138 | + |
| 139 | +untrash_file <- function(){ |
| 140 | + |
| 141 | +} |
| 142 | + |
| 143 | +empty_trash <- function(){ |
| 144 | + |
| 145 | +} |
| 146 | +watch_file <- function(){ |
| 147 | + |
| 148 | +} |
| 149 | + |
0 commit comments