Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
^DECISIONS\.md$
^README\.Rmd$
^CLAUDE\.md$
^.*\.Rproj$
^\.Rproj\.user$
^CRAN-SUBMISSION$
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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")),
Expand Down
15 changes: 15 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 3 additions & 0 deletions R/aliases.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 21 additions & 14 deletions R/people.R
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand All @@ -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")
}
Expand All @@ -54,19 +57,23 @@ 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()
#' alepe_positions(status = "commissioned")
#' @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")
}
Expand Down
12 changes: 10 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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]])
}
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
7 changes: 3 additions & 4 deletions man/alepe_aliases.Rd

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

3 changes: 2 additions & 1 deletion man/alepe_positions.Rd

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

10 changes: 7 additions & 3 deletions man/alepe_staff.Rd

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

24 changes: 24 additions & 0 deletions tests/testthat/test-endpoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
3 changes: 3 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
Loading