-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve caching; add academicyear as a parameter; harden errors and w…
…arnings; break apart processing from api requests
- Loading branch information
Showing
39 changed files
with
1,247 additions
and
440 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
S3method(print,explorecourses_cache_list) | ||
export(cache_exists) | ||
export(clear_cache) | ||
export(fetch_all_courses) | ||
export(fetch_department_courses) | ||
export(fetch_departments) | ||
export(parse_courses) | ||
export(read_cache) | ||
export(generate_academic_year) | ||
export(list_cache) | ||
export(read_xml_cache) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#' Make API request to ExploreCourses endpoint | ||
#' | ||
#' @param url API endpoint URL | ||
#' @return Raw response content or error | ||
#' @keywords internal | ||
#' @include constants.R | ||
make_api_request <- function(url) { | ||
tryCatch({ | ||
req <- httr2::request(url) |> | ||
httr2::req_perform() | ||
|
||
if (httr2::resp_status(req) != 200) { | ||
cli::cli_abort(c( | ||
"API request failed", | ||
"i" = "Status code: {httr2::resp_status(req)}", | ||
"i" = "Endpoint: {url}" | ||
)) | ||
} | ||
|
||
xml2::read_xml(httr2::resp_body_string(req)) | ||
}, error = function(e) { | ||
cli::cli_abort(c( | ||
"Failed to make API request", | ||
"x" = "{conditionMessage(e)}", | ||
"i" = "Endpoint: {url}" | ||
)) | ||
}) | ||
} | ||
|
||
#' Fetch raw department data from API | ||
#' | ||
#' @return Raw XML content | ||
#' @keywords internal | ||
fetch_departments_raw <- function() { | ||
make_api_request(DEPARTMENTS_ENDPOINT) | ||
} | ||
|
||
#' Fetch raw course data for a department from API | ||
#' | ||
#' @param name Department code | ||
#' @param year Academic year in format YYYYYYYY or NULL for current year | ||
#' @return Raw XML content | ||
#' @keywords internal | ||
fetch_department_courses_raw <- function(name, year = NULL) { | ||
year <- validate_academic_year(year) | ||
url <- glue::glue(COURSE_ENDPOINT, year = year, name = name) | ||
make_api_request(url) | ||
} |
Oops, something went wrong.