diff --git a/NAMESPACE b/NAMESPACE index 38a9e9d..7c80a24 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,6 +15,7 @@ export(get_accounts) export(get_all_courses) export(get_assignment_data) export(get_assignment_details) +export(get_assignment_groups) export(get_assignment_submissions) export(get_assignments) export(get_calendar_events) @@ -24,11 +25,13 @@ export(get_course_enrollments) export(get_course_files) export(get_course_folders) export(get_course_groups) +export(get_course_media_objects) export(get_course_pages) export(get_course_participation) export(get_course_quizzes) export(get_course_sections) export(get_course_students) +export(get_course_users) export(get_courses) export(get_department_grade_data) export(get_department_participation_data) diff --git a/R/get_assignment_groups.R b/R/get_assignment_groups.R new file mode 100644 index 0000000..ab8a1e1 --- /dev/null +++ b/R/get_assignment_groups.R @@ -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) +} diff --git a/R/get_course_folders.R b/R/get_course_folders.R index 66dd42f..8944a71 100644 --- a/R/get_course_folders.R +++ b/R/get_course_folders.R @@ -25,7 +25,7 @@ get_course_folders <- function(canvas, course_id, per_page = 100) { folders <- httr::content(response, "text", encoding = "UTF-8") %>% jsonlite::fromJSON(flatten = TRUE) %>% as.data.frame() %>% - mutate(course_id = course_id) + dplyr::mutate(course_id = course_id) # Return the data frame of folders return(folders) diff --git a/R/get_course_media_objects.R b/R/get_course_media_objects.R new file mode 100644 index 0000000..e29ec3b --- /dev/null +++ b/R/get_course_media_objects.R @@ -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) +} diff --git a/R/get_course_users.R b/R/get_course_users.R new file mode 100644 index 0000000..d626bf4 --- /dev/null +++ b/R/get_course_users.R @@ -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) +} diff --git a/_pkgdown.yml b/_pkgdown.yml index bedf868..7f38863 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -131,7 +131,7 @@ reference: desc: > Methos for assignment groups. contents: -# - list_assignment_groups + - get_assignment_groups # - get_assignment_group - create_assignment_group # - edit_assignment_group @@ -373,6 +373,7 @@ reference: # - create_new_course # - upload_file - get_course_students + - get_course_users # - get_single_user # - search_for_content_share_users # - preview_processed_html @@ -677,11 +678,11 @@ reference: # contents: # - list_media_tracks # - update_media_tracks -# - title: Media Objects -# desc: > -# Retrieve the list of Media Objects. -# contents: -# - list_media_objects +- title: Media Objects + desc: > + Retrieve the list of Media Objects. + contents: + - get_course_media_objects # - update_media_object # - title: Moderation Set # desc: > diff --git a/man/get_assignment_groups.Rd b/man/get_assignment_groups.Rd new file mode 100644 index 0000000..ccf6375 --- /dev/null +++ b/man/get_assignment_groups.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_assignment_groups.R +\name{get_assignment_groups} +\alias{get_assignment_groups} +\title{Retrieves the assignment groups within a course.} +\usage{ +get_assignment_groups(canvas, course_id, per_page = 100) +} +\arguments{ +\item{canvas}{An object containing the Canvas API key and base URL, obtained through the \code{canvas_authenticate} function.} + +\item{course_id}{The ID of the course for which to fetch the assignment groups.} + +\item{per_page}{The number of entries to show per page.} +} +\value{ +A list of assignment groups within the specified course. +} +\description{ +This function retrieves the assignment groups within a specific course in the Canvas LMS API. +} diff --git a/man/get_course_media_objects.Rd b/man/get_course_media_objects.Rd new file mode 100644 index 0000000..7422dd4 --- /dev/null +++ b/man/get_course_media_objects.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_course_media_objects.R +\name{get_course_media_objects} +\alias{get_course_media_objects} +\title{Retrieves the media objects in a course.} +\usage{ +get_course_media_objects(canvas, course_id, per_page = 100) +} +\arguments{ +\item{canvas}{An object containing the Canvas API key and base URL, obtained through the \code{canvas_authenticate} function.} + +\item{course_id}{The ID of the course for which to fetch the media objects.} + +\item{per_page}{The number of entries to show per page.} +} +\value{ +A data frame containing the media objects in the specified course. +} +\description{ +This function retrieves the media objects associated with a specific course in the Canvas LMS API. +} diff --git a/man/get_course_users.Rd b/man/get_course_users.Rd new file mode 100644 index 0000000..5561b35 --- /dev/null +++ b/man/get_course_users.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_course_users.R +\name{get_course_users} +\alias{get_course_users} +\title{Retrieves the users in a course.} +\usage{ +get_course_users( + canvas, + course_id, + per_page = 100, + include = c("enrollments", "locked", "avatar_url", "test_student", "bio", + "custom_links", "current_grading_period_scores", "uuid") +) +} +\arguments{ +\item{canvas}{An object containing the Canvas API key and base URL, obtained through the \code{canvas_authenticate} function.} + +\item{course_id}{The ID of the course for which to fetch the users.} + +\item{per_page}{The number of entries to show per page.} + +\item{include}{Optional parameters to include in the response. Possible values: "enrollments", "locked", "avatar_url", "test_student", "bio", "custom_links", "current_grading_period_scores", "uuid".} +} +\value{ +A data frame containing the users in the specified course. +} +\description{ +This function retrieves the users enrolled in a specific course in the Canvas LMS API. +}