Skip to content

Commit

Permalink
Improve entity_list: add parameter deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
florianm committed Apr 1, 2024
1 parent cbce233 commit c8c0d34
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 53 deletions.
11 changes: 7 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Type: Package
Package: ruODK
Title: An R Client for the ODK Central API
Version: 1.4.9.9004
Version: 1.4.9.9005
Authors@R:
c(person(given = c("Florian", "W."),
family = "Mayer",
role = c("aut", "cre"),
email = "Florian.Mayer@dbca.wa.gov.au",
email = "Florian.Mayer@dpc.wa.gov.au",
comment = c(ORCID = "0000-0003-4269-4242")),
person(given = "Maëlle",
family = "Salmon",
Expand All @@ -33,9 +33,12 @@ Authors@R:
person(given = "NWSFTCP",
role = "fnd"))
Description: Access and tidy up data from the 'ODK Central' API.
'ODK Central' is a clearinghouse for digitally captured data
'ODK Central' is a clearinghouse for digitally captured data using ODK
<https://docs.getodk.org/central-intro/>.
'ODK Central' and its API are documented at <https://docs.getodk.org/>.
It manages user accounts and permissions, stores form definitions, and
allows data collection clients like 'ODK Collect' to connect to it for form
download and submission upload. The 'ODK Central' API is documented at
<https://docs.getodk.org/central-api/>.
License: GPL-3
URL: https://docs.ropensci.org/ruODK,
https://github.com/ropensci/ruODK
Expand Down
70 changes: 37 additions & 33 deletions R/entity_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
#' This function returns a list of the Entities of a kind (belonging to an
#' Entity List or Dataset).
#' Please note that this endpoint only returns metadata of the entities, not the
#' data. If you want to get the data of all entities then please refer to OData
#' Dataset Service
#' data. If you want to get the data of all entities then please refer to the
#' OData Dataset Service.
#'
#' You can provide ?deleted=true to get only deleted entities.
#'
#' `entity_list()` will fail with incorrect or missing authentication.
#'
#' This function is supported from ODK Central v2022.3 and will warn if the
#' given odkc_version is lower.
#' You can get only deleted entities with `deleted=TRUE`.
#'
#' @template tpl-auth-missing
#' @template tpl-compat-2022-3
#' @template param-pid
#' @template param-did
#' @param deleted (bool) Whether to get only deleted entities (`TRUE`) or not
#' (`FALSE`). Default: `FALSE`.
#' @template param-url
#' @template param-auth
#' @template param-retries
Expand All @@ -36,36 +35,37 @@
#' # See vignette("setup") for setup and authentication options
#' # ruODK::ru_setup(svc = "....svc", un = "[email protected]", pw = "...")
#'
#' el <- entitylist_list()
#' el <- entitylist_list()
#'
#' # Entity List name (dataset ID)
#' did <- el$name[1]
#' # Entity List name (dataset ID)
#' did <- el$name[1]
#'
#' # All Entities of Entity List
#' en <- entity_list(did = el$name[1])
#' # All Entities of Entity List
#' en <- entity_list(did = el$name[1])
#'
#' # The UUID of the first Entity
#' eid <- en$uuid[1]
#' # The UUID of the first Entity
#' eid <- en$uuid[1]
#'
#' # The current version of the first Entity
#' ev <- en$current_version_version[1]
#' # The current version of the first Entity
#' ev <- en$current_version_version[1]
#' }
entity_list <- function(pid = get_default_pid(),
did = NULL,
url = get_default_url(),
un = get_default_un(),
pw = get_default_pw(),
retries = get_retries(),
odkc_version = get_default_odkc_version(),
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
tz = get_default_tz()) {
did = NULL,
deleted = FALSE,
url = get_default_url(),
un = get_default_un(),
pw = get_default_pw(),
retries = get_retries(),
odkc_version = get_default_odkc_version(),
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
tz = get_default_tz()) {
yell_if_missing(url, un, pw, pid = pid)

if (is.null(did)) {
Expand All @@ -80,6 +80,10 @@ entity_list <- function(pid = get_default_pid(),
"v1/projects/{pid}/datasets/{URLencode(did, reserved = TRUE)}/entities"
)

if (deleted == TRUE) {
pth <- glue::glue("{pth}?deleted=true")

Check warning on line 84 in R/entity_list.R

View check run for this annotation

Codecov / codecov/patch

R/entity_list.R#L84

Added line #L84 was not covered by tests
}

httr::RETRY(
"GET",
httr::modify_url(url, path = pth),
Expand All @@ -101,4 +105,4 @@ entity_list <- function(pid = get_default_pid(),
)
}

# usethis::use_test("entity_list") # nolint
# usethis::use_test("entity_list") # nolint
5 changes: 2 additions & 3 deletions R/isodt_to_local.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
isodt_to_local <- function(datetime_string,
orders = c("YmdHMS", "YmdHMSz"),
tz = get_default_tz(),
quiet=TRUE
) {
quiet = TRUE) {
datetime_string %>%
lubridate::parse_date_time(orders = orders, quiet=quiet) %>%
lubridate::parse_date_time(orders = orders, quiet = quiet) %>%
lubridate::with_tz(., tzone = tz)
}
15 changes: 7 additions & 8 deletions man/entity_list.Rd

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

2 changes: 1 addition & 1 deletion man/ruODK-package.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/test-entity_detail.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test_that("entitylist_detail errors if did is missing", {

test_that("entitylist_detail warns if odkc_version too low", {
skip_if(Sys.getenv("ODKC_TEST_URL") == "",
message = "Test server not configured"
message = "Test server not configured"
)

ru_setup(
Expand All @@ -77,4 +77,4 @@ test_that("entitylist_detail warns if odkc_version too low", {
})


# usethis::use_e("entity_detail") # nolint
# usethis::use_e("entity_detail") # nolint
4 changes: 2 additions & 2 deletions tests/testthat/test-entity_list.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("entity_list works", {
skip_if(Sys.getenv("ODKC_TEST_URL") == "",
message = "Test server not configured"
message = "Test server not configured"
)

ru_setup(
Expand All @@ -18,7 +18,7 @@ test_that("entity_list works", {

testthat::expect_s3_class(en, "tbl_df")

cn <- c(
cn <- c(
"uuid",
"created_at",
"creator_id",
Expand Down

0 comments on commit c8c0d34

Please sign in to comment.