diff --git a/NAMESPACE b/NAMESPACE index ed91356..22d6508 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,6 +15,8 @@ export(delete_course_section) export(delete_page) export(download_course_file) export(edit_section) +export(get_account_rubric) +export(get_account_rubrics) export(extract_next_url) export(get_accounts) export(get_all_courses) @@ -52,6 +54,8 @@ export(get_module_items) export(get_modules) export(get_page_content) export(get_roles) +export(get_rubric) +export(get_rubrics) export(get_section_information) export(get_section_students) export(get_student_summaries) diff --git a/R/get_account_rubric.R b/R/get_account_rubric.R new file mode 100644 index 0000000..36feb4a --- /dev/null +++ b/R/get_account_rubric.R @@ -0,0 +1,30 @@ +#' Get Single Account Rubric from Canvas LMS API +#' +#' Fetches a single rubric by ID from a specific account in the Canvas LMS API. +#' +#' @param canvas A list containing the 'api_key' and 'base_url' for authentication. +#' @param account_id The ID of the account containing the rubric. +#' @param rubric_id The ID of the rubric to retrieve. +#' +#' @return A rubric object retrieved from the Canvas LMS API. +#' @export +#' +get_account_rubric <- function(canvas, account_id, rubric_id) { + # Construct the API endpoint URL + url <- paste0(canvas$base_url, "/api/v1/accounts/", account_id, "/rubrics/", rubric_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 account rubric. Please check your authentication and API endpoint.") + } + + # Parse the response as JSON + rubric <- httr::content(response, "text", encoding = "UTF-8") %>% + jsonlite::fromJSON(flatten = TRUE) + + # Return the rubric + return(rubric) +} \ No newline at end of file diff --git a/R/get_account_rubrics.R b/R/get_account_rubrics.R new file mode 100644 index 0000000..f1f95fc --- /dev/null +++ b/R/get_account_rubrics.R @@ -0,0 +1,37 @@ +#' Get Account Rubrics from Canvas LMS API +#' +#' Fetches a list of rubrics within a specific account from the Canvas LMS API. +#' +#' @param canvas A list containing the 'api_key' and 'base_url' for authentication. +#' @param account_id The ID of the account for which to retrieve the rubrics. +#' @param per_page Number of rubrics to retrieve per page. Default is 100. +#' +#' @return A list of rubrics retrieved from the Canvas LMS API. +#' @export +#' +get_account_rubrics <- function(canvas, account_id, per_page = 100) { + # Construct the API endpoint URL + url <- paste0(canvas$base_url, "/api/v1/accounts/", account_id, "/rubrics?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 account rubrics. Please check your authentication and API endpoint.") + } + + # Use pagination helper to get all pages + responses <- paginate(response, canvas$api_key) + + # Parse and combine all results + rubrics_list <- lapply(responses, function(resp) { + httr::content(resp, "text", encoding = "UTF-8") %>% + jsonlite::fromJSON(flatten = TRUE) %>% + as.data.frame() + }) + rubrics <- dplyr::bind_rows(rubrics_list) + + # Return the list of rubrics + return(rubrics) +} \ No newline at end of file diff --git a/R/get_rubric.R b/R/get_rubric.R new file mode 100644 index 0000000..fd6ff94 --- /dev/null +++ b/R/get_rubric.R @@ -0,0 +1,30 @@ +#' Get Single Rubric from Canvas LMS API +#' +#' Fetches a single rubric by ID from a specific course in 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 containing the rubric. +#' @param rubric_id The ID of the rubric to retrieve. +#' +#' @return A rubric object retrieved from the Canvas LMS API. +#' @export +#' +get_rubric <- function(canvas, course_id, rubric_id) { + # Construct the API endpoint URL + url <- paste0(canvas$base_url, "/api/v1/courses/", course_id, "/rubrics/", rubric_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 rubric. Please check your authentication and API endpoint.") + } + + # Parse the response as JSON + rubric <- httr::content(response, "text", encoding = "UTF-8") %>% + jsonlite::fromJSON(flatten = TRUE) + + # Return the rubric + return(rubric) +} \ No newline at end of file diff --git a/R/get_rubrics.R b/R/get_rubrics.R new file mode 100644 index 0000000..2e223ad --- /dev/null +++ b/R/get_rubrics.R @@ -0,0 +1,37 @@ +#' Get Rubrics from Canvas LMS API +#' +#' Fetches a list of rubrics within a specific course from 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 for which to retrieve the rubrics. +#' @param per_page Number of rubrics to retrieve per page. Default is 100. +#' +#' @return A list of rubrics retrieved from the Canvas LMS API. +#' @export +#' +get_rubrics <- function(canvas, course_id, per_page = 100) { + # Construct the API endpoint URL + url <- paste0(canvas$base_url, "/api/v1/courses/", course_id, "/rubrics?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 rubrics. Please check your authentication and API endpoint.") + } + + # Use pagination helper to get all pages + responses <- paginate(response, canvas$api_key) + + # Parse and combine all results + rubrics_list <- lapply(responses, function(resp) { + httr::content(resp, "text", encoding = "UTF-8") %>% + jsonlite::fromJSON(flatten = TRUE) %>% + as.data.frame() + }) + rubrics <- dplyr::bind_rows(rubrics_list) + + # Return the list of rubrics + return(rubrics) +} \ No newline at end of file diff --git a/TODO.md b/TODO.md index f8386d9..1178ada 100644 --- a/TODO.md +++ b/TODO.md @@ -2326,16 +2326,16 @@ - [ ] Delete a single rubric RubricsController#destroy ; DELETE /api/v1/courses/:course_id/rubrics/:id -- [ ] List rubrics RubricsApiController#index ; +- [x] List rubrics RubricsApiController#index ; GET /api/v1/accounts/:account_id/rubrics - -- [ ] List rubrics RubricsApiController#index ; + +- [x] List rubrics RubricsApiController#index ; GET /api/v1/courses/:course_id/rubrics - -- [ ] Get a single rubric RubricsApiController#show ; + +- [x] Get a single rubric RubricsApiController#show ; GET /api/v1/accounts/:account_id/rubrics/:id - -- [ ] Get a single rubric RubricsApiController#show ; + +- [x] Get a single rubric RubricsApiController#show ; GET /api/v1/courses/:course_id/rubrics/:id - [ ] Create a single rubric assessment RubricAssessmentsController#create ; diff --git a/_pkgdown.yml b/_pkgdown.yml index 875c017..49e30dd 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1067,15 +1067,17 @@ reference: # - deactivate_role # - activate_role # - update_role -# title: Rubrics -# desc: > -# Manage rubrics. -# contents: +- title: Rubrics + desc: > + Manage rubrics. + contents: + - get_rubrics + - get_rubric + - get_account_rubrics + - get_account_rubric # - create_rubric # - update_rubric # - delete_rubric -# - list_rubrics -# - get_single_rubric # # title: RubricAssessments # desc: > diff --git a/man/get_account_rubric.Rd b/man/get_account_rubric.Rd new file mode 100644 index 0000000..0b1bda9 --- /dev/null +++ b/man/get_account_rubric.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_account_rubric.R +\name{get_account_rubric} +\alias{get_account_rubric} +\title{Get Single Account Rubric from Canvas LMS API} +\usage{ +get_account_rubric(canvas, account_id, rubric_id) +} +\arguments{ +\item{canvas}{A list containing the 'api_key' and 'base_url' for authentication.} + +\item{account_id}{The ID of the account containing the rubric.} + +\item{rubric_id}{The ID of the rubric to retrieve.} +} +\value{ +A rubric object retrieved from the Canvas LMS API. +} +\description{ +Fetches a single rubric by ID from a specific account in the Canvas LMS API. +} \ No newline at end of file diff --git a/man/get_account_rubrics.Rd b/man/get_account_rubrics.Rd new file mode 100644 index 0000000..acdcb30 --- /dev/null +++ b/man/get_account_rubrics.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_account_rubrics.R +\name{get_account_rubrics} +\alias{get_account_rubrics} +\title{Get Account Rubrics from Canvas LMS API} +\usage{ +get_account_rubrics(canvas, account_id, per_page = 100) +} +\arguments{ +\item{canvas}{A list containing the 'api_key' and 'base_url' for authentication.} + +\item{account_id}{The ID of the account for which to retrieve the rubrics.} + +\item{per_page}{Number of rubrics to retrieve per page. Default is 100.} +} +\value{ +A list of rubrics retrieved from the Canvas LMS API. +} +\description{ +Fetches a list of rubrics within a specific account from the Canvas LMS API. +} \ No newline at end of file diff --git a/man/get_rubric.Rd b/man/get_rubric.Rd new file mode 100644 index 0000000..11f6a33 --- /dev/null +++ b/man/get_rubric.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_rubric.R +\name{get_rubric} +\alias{get_rubric} +\title{Get Single Rubric from Canvas LMS API} +\usage{ +get_rubric(canvas, course_id, rubric_id) +} +\arguments{ +\item{canvas}{A list containing the 'api_key' and 'base_url' for authentication.} + +\item{course_id}{The ID of the course containing the rubric.} + +\item{rubric_id}{The ID of the rubric to retrieve.} +} +\value{ +A rubric object retrieved from the Canvas LMS API. +} +\description{ +Fetches a single rubric by ID from a specific course in the Canvas LMS API. +} \ No newline at end of file diff --git a/man/get_rubrics.Rd b/man/get_rubrics.Rd new file mode 100644 index 0000000..247f25f --- /dev/null +++ b/man/get_rubrics.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_rubrics.R +\name{get_rubrics} +\alias{get_rubrics} +\title{Get Rubrics from Canvas LMS API} +\usage{ +get_rubrics(canvas, course_id, per_page = 100) +} +\arguments{ +\item{canvas}{A list containing the 'api_key' and 'base_url' for authentication.} + +\item{course_id}{The ID of the course for which to retrieve the rubrics.} + +\item{per_page}{Number of rubrics to retrieve per page. Default is 100.} +} +\value{ +A list of rubrics retrieved from the Canvas LMS API. +} +\description{ +Fetches a list of rubrics within a specific course from the Canvas LMS API. +} \ No newline at end of file