Skip to content

Commit

Permalink
Add entity_version, add get_default_orders
Browse files Browse the repository at this point in the history
  • Loading branch information
florianm committed Jul 26, 2024
1 parent 6f87d3d commit c6f09b5
Show file tree
Hide file tree
Showing 38 changed files with 365 additions and 144 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export(entity_delete)
export(entity_detail)
export(entity_list)
export(entity_update)
export(entity_versions)
export(entitylist_detail)
export(entitylist_download)
export(entitylist_list)
Expand All @@ -30,6 +31,7 @@ export(form_schema_parse)
export(form_xml)
export(get_default_fid)
export(get_default_odkc_version)
export(get_default_orders)
export(get_default_pid)
export(get_default_pp)
export(get_default_pw)
Expand Down
9 changes: 1 addition & 8 deletions R/encryption_key_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,7 @@ encryption_key_list <- function(pid = get_default_pid(),
un = get_default_un(),
pw = get_default_pw(),
retries = get_retries(),
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
orders = get_default_orders(),
tz = get_default_tz()) {
yell_if_missing(url, un, pw)
httr::RETRY(
Expand Down
9 changes: 1 addition & 8 deletions R/entity_create.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,7 @@ entity_create <- function(pid = get_default_pid(),
pw = get_default_pw(),
retries = get_retries(),
odkc_version = get_default_odkc_version(),
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
orders = get_default_orders(),
tz = get_default_tz()) {
yell_if_missing(url, un, pw, pid = pid, did = did)

Expand Down
9 changes: 1 addition & 8 deletions R/entity_delete.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,7 @@ entity_delete <- function(pid = get_default_pid(),
pw = get_default_pw(),
retries = get_retries(),
odkc_version = get_default_odkc_version(),
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
orders = get_default_orders(),
tz = get_default_tz()) {
yell_if_missing(url, un, pw, pid = pid, did = did, eid = eid)

Expand Down
9 changes: 1 addition & 8 deletions R/entity_detail.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,7 @@ entity_detail <- function(pid = get_default_pid(),
pw = get_default_pw(),
retries = get_retries(),
odkc_version = get_default_odkc_version(),
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
orders = get_default_orders(),
tz = get_default_tz()) {
yell_if_missing(url, un, pw, pid = pid, did = did, eid = eid)

Expand Down
9 changes: 1 addition & 8 deletions R/entity_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,7 @@ entity_list <- function(pid = get_default_pid(),
pw = get_default_pw(),
retries = get_retries(),
odkc_version = get_default_odkc_version(),
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
orders = get_default_orders(),
tz = get_default_tz()) {
yell_if_missing(url, un, pw, pid = pid, did = did)

Expand Down
9 changes: 1 addition & 8 deletions R/entity_update.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,7 @@ entity_update <- function(pid = get_default_pid(),
pw = get_default_pw(),
retries = get_retries(),
odkc_version = get_default_odkc_version(),
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
orders = get_default_orders(),
tz = get_default_tz()) {
yell_if_missing(url, un, pw, pid = pid, did = did, eid = eid)

Expand Down
117 changes: 117 additions & 0 deletions R/entity_versions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#' List versions of one Entity.
#'
#' `r lifecycle::badge("maturing")`
#'
#'
#' This returns the Entity metadata and data for every version of this Entity
#' in ascending creation order.
#'
#' The ODK Central endpoint supports retrieving extended metadata which this
#' function always returns.
#'
#' There is an optional query flag `relevantToConflict` that returns the subset
#' of past versions of an Entity that are relevant to the Entity's current
#' conflict. This includes the latest version, the base version, the previous
#' server version, and any other versions since the last time the Entity was
#' in a conflict-free state. If the Entity is not in conflict, zero versions
#' are returned.
#'
#' @template tpl-structure-nested
#' @template tpl-names-cleaned-top-level
#' @template tpl-auth-missing
#' @template tpl-compat-2022-3
#' @template param-pid
#' @template param-did
#' @template param-eid
#' @param conflict (lgl) Whether to return all versions (`FALSE`) or
#' whether to returns the subset of past versions of an Entity that are
#' relevant to the Entity's current conflict (`TRUE`).
#' This includes the latest version, the base version, the previous
#' server version, and any other versions since the last time the Entity was
#' in a conflict-free state. If the Entity is not in conflict, zero versions
#' are returned.
#' Default: `FALSE` (return all versions)
#' @template param-url
#' @template param-auth
#' @template param-retries
#' @template param-odkcv
#' @template param-orders
#' @template param-tz
#' @return A tibble with one row per version. List columns contain unstructured
#' data.
#' See <https://docs.getodk.org/central-api-entity-management/#listing-versions>
#' for the full schema.
#' Top level list elements are renamed from ODK's `camelCase` to `snake_case`.
#' Nested list elements have the original `camelCase`.
# nolint start
#' @seealso \url{https://docs.getodk.org/central-api-entity-management/#listing-versions}
# nolint end
#' @family entity-management
#' @export
#' @examples
#' \dontrun{
#' # See vignette("setup") for setup and authentication options
#' # ruODK::ru_setup(svc = "....svc", un = "[email protected]", pw = "...")
#'
#' el <- entitylist_list()
#'
#' # Entity List name (dataset ID, did)
#' did <- el$name[1]
#'
#' # All Entities of Entity List
#' en <- entity_list(did = did)
#'
#' ed <- entity_detail(did = did, eid = en$uuid[1])
#'
#' # The current version of the first Entity
#' ev <- en$current_version_version[1]
#' }
entity_versions <- function(pid = get_default_pid(),
did = "",
eid = "",
conflict = FALSE,
url = get_default_url(),
un = get_default_un(),
pw = get_default_pw(),
retries = get_retries(),
odkc_version = get_default_odkc_version(),
orders = get_default_orders(),
tz = get_default_tz()) {
yell_if_missing(url,
un,
pw,
pid = pid,
did = did,
eid = eid
)

if (odkc_version |> semver_lt("2022.3")) {
ru_msg_warn("entity_detail is supported from v2022.3")
}

pth <- glue::glue(
"v1/projects/{pid}/datasets/{URLencode(did, reserved = TRUE)}/",
"entities/{eid}/versions"
)

qry <- list(relevantToConflict = ifelse(conflict == TRUE, "True", "False"))

httr::RETRY(
"GET",
httr::modify_url(url, path = pth),
httr::add_headers(
"Accept" = "application/json",
"X-Extended-Metadata" = "true"
),
httr::authenticate(un, pw),
query = qry,
times = retries
) |>
yell_if_error(url, un, pw) |>
httr::content(encoding = "utf-8") |>
purrr::list_transpose() |>
tibble::as_tibble(.name_repair = "universal") |>
janitor::clean_names()
}

# usethis::use_test("entity_update") # nolint
9 changes: 1 addition & 8 deletions R/entitylist_detail.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,7 @@ entitylist_detail <- function(pid = get_default_pid(),
pw = get_default_pw(),
retries = get_retries(),
odkc_version = get_default_odkc_version(),
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
orders = get_default_orders(),
tz = get_default_tz()) {
yell_if_missing(url, un, pw, pid = pid, did = did)

Expand Down
9 changes: 1 addition & 8 deletions R/entitylist_download.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,7 @@ entitylist_download <- function(pid = get_default_pid(),
overwrite = TRUE,
retries = get_retries(),
odkc_version = get_default_odkc_version(),
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
orders = get_default_orders(),
tz = get_default_tz(),
verbose = get_ru_verbose()) {
# Gatecheck params
Expand Down
9 changes: 1 addition & 8 deletions R/entitylist_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,7 @@ entitylist_list <- function(pid = get_default_pid(),
pw = get_default_pw(),
retries = get_retries(),
odkc_version = get_default_odkc_version(),
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
orders = get_default_orders(),
tz = get_default_tz()) {
yell_if_missing(url, un, pw, pid = pid)

Expand Down
9 changes: 1 addition & 8 deletions R/entitylist_update.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,7 @@ entitylist_update <- function(pid = get_default_pid(),
pw = get_default_pw(),
retries = get_retries(),
odkc_version = get_default_odkc_version(),
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
orders = get_default_orders(),
tz = get_default_tz()) {
yell_if_missing(url, un, pw, pid = pid, did = did)

Expand Down
9 changes: 1 addition & 8 deletions R/form_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,7 @@ form_list <- function(pid = get_default_pid(),
un = get_default_un(),
pw = get_default_pw(),
retries = get_retries(),
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
orders = get_default_orders(),
tz = get_default_tz()) {
yell_if_missing(url, un, pw, pid = pid)
httr::RETRY(
Expand Down
9 changes: 1 addition & 8 deletions R/handle_ru_datetimes.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@
#' }
handle_ru_datetimes <- function(data,
form_schema,
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
orders = get_default_orders(),
tz = get_default_tz(),
verbose = get_ru_verbose()) {
# Find all date/time columns in form_schema
Expand Down
9 changes: 1 addition & 8 deletions R/odata_submission_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,7 @@ odata_submission_get <- function(table = "Submissions",
filter = NULL,
parse = TRUE,
download = TRUE,
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
orders = get_default_orders(),
local_dir = "media",
pid = get_default_pid(),
fid = get_default_fid(),
Expand Down
9 changes: 1 addition & 8 deletions R/project_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,7 @@ project_list <- function(url = get_default_url(),
un = get_default_un(),
pw = get_default_pw(),
retries = get_retries(),
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
orders = get_default_orders(),
tz = get_default_tz()) {
yell_if_missing(url, un, pw)
httr::RETRY(
Expand Down
14 changes: 14 additions & 0 deletions R/ru_setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,20 @@ get_default_tz <- function() {
x
}

#' `r lifecycle::badge("stable")`
#' @export
#' @rdname ru_settings
get_default_orders <- function() {
c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
)
}

#' `r lifecycle::badge("stable")`
#' @export
#' @rdname ru_settings
Expand Down
9 changes: 1 addition & 8 deletions R/submission_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,7 @@ submission_list <- function(pid = get_default_pid(),
un = get_default_un(),
pw = get_default_pw(),
retries = get_retries(),
orders = c(
"YmdHMS",
"YmdHMSz",
"Ymd HMS",
"Ymd HMSz",
"Ymd",
"ymd"
),
orders = get_default_orders(),
tz = get_default_tz()) {
yell_if_missing(url, un, pw, pid = pid, fid = fid)
url <- httr::modify_url(
Expand Down
Loading

0 comments on commit c6f09b5

Please sign in to comment.