|
- url_nc_cf_search_doc <- function() {
- "https://cf.ncsbe.gov/CFDocLkup/DocumentResult/"
- }
-
- url_nc_cf_export_search_doc <- function() {
- "https://cf.ncsbe.gov/CFDocLkup/ExportSearchResults/"
- }
-
- match_report_type <- function(report, collapse = TRUE) {
- report <- toupper(report)
-
- reports <- c("RPMYSA", "RPYESA", "RPQTR1", "RPQTR2", "RPQTR3", "RPQTR4")
- valid <- c(
- reports,
- sub("^RP", "", reports),
- gsub("^RP|SA$", "", reports),
- sub("RPQTR", "Q", reports)
- )
- names(valid) <- rep(reports, 4)
-
- x <- names(valid)[match(report, valid)]
- if (any(is.na(x))) {
- report <- report[is.na(x)]
- cli::cli_abort(c("Invalid report {.val {report}}", i = "Valid: {.val {reports}}"))
- }
-
- if (!collapse) return(x)
-
- paste(paste0("'", x, "'"), collapse = ", ")
- }
-
- req_report_by_year <- function(
- year,
- report = c("RPMYSA", "RPYESA", "RPQTR1", "RPQTR2", "RPQTR3", "RPQTR4")
- ) {
- reports <- match_report_type(report)
-
- req <- request(url_nc_cf_search_doc())
- req <- req_url_query(req, year = year, reports = reports)
-
- req
- }
-
- req_report_by_year_export <- function(
- year,
- report = c("RPMYSA", "RPYESA", "RPQTR1", "RPQTR2", "RPQTR3", "RPQTR4")
- ) {
- reports <- match_report_type(report)
-
- req <- request(url_nc_cf_export_search_doc())
- req <- req_url_query(req, year = year, reports = reports)
-
- req
- }
|