Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make attachment metadata optional #210

Merged
merged 2 commits into from
Jul 19, 2024
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
5 changes: 3 additions & 2 deletions R/attachments.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#' @param global_ids mutally exclusive with `definition_expression` and `object_ids`. The global IDs of the features to query attachments of.
#' @param keywords default `NULL`. A character vector of the keywords to filter on.
#' @param attachment_types default `NULL`. A character vector of attachment types to filter on.
#' @param return_metadata default `TRUE`. Returns metadata stored in the `exifInfo` field.
#' @param overwrite default `FALSE`. A
#' @rdname attachments
#' @references [ArcGIS REST API Documentation](https://developers.arcgis.com/rest/services-reference/enterprise/query-attachments-feature-service-layer/)
Expand Down Expand Up @@ -49,6 +50,7 @@ query_layer_attachments <- function(
global_ids = NULL,
attachment_types = NULL,
keywords = NULL,
return_metadata = TRUE,
...,
token = arc_token()
# Ignored arguments for now:
Expand Down Expand Up @@ -93,7 +95,7 @@ query_layer_attachments <- function(
attachmentsDefinitionExpression = attachments_definition_expression,
keywords = keywords,
returnUrl = TRUE,
returnMetadata = TRUE,
returnMetadata = return_metadata,
f = "json"
)

Expand Down Expand Up @@ -125,7 +127,6 @@ unnest_attachment_groups <- function(x) {
}



# Attachment types
possible_attachment_types <- c(
"7z", "aif", "avi", "bmp", "csv", "doc", "docx", "dot", "ecw", "emf", "eps",
Expand Down
58 changes: 28 additions & 30 deletions man/arc_open.Rd

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

3 changes: 3 additions & 0 deletions man/attachments.Rd

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

40 changes: 40 additions & 0 deletions tests/testthat/test-attachments.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
furl <- "https://services1.arcgis.com/hLJbHVT9ZrDIzK0I/arcgis/rest/services/v8_Wide_Area_Search_Form_Feature_Layer___a2fe9c/FeatureServer/0"
layer <- arc_open(furl)

test_that("query_layer_attachments() default args", {
# connect to the layer
expect_no_error()
})


test_that("query_layer_attachments() no metadata", {
att <- query_layer_attachments(layer, return_metadata = FALSE)
expect_true(all(is.na(att$exifInfo)))
})


test_that("query_layer_attachments() filter on layer field", {
att <- query_layer_attachments(layer, "followup_status = 'needs_followup'")
expect_equal(nrow(att), 24L)
})

test_that("query_layer_attachments() filter on attachment field", {
att <-
query_layer_attachments(
layer,
attachments_definition_expression = "att_name like 'image0%'"
)
expect_true(all(grepl("image0*", att$name)))
})


test_that("download_attachments()", {
tmp <- tempdir()
att <-
query_layer_attachments(
layer,
attachments_definition_expression = "att_name like 'image0%'"
)
res <- download_attachments(att, tmp)
expect_true(all(basename(unlist(res)) %in% list.files(tmp)))
})
Loading