Skip to content

Commit

Permalink
feat: get favorites for user
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomeriko96 committed Jan 6, 2024
1 parent 79d057c commit bae2711
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export(get_department_participation_data)
export(get_department_statistics)
export(get_department_statistics_by_subaccount)
export(get_discussions)
export(get_favorite_courses)
export(get_group_categories)
export(get_group_info)
export(get_group_memberships)
Expand Down
35 changes: 35 additions & 0 deletions R/get_favorite_courses.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#' Get Favorite Courses in Canvas LMS
#'
#' Retrieves the data of favorite courses for the authenticated user using the Canvas LMS API.
#'
#' @param canvas A list containing the 'api_key' and 'base_url' for authentication.
#' @param exclude_blueprint_courses When set, only return courses that are not configured as blueprint courses (optional).
#'
#' @return The dataframe of favorite courses.
#' @export
#'
get_favorite_courses <- function(canvas, exclude_blueprint_courses = NULL) {
# Construct the API endpoint URL
url <- paste0(canvas$base_url, "/api/v1/users/self/favorites/courses")

# Add the query parameter to the URL
if (!is.null(exclude_blueprint_courses)) {
url <- httr::modify_url(url, query = list(exclude_blueprint_courses = exclude_blueprint_courses))
}

# 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 favorite courses. Please check your authentication and API endpoint.")
}

# Parse the response
favorite_courses <- httr::content(response, "text", encoding = "UTF-8") %>%
jsonlite::fromJSON(flatten = TRUE)

# Return the list of favorite courses
return(favorite_courses)
}
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@
- [ ] Get visible course navigation tools for a single course ExternalToolsController#visible_course_nav_tools ;
GET /api/v1/courses/:course_id/external_tools/visible_course_nav_tools

- [ ] List favorite courses FavoritesController#list_favorite_courses ;
- [x] List favorite courses FavoritesController#list_favorite_courses ;
GET /api/v1/users/self/favorites/courses

- [ ] List favorite groups FavoritesController#list_favorite_groups ;
Expand Down
10 changes: 5 additions & 5 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,11 @@ reference:
# - remove_tool_from_rce_favorites
# - get_visible_course_navigation_tools
# - get_visible_course_navigation_tools_for_a_single_course
# - title: Favorites
# desc: >
# Retrieve the list of favorite courses.
# contents:
# - list_favorite_courses
- title: Favorites
desc: >
Methods of favorites.
contents:
- get_favorite_courses
# - list_favorite_groups
# - add_course_to_favorites
# - add_group_to_favorites
Expand Down
19 changes: 19 additions & 0 deletions man/get_favorite_courses.Rd

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

0 comments on commit bae2711

Please sign in to comment.