You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To improve the package's control over Canvas elements it would be great to be able to create new Modules. A sketch of a function allowing for that would be:
create_module <- function(canvas, course_id, module_name, position = NULL)
{
url <- paste0(canvas$base_url, "/api/v1/courses/", course_id,
"/modules")
payload <- list(module = list(name = module_name, position = position))
response <- httr::POST(url, httr::add_headers(Authorization = paste("Bearer",
canvas$api_key)), body = payload, encode = "json")
if (httr::status_code(response) != 200) {
stop("Failed to create module. Please check your authentication and API endpoint.")
}
return("The module has been created.")
}
The possibility to create new items within modules
Also it would be nice to create new Items within a module. Below you find a sketch of a function allowing for adding content:
create_module_item <- function(canvas, course_id, module_id, item_title, item_type = "Page",
position = NULL, page_url = NULL, page_id = NULL)
{
if(item_type == "Page"){
url <- paste0(canvas$base_url, "/api/v1/courses/", course_id,
"/pages/", page_id)
page <- httr::GET(url, httr::add_headers(Authorization = paste("Bearer", canvas$api_key)))
page_url <- httr::content(page)$url
}
url <- paste0(canvas$base_url, "/api/v1/courses/", course_id,
"/modules/", module_id, "/items/")
payload <- list(module_item = list(title = item_title, type = item_type,
position = position, page_url = page_url))
response <- httr::POST(url, httr::add_headers(Authorization = paste("Bearer",
canvas$api_key)), body = payload, encode = "json")
if (httr::status_code(response) != 200) {
stop("Failed to create module item. Please check your authentication and API endpoint.")
}
return("The module item has been created.")
}
This function now has a focus on adding existing pages to a module and for other item types tailored arguments may have to be added.
The possibility to update or delete created elements
Not only for the two suggested functions above, but also for an existing function like create_page() it seems useful to add functions to either delete or update existing elements. This is also convenient for publishing newly created elements as Canvas does not seem to allow for setting these published argument while creating, but needs an additional update step.
The text was updated successfully, but these errors were encountered:
Sure, I could do that. As I am not used to working in github, I will have to set up things and learn how stuff may be added, so it may take a while (R/exams' version control is done in https://r-forge.r-project.org).
The Possibility to create new modules.
To improve the package's control over Canvas elements it would be great to be able to create new Modules. A sketch of a function allowing for that would be:
The possibility to create new items within modules
Also it would be nice to create new Items within a module. Below you find a sketch of a function allowing for adding content:
This function now has a focus on adding existing pages to a module and for other item types tailored arguments may have to be added.
The possibility to update or delete created elements
Not only for the two suggested functions above, but also for an existing function like
create_page()
it seems useful to add functions to either delete or update existing elements. This is also convenient for publishing newly created elements as Canvas does not seem to allow for setting thesepublished
argument while creating, but needs an additional update step.The text was updated successfully, but these errors were encountered: