-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
186 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
#' Retrieves the assignment groups within a course. | ||
#' | ||
#' This function retrieves the assignment groups within a specific course in the Canvas LMS API. | ||
#' | ||
#' @param canvas An object containing the Canvas API key and base URL, obtained through the `canvas_authenticate` function. | ||
#' @param course_id The ID of the course for which to fetch the assignment groups. | ||
#' @param per_page The number of entries to show per page. | ||
#' | ||
#' @return A list of assignment groups within the specified course. | ||
#' @export | ||
#' | ||
get_assignment_groups <- function(canvas, course_id, per_page = 100) { | ||
# Construct the API endpoint URL | ||
url <- paste0(canvas$base_url, "/api/v1/courses/", course_id, "/assignment_groups?per_page=", per_page) | ||
|
||
# Make the API request | ||
response <- httr::GET(url, httr::add_headers(Authorization = paste("Bearer", canvas$api_key))) | ||
|
||
# Check the response status code | ||
if (httr::status_code(response) != 200) { | ||
stop("Failed to retrieve assignment groups. Please check your authentication and API endpoint.") | ||
} | ||
|
||
# Parse the response as JSON | ||
assignment_groups <- httr::content(response, "text", encoding = "UTF-8") %>% | ||
jsonlite::fromJSON(flatten = TRUE) %>% | ||
as.data.frame() %>% | ||
dplyr::mutate(course_id = course_id) | ||
|
||
# Return the list of assignment groups | ||
return(assignment_groups) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
#' Retrieves the media objects in a course. | ||
#' | ||
#' This function retrieves the media objects associated with a specific course in the Canvas LMS API. | ||
#' | ||
#' @param canvas An object containing the Canvas API key and base URL, obtained through the `canvas_authenticate` function. | ||
#' @param course_id The ID of the course for which to fetch the media objects. | ||
#' @param per_page The number of entries to show per page. | ||
#' | ||
#' @return A data frame containing the media objects in the specified course. | ||
#' @export | ||
#' | ||
get_course_media_objects <- function(canvas, course_id, per_page = 100) { | ||
# Construct the API endpoint URL | ||
url <- paste0(canvas$base_url, "/api/v1/courses/", course_id, "/media_objects?per_page=", per_page) | ||
|
||
# Make the API request | ||
response <- httr::GET(url, httr::add_headers(Authorization = paste("Bearer", canvas$api_key))) | ||
|
||
# Check the response status code | ||
if (httr::status_code(response) != 200) { | ||
stop("Failed to retrieve course media objects. Please check your authentication and API endpoint.") | ||
} | ||
|
||
# Parse the response as JSON | ||
media_objects <- httr::content(response, "text", encoding = "UTF-8") %>% | ||
jsonlite::fromJSON(flatten = TRUE) %>% | ||
as.data.frame() %>% | ||
dplyr::mutate(course_id = course_id) | ||
|
||
# Return the list of media objects | ||
return(media_objects) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#' Retrieves the users in a course. | ||
#' | ||
#' This function retrieves the users enrolled in a specific course in the Canvas LMS API. | ||
#' | ||
#' @param canvas An object containing the Canvas API key and base URL, obtained through the `canvas_authenticate` function. | ||
#' @param course_id The ID of the course for which to fetch the users. | ||
#' @param per_page The number of entries to show per page. | ||
#' @param include Optional parameters to include in the response. Possible values: "enrollments", "locked", "avatar_url", "test_student", "bio", "custom_links", "current_grading_period_scores", "uuid". | ||
#' | ||
#' @return A data frame containing the users in the specified course. | ||
#' @export | ||
#' | ||
get_course_users <- function(canvas, course_id, per_page = 100, include = c("enrollments", "locked", "avatar_url", "test_student", "bio", "custom_links", "current_grading_period_scores", "uuid")) { | ||
# Construct the API endpoint URL | ||
url <- paste0(canvas$base_url, "/api/v1/courses/", course_id, "/users?per_page=", per_page) | ||
|
||
# Add the include parameters to the URL | ||
if (length(include) > 0) { | ||
url <- paste0(url, "&include[]=", paste(include, collapse = "&include[]=")) | ||
} | ||
|
||
# Make the API request | ||
response <- httr::GET(url, httr::add_headers(Authorization = paste("Bearer", canvas$api_key))) | ||
|
||
# Check the response status code | ||
if (httr::status_code(response) != 200) { | ||
stop("Failed to retrieve course users. Please check your authentication and API endpoint.") | ||
} | ||
|
||
# Parse the response as JSON | ||
users <- httr::content(response, "text", encoding = "UTF-8") %>% | ||
jsonlite::fromJSON(flatten = TRUE) %>% | ||
as.data.frame() %>% | ||
dplyr::mutate(course_id = course_id) | ||
|
||
# Return the list of users | ||
return(users) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.