-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
e655441
commit 79d057c
Showing
9 changed files
with
218 additions
and
30 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,26 @@ | ||
#' Delete a Course Section in Canvas LMS | ||
#' | ||
#' Deletes an existing course section using the Canvas LMS API. | ||
#' | ||
#' @param canvas A list containing the 'api_key' and 'base_url' for authentication. | ||
#' @param section_id The ID of the section to delete. | ||
#' | ||
#' @return A confirmation message that the section has been deleted. | ||
#' @export | ||
#' | ||
delete_course_section <- function(canvas, section_id) { | ||
# Construct the API endpoint URL | ||
url <- paste0(canvas$base_url, "/api/v1/sections/", section_id) | ||
|
||
# Make the API request | ||
response <- httr::DELETE(url, | ||
httr::add_headers(Authorization = paste("Bearer", canvas$api_key))) | ||
|
||
# Check the response status code | ||
if (httr::status_code(response) != 200) { | ||
stop("Failed to delete course section. Please check your authentication and API endpoint.") | ||
} | ||
|
||
# Return a confirmation message | ||
return("The course section has been deleted.") | ||
} |
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,45 @@ | ||
#' Edit a Course Section in Canvas LMS | ||
#' | ||
#' Modifies an existing course section using the Canvas LMS API. | ||
#' | ||
#' @param canvas A list containing the 'api_key' and 'base_url' for authentication. | ||
#' @param section_id The ID of the section to edit. | ||
#' @param section_name The new name of the section (optional). | ||
#' @param sis_section_id The new SIS ID of the section (optional). | ||
#' @param integration_id The new integration ID of the section (optional). | ||
#' @param section_start_date The new start date of the section (optional). | ||
#' @param section_end_date The new end date of the section (optional). | ||
#' @param restrict_enrollments_to_section_dates Whether to restrict user enrollments to the start and end dates of the section (optional). | ||
#' @param override_sis_stickiness Whether to override SIS stickiness (optional). | ||
#' | ||
#' @return A confirmation message that the section has been edited. | ||
#' @export | ||
#' | ||
edit_section <- function(canvas, section_id, section_name = NULL, sis_section_id = NULL, integration_id = NULL, section_start_date = NULL, section_end_date = NULL, restrict_enrollments_to_section_dates = NULL, override_sis_stickiness = NULL) { | ||
# Construct the API endpoint URL | ||
url <- paste0(canvas$base_url, "/api/v1/sections/", section_id) | ||
|
||
# Create the request payload | ||
payload <- list() | ||
if (!is.null(section_name)) payload$course_section$name <- section_name | ||
if (!is.null(sis_section_id)) payload$course_section$sis_section_id <- sis_section_id | ||
if (!is.null(integration_id)) payload$course_section$integration_id <- integration_id | ||
if (!is.null(section_start_date)) payload$course_section$start_at <- section_start_date | ||
if (!is.null(section_end_date)) payload$course_section$end_at <- section_end_date | ||
if (!is.null(restrict_enrollments_to_section_dates)) payload$course_section$restrict_enrollments_to_section_dates <- restrict_enrollments_to_section_dates | ||
if (!is.null(override_sis_stickiness)) payload$override_sis_stickiness <- override_sis_stickiness | ||
|
||
# Make the API request | ||
response <- httr::PUT(url, | ||
httr::add_headers(Authorization = paste("Bearer", canvas$api_key)), | ||
body = payload, | ||
encode = "json") | ||
|
||
# Check the response status code | ||
if (httr::status_code(response) != 200) { | ||
stop("Failed to edit course section. Please check your authentication and API endpoint.") | ||
} | ||
|
||
# Return a confirmation message | ||
return("The course section has been edited.") | ||
} |
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,32 @@ | ||
#' Get Section Information in Canvas LMS | ||
#' | ||
#' Retrieves information about a specific course section using the Canvas LMS API. | ||
#' | ||
#' @param canvas A list containing the 'api_key' and 'base_url' for authentication. | ||
#' @param course_id The ID of the course. | ||
#' @param section_id The ID of the section. | ||
#' | ||
#' @return The information about the section. | ||
#' @export | ||
#' | ||
get_section_information <- function(canvas, course_id, section_id) { | ||
# Construct the API endpoint URL | ||
url <- paste0(canvas$base_url, "/api/v1/courses/", course_id, "/sections/", section_id) | ||
|
||
# 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 section information. Please check your authentication and API endpoint.") | ||
} | ||
|
||
# Parse the response | ||
section_info <- httr::content(response, "text", encoding = "UTF-8") %>% | ||
jsonlite::fromJSON(flatten = TRUE) %>% | ||
dplyr::bind_rows() | ||
|
||
# Return the section information | ||
return(section_info) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.