Minimal wrapper to access the Canvas LMS API.
This is an extremely minimal client. You need to know the API to be able to use this client. All this function does is:
Try to substitute each listed parameter into
endpoint
, using the :parameter
notation.
If a GET request (the default), then add all other listed parameters as query parameters.
If not a GET request, then send the other parameters in the request body, as JSON.
Convert the response to an R list using
jsonlite::fromJSON
.
cnvs( endpoint = "/api/v1/courses", ..., per_page = NULL, .token = NULL, .destfile = NULL, .overwrite = FALSE, .api_url = NULL, .method = "GET", .limit = NULL, .send_headers = NULL )
endpoint | Canvas LMS API endpoint. Must be one of the following forms:
If the method is not supplied, will use |
---|---|
... | Name-value pairs giving API parameters. Will be matched
into |
per_page | Number of items to return per page. If omitted,
will be substituted by |
.token | Authentication token. Defaults to CANVAS_API_TOKEN environment variable, if set. |
.destfile | path to write response to disk. If NULL (default), response will be processed and returned as an object. If path is given, response will be written to disk in the form sent. |
.overwrite | if |
.api_url | Canvas domain. Used
if |
.method | HTTP method to use if not explicitly supplied in the
|
.limit | Number of records to return. This can be used
instead of manual pagination. By default it is |
.send_headers | Named character vector of header field values
(excepting |
Answer from the API as a cnvs_response
object, which is also a
list
. Failed requests will generate an R error. Requests that
generate a raw response will return a raw vector.
cnvs_whoami()
for details on Canvas API token
management.
if (FALSE) { ## Your courses cnvs("/api/v1/courses") }