cnvs: Canvas LMS API

Description Usage Arguments Value See Also Examples

View source: R/package.R

Description

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:

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
cnvs(
  endpoint = "/api/v1/courses",
  ...,
  per_page = NULL,
  .token = NULL,
  .destfile = NULL,
  .overwrite = FALSE,
  .api_url = NULL,
  .method = "GET",
  .limit = NULL,
  .send_headers = NULL
)

Arguments

endpoint

Canvas LMS API endpoint. Must be one of the following forms:

  • "METHOD path", e.g. "GET /api/v1/courses"

  • "path", e.g. "/api/v1/courses".

  • "METHOD url", e.g. "GET https://canvas.instructure.com/api/v1/courses"

  • "url", e.g. "https://canvas.instructure.com/api/v1/courses".

If the method is not supplied, will use .method, which defaults to GET.

...

Name-value pairs giving API parameters. Will be matched into url placeholders, sent as query parameters in GET requests, and in the JSON body of POST requests.

per_page

Number of items to return per page. If omitted, will be substituted by max(.limit, 100) if .limit is set, otherwise determined by the API (never greater than 100).

.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 destfile is provided, whether to overwrite an existing file. Defaults to FALSE.

.api_url

Canvas domain. Used if endpoint just contains a path. Defaults to CANVAS_DOMAIN environment variable, if set.

.method

HTTP method to use if not explicitly supplied in the endpoint.

.limit

Number of records to return. This can be used instead of manual pagination. By default it is NULL, which means that the defaults of the Canvas API are used. You can set it to a number to request more (or less) records, and also to Inf to request all records. Note, that if you request many records, then multiple Canva API calls are used to get them, and this can take a potentially long time.

.send_headers

Named character vector of header field values (excepting Authorization, which is handled via .token). This can be used to override or augment the defaults, which are as follows: the Accept field defaults to "application/json", the User-Agent field defaults to "https://github.com/cwickham/cnvs", and the Content-Type defaults to "application/json".

Value

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.

See Also

cnvs_whoami() for details on Canvas API token management.

Examples

1
2
3
4
5
## Not run: 
## Your courses
cnvs("/api/v1/courses")

## End(Not run)

cwickham/cnvs documentation built on Oct. 20, 2020, 5:34 a.m.