diff --git a/NAMESPACE b/NAMESPACE index 816e7c9..c071f24 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,6 +21,7 @@ export(get_course_list) export(get_course_user_groups) export(get_discussion_id) export(get_discussions_context) +export(get_folder_list) export(get_group_categories) export(get_group_category) export(get_group_users) @@ -39,6 +40,7 @@ export(set_canvas_token) export(show_wpage_front) export(submit_file_upload_assignment) export(update_discussion_id) +export(update_syllabus_body) export(update_wpage) export(upload_assignment_file) export(upload_course_file) diff --git a/R/announcements.R b/R/announcements.R index c45bc2d..ffa5542 100644 --- a/R/announcements.R +++ b/R/announcements.R @@ -19,7 +19,7 @@ get_announcements <- function(course_id, start_date = NULL, end_date = NULL, if (!grepl(pattern = "course", x = course_id)) { course_id <- paste0("course_", course_id) } - url <- paste0(canvas_url(), "announcements") + url <- file.path(canvas_url(), "announcements") args <- list(per_page = 100) include <- iter_args_list(course_id, "context_codes[]") include2 <- iter_args_list(start_date, "start_date") diff --git a/R/pages.R b/R/pages.R index 972aeb5..965970e 100644 --- a/R/pages.R +++ b/R/pages.R @@ -70,7 +70,7 @@ create_wpage_front <- function(){ get_wpages_list <- function(course_id, sort_type = c("title", "created_at", "updated_at")[1], order_type = "asc", search = NULL, published = NULL){ # GET /api/v1/courses/:course_id/pages - url <- paste0(canvas_url(), file.path("courses", course_id, "pages")) + url <- file.path(canvas_url(), file.path("courses", course_id, "pages")) args_list <- list(sort = sort_type, order = order_type) if(!is.null(search)) args_list <- c(args_list, search_term = search) if(!is.null(published)) args_list <- c(args_list, published = published) @@ -147,7 +147,7 @@ create_wpage <- function(course_id, title, body, editing_roles = "teachers", pub update_wpage <- function(course_id, page_url, title = NULL, body = NULL, editing_roles = "teachers", published = FALSE, notify = FALSE){ # PUT /api/v1/courses/:course_id/pages/:url # wiki_page[front_page] boolean Set an unhidden page as the front page (if true) - url <- paste0(canvas_url(), file.path("courses", course_id, "pages", page_url)) + url <- file.path(canvas_url(), file.path("courses", course_id, "pages", page_url)) args_list <- list(`wiki_page[editing_roles]` = editing_roles, `wiki_page[published]` = published, `wiki_page[notify_of_update]` = notify, @@ -186,4 +186,20 @@ delete_wpage <- function(course_id, page_url){ } +#' Update syllabus body +#' +#' @param course_id a valid course id +#' +#' @return invisible +#' @export +#' +update_syllabus_body <- function(course_id, body) { + url <- file.path(canvas_url(), file.path("courses", course_id)) + args <- sc(list(`course[syllabus_body]` = body)) + resp <- canvas_query(url, args, "PUT") + + httr::stop_for_status(resp) + message("Syllabus body updated") + return(resp) +} diff --git a/R/submissions.R b/R/submissions.R index 1ff354a..b08b3f6 100644 --- a/R/submissions.R +++ b/R/submissions.R @@ -77,7 +77,7 @@ NULL #' \dontrun{comment_submission(1350207, 5681164, 4928217, "test")} comment_submission <- function(course_id, assignment_id, user_id, comm, to_group = TRUE, visible = TRUE) { - url <- paste0(canvas_url(), + url <- file.path(canvas_url(), paste("courses", course_id, "assignments", assignment_id, "submissions", user_id, sep = "/")) args <- list(access_token = check_token(), @@ -100,7 +100,7 @@ comment_submission <- function(course_id, assignment_id, user_id, comm, #' @examples #' \dontrun{grade_submission(1350207, 5681164, 4928217, 80)} grade_submission <- function(course_id, assignment_id, user_id, grade) { - url <- paste0(canvas_url(), + url <- file.path(canvas_url(), paste("courses", course_id, "assignments", assignment_id, "submissions", user_id, sep = "/")) args <- list(access_token = check_token(), diff --git a/R/uploads.R b/R/uploads.R index 6a2ddb4..345f9ba 100644 --- a/R/uploads.R +++ b/R/uploads.R @@ -65,22 +65,53 @@ upload_file <- function(url, file_name, parent_folder_id = NULL, parent_folder_p #' @param course_id a valid course id #' @param name name of the folder (required) #' @param parent_folder_id The id of the folder to store the file in. If this and parent_folder_path -#' are sent an error will be returned. If neither is given, a default folder will be used. +#' are sent an error will be returned. If neither is given, a default folder will be used. +#' @param parent_folder_path The path of the folder to store the new folder in. If this and +#' parent_folder_id are sent an error will be returned. If neither is given, a default folder will be used. #' #' @return invisible #' @export #' #' @examples #' create_course_folder(34232, name = "activities") -create_course_folder <- function(course_id, name, parent_folder_id = NULL) { - url <- paste0(canvas_url(), +create_course_folder <- function(course_id, name, parent_folder_id = NULL, parent_folder_path = "") { + url <- file.path(canvas_url(), paste("courses", course_id, "folders", sep = "/")) - args <- sc(list(name = name, - parent_folder_id = parent_folder_id)) + + if (length(parent_folder_id) == 0) { + url_check <- rcanvas:::make_canvas_url("courses", course_id, file.path("folders/by_path", parent_folder_path)) %>% + file.path(name) + check <- try(process_response(url_check, NULL), silent = TRUE) + if (!inherits(check, "try-error")) { + message(sprintf("Folder %s already exists", name)) + return(invisible()) + } + args <- sc(list(name = name, + parent_folder_path = parent_folder_path)) + } else { + args <- sc(list(name = name, + parent_folder_id = parent_folder_id)) + } + invisible(canvas_query(url, args, "POST")) message(sprintf("Folder %s created", name)) } +#' Function to list all folders. +#' +#' @param course_id Course ID +#' +#' @return data frame +#' @export +#' +#' @examples +#' get_folder_list(1234) +get_folder_list <- function(course_id) { + url <- make_canvas_url("courses", course_id, "folders") + args <- list(per_page = 100) + process_response(url, args) +} + #' Create a course assignment #' #' @param course_id a valid course id diff --git a/man/create_course_folder.Rd b/man/create_course_folder.Rd index 2b88885..c632311 100644 --- a/man/create_course_folder.Rd +++ b/man/create_course_folder.Rd @@ -4,7 +4,12 @@ \alias{create_course_folder} \title{Create a course folder} \usage{ -create_course_folder(course_id, name, parent_folder_id = NULL) +create_course_folder( + course_id, + name, + parent_folder_id = NULL, + parent_folder_path = "" +) } \arguments{ \item{course_id}{a valid course id} @@ -13,6 +18,9 @@ create_course_folder(course_id, name, parent_folder_id = NULL) \item{parent_folder_id}{The id of the folder to store the file in. If this and parent_folder_path are sent an error will be returned. If neither is given, a default folder will be used.} + +\item{parent_folder_path}{The path of the folder to store the new folder in. If this and +parent_folder_id are sent an error will be returned. If neither is given, a default folder will be used.} } \value{ invisible diff --git a/man/get_folder_list.Rd b/man/get_folder_list.Rd new file mode 100644 index 0000000..1016427 --- /dev/null +++ b/man/get_folder_list.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/uploads.R +\name{get_folder_list} +\alias{get_folder_list} +\title{Function to list all folders.} +\usage{ +get_folder_list(course_id) +} +\arguments{ +\item{course_id}{Course ID} +} +\value{ +data frame +} +\description{ +Function to list all folders. +} +\examples{ +get_folder_list(1234) +} diff --git a/man/rcanvas.Rd b/man/rcanvas.Rd index 058d531..40dffa2 100644 --- a/man/rcanvas.Rd +++ b/man/rcanvas.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/rcanvas-package.R +% Please edit documentation in R/rcanvas-package.r \docType{package} \name{rcanvas} \alias{rcanvas} diff --git a/man/update_syllabus_body.Rd b/man/update_syllabus_body.Rd new file mode 100644 index 0000000..376bc77 --- /dev/null +++ b/man/update_syllabus_body.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pages.R +\name{update_syllabus_body} +\alias{update_syllabus_body} +\title{Update syllabus body} +\usage{ +update_syllabus_body(course_id, body) +} +\arguments{ +\item{course_id}{a valid course id} +} +\value{ +invisible +} +\description{ +Update syllabus body +}