diff --git a/.Rbuildignore b/.Rbuildignore index 28bdb36..15fe9c6 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,3 +10,6 @@ ^DECISIONS\.md$ ^README\.Rmd$ ^CLAUDE\.md$ +^.*\.Rproj$ +^\.Rproj\.user$ +^CRAN-SUBMISSION$ diff --git a/DESCRIPTION b/DESCRIPTION index ff1fc56..b2ccda3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: alepe Title: Access the Open Data API of the Legislative Assembly of Pernambuco -Version: 0.1.0 +Version: 0.1.0.9000 Authors@R: c( person("André", "Leite", email = "leite@castlab.org", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-4718-9766")), diff --git a/NEWS.md b/NEWS.md index 9f25588..d95f9c9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,18 @@ +# alepe (development version) + +* `alepe_staff()` gains `status = "lent"` (API term `"efetivo-cedido"`): + the Assembly's own permanent staff lent to other bodies. The API + publishes them with `vinculo` `"Efetivo"`, so this server-side filter + is the only way to single them out. `alepe_positions()` does not accept + it, because `/cargos` ignores the value and returns every status. +* An invalid `status` in `alepe_staff()` / `alepe_positions()` (and + their aliases) is now an error, as documented. It used to be evaluated + inside the fetch layer's error handler and surfaced as a warning that + the API could not be reached, followed by an empty tibble. +* Author metadata: the maintainer's name is spelled André Leite; Marcos + Wasiliew's e-mail address is updated; ORCIDs added for Marcos Wasiliew + and Júlia Nascimento Barreto. + # alepe 0.1.0 * Initial release. diff --git a/R/aliases.R b/R/aliases.R index 7119514..69fd4d2 100644 --- a/R/aliases.R +++ b/R/aliases.R @@ -28,6 +28,9 @@ #' `alepe_servidores(status = "efetivo")` and #' `alepe_staff(status = "permanent")` are the same query. #' +#' @param status Employment status filter, as in [alepe_staff()] and +#' [alepe_positions()]. `"lent"` (`"efetivo-cedido"`) is accepted by +#' `alepe_servidores()` only. #' @inheritParams alepe_staff #' @inheritParams alepe_bills #' @returns The same tibble the corresponding English function returns. diff --git a/R/people.R b/R/people.R index 6bd5970..b31e776 100644 --- a/R/people.R +++ b/R/people.R @@ -23,9 +23,13 @@ alepe_representatives <- function(refresh = FALSE) { #' employment status. #' #' @param status Employment status filter. One of `"permanent"`, -#' `"commissioned"`, or `"seconded"` (the original API terms -#' `"efetivo"`, `"comissionado"`, and `"a-disposicao"` are also -#' accepted), or `NULL` (default) for all. +#' `"commissioned"`, `"seconded"` (staff from other bodies placed at +#' the Assembly's disposal), or `"lent"` (the Assembly's own permanent +#' staff lent to other bodies, a subset of `"permanent"`); the original +#' API terms `"efetivo"`, `"comissionado"`, `"a-disposicao"`, and +#' `"efetivo-cedido"` are also accepted. `NULL` (default) for all. +#' Lent staff are published with `vinculo` `"Efetivo"`, so this filter +#' is the only way to tell them apart. #' @inheritParams alepe_representatives #' @returns A tibble with one row per staff member: `nome`, #' `codigo_lotacao`, `nome_lotacao`, `cargo_efetivo`, `cargo_nivel`, @@ -40,11 +44,10 @@ alepe_staff <- function(status = NULL, refresh = FALSE) { cargo_efetivo = "chr", cargo_nivel = "chr", vinculo = "chr", data_admissao = "date" ) - records <- alepe_fetch_json( - "servidores", - vinculo = map_status(status), - refresh = refresh - ) + # Resolved before the fetch: an argument evaluated lazily inside the + # fetch would be caught there and reported as an unreachable API. + vinculo <- map_status(status, lent = TRUE) + records <- alepe_fetch_json("servidores", vinculo = vinculo, refresh = refresh) out <- records_to_tibble(records, schema) report_rows(out, "staff members") } @@ -54,7 +57,12 @@ alepe_staff <- function(status = NULL, refresh = FALSE) { #' Retrieves the number of staff members per position/level, optionally #' filtered by employment status. #' -#' @inheritParams alepe_staff +#' @param status Employment status filter. One of `"permanent"`, +#' `"commissioned"`, or `"seconded"` (the original API terms +#' `"efetivo"`, `"comissionado"`, and `"a-disposicao"` are also +#' accepted), or `NULL` (default) for all. Unlike [alepe_staff()], +#' `"lent"` is not available: the API ignores it for this endpoint. +#' @inheritParams alepe_representatives #' @returns A tibble with `total` and `cargo_nivel`. Zero rows (with a #' warning) on network failure. #' @examplesIf interactive() @@ -62,11 +70,10 @@ alepe_staff <- function(status = NULL, refresh = FALSE) { #' @export alepe_positions <- function(status = NULL, refresh = FALSE) { schema <- c(total = "int", cargo_nivel = "chr") - records <- alepe_fetch_json( - "cargos", - vinculo = map_status(status), - refresh = refresh - ) + # Resolved before the fetch: an argument evaluated lazily inside the + # fetch would be caught there and reported as an unreachable API. + vinculo <- map_status(status) + records <- alepe_fetch_json("cargos", vinculo = vinculo, refresh = refresh) out <- records_to_tibble(records, schema) report_rows(out, "positions") } diff --git a/R/utils.R b/R/utils.R index 545c39b..8d7d6ee 100644 --- a/R/utils.R +++ b/R/utils.R @@ -232,10 +232,15 @@ decode_numeric_entities <- function(x) { #' #' @param status `NULL` (no filter) or one of `"permanent"`, #' `"commissioned"`, `"seconded"`, `"efetivo"`, `"comissionado"`, -#' `"a-disposicao"`. +#' `"a-disposicao"`; with `lent = TRUE`, also `"lent"` and +#' `"efetivo-cedido"`. +#' @param lent Whether to accept the `efetivo-cedido` value. Only +#' `/servidores` honours it; `/cargos` silently ignores it and returns +#' every status, so it must be rejected there (D22). #' @returns The API value, or `NULL`. #' @noRd -map_status <- function(status, error_call = rlang::caller_env()) { +map_status <- function(status, lent = FALSE, + error_call = rlang::caller_env()) { if (is.null(status)) { return(NULL) } @@ -247,6 +252,9 @@ map_status <- function(status, error_call = rlang::caller_env()) { comissionado = "comissionado", `a-disposicao` = "a-disposicao" ) + if (lent) { + map <- c(map, lent = "efetivo-cedido", `efetivo-cedido` = "efetivo-cedido") + } status <- rlang::arg_match(status, names(map), error_call = error_call) unname(map[[status]]) } diff --git a/README.md b/README.md index 3454608..673bcb0 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,9 @@ alepe_bills(year = 2024) ``` Filter values use an English vocabulary (`"permanent"`, -`"commissioned"`, `"seconded"`), but the original API terms -(`"efetivo"`, `"comissionado"`, `"a-disposicao"`) are accepted as well. +`"commissioned"`, `"seconded"`, `"lent"`), but the original API terms +(`"efetivo"`, `"comissionado"`, `"a-disposicao"`, `"efetivo-cedido"`) +are accepted as well. Column names keep the official Portuguese field names, normalized to snake_case, so results stay traceable to the source. diff --git a/man/alepe_aliases.Rd b/man/alepe_aliases.Rd index 153c642..eaf2a91 100644 --- a/man/alepe_aliases.Rd +++ b/man/alepe_aliases.Rd @@ -50,10 +50,9 @@ alepe_limpar_cache() \arguments{ \item{refresh}{If \code{TRUE}, bypass the local cache.} -\item{status}{Employment status filter. One of \code{"permanent"}, -\code{"commissioned"}, or \code{"seconded"} (the original API terms -\code{"efetivo"}, \code{"comissionado"}, and \code{"a-disposicao"} are also -accepted), or \code{NULL} (default) for all.} +\item{status}{Employment status filter, as in \code{\link[=alepe_staff]{alepe_staff()}} and +\code{\link[=alepe_positions]{alepe_positions()}}. \code{"lent"} (\code{"efetivo-cedido"}) is accepted by +\code{alepe_servidores()} only.} \item{numero}{Portuguese spelling of \code{number}.} diff --git a/man/alepe_positions.Rd b/man/alepe_positions.Rd index 67c2f73..01be9b9 100644 --- a/man/alepe_positions.Rd +++ b/man/alepe_positions.Rd @@ -10,7 +10,8 @@ alepe_positions(status = NULL, refresh = FALSE) \item{status}{Employment status filter. One of \code{"permanent"}, \code{"commissioned"}, or \code{"seconded"} (the original API terms \code{"efetivo"}, \code{"comissionado"}, and \code{"a-disposicao"} are also -accepted), or \code{NULL} (default) for all.} +accepted), or \code{NULL} (default) for all. Unlike \code{\link[=alepe_staff]{alepe_staff()}}, +\code{"lent"} is not available: the API ignores it for this endpoint.} \item{refresh}{If \code{TRUE}, bypass the local cache.} } diff --git a/man/alepe_staff.Rd b/man/alepe_staff.Rd index 52942a3..4681aff 100644 --- a/man/alepe_staff.Rd +++ b/man/alepe_staff.Rd @@ -8,9 +8,13 @@ alepe_staff(status = NULL, refresh = FALSE) } \arguments{ \item{status}{Employment status filter. One of \code{"permanent"}, -\code{"commissioned"}, or \code{"seconded"} (the original API terms -\code{"efetivo"}, \code{"comissionado"}, and \code{"a-disposicao"} are also -accepted), or \code{NULL} (default) for all.} +\code{"commissioned"}, \code{"seconded"} (staff from other bodies placed at +the Assembly's disposal), or \code{"lent"} (the Assembly's own permanent +staff lent to other bodies, a subset of \code{"permanent"}); the original +API terms \code{"efetivo"}, \code{"comissionado"}, \code{"a-disposicao"}, and +\code{"efetivo-cedido"} are also accepted. \code{NULL} (default) for all. +Lent staff are published with \code{vinculo} \code{"Efetivo"}, so this filter +is the only way to tell them apart.} \item{refresh}{If \code{TRUE}, bypass the local cache.} } diff --git a/tests/testthat/test-endpoints.R b/tests/testthat/test-endpoints.R index 3e011ce..94a3360 100644 --- a/tests/testthat/test-endpoints.R +++ b/tests/testthat/test-endpoints.R @@ -180,3 +180,27 @@ test_that("proposition detail parses one full record", { test_that("detail mode requires year alongside number", { expect_error(alepe_bills(number = 10), class = "alepe_error_input") }) + +test_that("status = 'lent' reaches /servidores but is refused by positions", { + sent <- NULL + local_mocked_bindings(alepe_fetch_json = function(endpoint, ...) { + sent <<- list(...)$vinculo + fixture_json("servidores.json") + }) + + alepe_staff(status = "lent") + expect_equal(sent, "efetivo-cedido") + alepe_servidores(status = "efetivo-cedido") + expect_equal(sent, "efetivo-cedido") + + expect_error(alepe_positions(status = "lent"), class = "rlang_error") +}) + +test_that("an invalid status is an input error, not a network warning", { + # The mock never touches `...`, as the real fetch layer would only + # evaluate it inside its own error handler. + local_mocked_bindings(alepe_fetch_json = function(...) list()) + + expect_error(alepe_staff(status = "nope"), class = "rlang_error") + expect_error(alepe_positions(status = "lent"), class = "rlang_error") +}) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 4b4ec64..f91e1b7 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -39,6 +39,9 @@ test_that("map_status accepts English and Portuguese vocabularies", { expect_equal(map_status("efetivo"), "efetivo") expect_equal(map_status("seconded"), "a-disposicao") expect_error(map_status("nope"), class = "rlang_error") + expect_equal(map_status("lent", lent = TRUE), "efetivo-cedido") + expect_equal(map_status("efetivo-cedido", lent = TRUE), "efetivo-cedido") + expect_error(map_status("lent"), class = "rlang_error") }) test_that("records_to_tibble builds typed tibbles and handles NULL", {