Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use file.path for update_wpage #49

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/announcements.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
20 changes: 18 additions & 2 deletions R/pages.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}

4 changes: 2 additions & 2 deletions R/submissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down
41 changes: 36 additions & 5 deletions R/uploads.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion man/create_course_folder.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions man/get_folder_list.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/rcanvas.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions man/update_syllabus_body.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.