request_make: Make a request for the Google Drive v3 API

Description Usage Arguments Value See Also Examples

View source: R/request_make.R

Description

Low-level functions to execute one or more Drive API requests and, perhaps, process the response(s). Most users should, instead, use higher-level wrappers that facilitate common tasks, such as uploading or downloading Drive files. The functions here are intended for internal use and for programming around the Drive API. Three functions are documented here:

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
request_make(x, ...)

do_request(x, ...)

do_paginated_request(
  x,
  ...,
  n_max = Inf,
  n = function(res) 1,
  verbose = deprecated()
)

Arguments

x

List, holding the components for an HTTP request, presumably created with request_generate() Should contain the method, url, body, and token.

...

Optional arguments passed through to the HTTP method.

n_max

Maximum number of items to return. Defaults to Inf, i.e. there is no limit and we keep making requests until we get all items.

n

Function that computes the number of items in one response or page. The default function always returns 1 and therefore treats each page as an item. If you know more about the structure of the response, you can pass another function to count and threshhold, for example, the number of files or comments.

verbose

[Deprecated] This logical argument to individual googledrive functions is deprecated. To globally suppress googledrive messaging, use options(googledrive_quiet = TRUE) (the default behaviour is to emit informational messages). To suppress messaging in a more limited way, use the helpers local_drive_quiet() or with_drive_quiet().

Value

request_make(): Object of class response from httr.

do_request(): List representing the content returned by a single request.

do_paginated_request(): List of lists, representing the returned content, one component per page.

See Also

Other low-level API functions: drive_has_token(), drive_token(), request_generate()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## Not run: 
# build a request for an endpoint that is:
#   * paginated
#   * NOT privileged in googledrive, i.e. not covered by request_generate()
# "comments" are a great example
# https://developers.google.com/drive/v3/reference/comments
#
# Practice with a target file with > 2 comments
# Note that we request 2 items (comments) per page
req <- build_request(
  path = "drive/v3/files/{fileId}/comments",
  method = "GET",
  params = list(
    fileId = "your-file-id-goes-here",
    fields = "*",
    pageSize = 2
  ),
  token = googledrive::drive_token()
)
# make the paginated request, but cap it at 1 page
# should get back exactly two comments
do_paginated_request(req, n_max = 1)

## End(Not run)

googledrive documentation built on July 8, 2021, 5:07 p.m.