Skip to content

Commit c5bad31

Browse files
authored
Merge pull request #64 from ScotGovAnalysis/assets
Temporary fix to type arg in assets() (#53)
2 parents 0ff1b19 + df8d49f commit c5bad31

File tree

5 files changed

+45
-10
lines changed

5 files changed

+45
-10
lines changed

NEWS.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616
`read/write_data_version()`(#54).
1717

1818
* Added support for [mobile authentication](https://secure.objectiveconnect.co.uk/publicapi/1/swagger-ui/index.html?configUrl=/publicapi/1/v3/api-docs/swagger-config#/MobileAuth)
19-
to view status (`mobile_auth_staus()`) and to login (`mobile_auth_login()`)
19+
to view status (`mobile_auth_staus()`) and to login (`mobile_auth_login()`)
2020
(#52).
2121

22+
* Temporary fix to `assets()` to account for bug in underlying API (#53).
23+
The `type` argument now only accepts an empty list (default to return all asset
24+
types) or a list of length 1.
25+
2226
# objr 0.1.1
2327

2428
* Set minimum versions for `dplyr` and `tidyr` dependencies (#32).

R/assets.R

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@
77
# nolint end
88
#'
99
#' @param workspace_uuid UUID of workspace
10-
#' @param type List of asset types to return. Defaults to all types;
11-
#' document, folder and link.
10+
#' @param type List of asset types to return. Default returns all types;
11+
#' "document", "folder" and "link".
12+
#'
13+
#' List must be empty (default, returns all asset types), or length 1 (e.g.
14+
#' `list("document")`). This is a temporary measure while a bug in the
15+
#' underlying API is outstanding (see
16+
#' [objr#53](https://github.com/ScotGovAnalysis/objr/issues/53)).
17+
#'
1218
#' @inheritParams objr
1319
#' @inheritParams workspaces
1420
#'
@@ -17,13 +23,28 @@
1723
#' @export
1824

1925
assets <- function(workspace_uuid,
20-
type = list("document", "folder", "link"),
26+
type = list(),
2127
page = NULL,
2228
size = NULL,
2329
use_proxy = FALSE) {
2430

2531
check_list(type)
2632

33+
if (length(type) > 1) {
34+
cli::cli_abort(c(
35+
"x" = "{.arg type} must be a list of length 0 or 1, not {length(type)}.",
36+
"i" = paste(
37+
"There is currently a bug in the underlying API preventing",
38+
"users from selecting more than one asset type. See",
39+
"{.href [objr#53](https://github.com/ScotGovAnalysis/objr/issues/53)}",
40+
"for more information."),
41+
"i" = paste("To return all assets, use `type = list()` (default)."),
42+
"i" = paste("To return one asset type only, e.g. documents, use",
43+
"`type = list(\"document\")`. See `?assets` for all",
44+
"options.")
45+
))
46+
}
47+
2748
type <- paste(toupper(type), collapse = "|")
2849

2950
response <- objr(

man/assets.Rd

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# All types
22

3-
structure(list(method = "GET", url = "https://api/assets?workspaceUuid=test_workspace&type=DOCUMENT%7CFOLDER%7CLINK",
3+
structure(list(method = "GET", url = "https://api/assets?workspaceUuid=test_workspace&type=",
44
status_code = 200L, headers = structure(list(Date = "Mon, 08 Apr 2024 16:12:59 GMT",
55
`Content-Type` = "application/json", `Transfer-Encoding` = "chunked",
66
Connection = "keep-alive", `X-CONNECT-MDC` = "apiGMsONBfA",

tests/testthat/test-assets.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
# assets ----
22

3+
test_that("Error if `type` length > 1", {
4+
expect_error(assets(workspace_uuid = "test_workspace",
5+
type = list("document", "link")))
6+
})
7+
38
without_internet({
49

510
test_that("Valid request created", {
611

712
expect_GET(
8-
assets(workspace_uuid = "test_workspace"),
13+
assets(workspace_uuid = "test_workspace", type = list()),
914
paste0("https://secure.objectiveconnect.co.uk/publicapi/1/assets?",
10-
"workspaceUuid=test_workspace&type=DOCUMENT%7CFOLDER%7CLINK")
15+
"workspaceUuid=test_workspace&type=")
1116
)
1217

1318
expect_GET(

0 commit comments

Comments
 (0)