Skip to content

Commit 754bd2d

Browse files
authored
Merge pull request #210 from R-ArcGIS/attach_meta
Make attachment metadata optional
2 parents 7a78682 + 89b7f61 commit 754bd2d

File tree

4 files changed

+74
-32
lines changed

4 files changed

+74
-32
lines changed

Diff for: R/attachments.R

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#' @param global_ids mutally exclusive with `definition_expression` and `object_ids`. The global IDs of the features to query attachments of.
1313
#' @param keywords default `NULL`. A character vector of the keywords to filter on.
1414
#' @param attachment_types default `NULL`. A character vector of attachment types to filter on.
15+
#' @param return_metadata default `TRUE`. Returns metadata stored in the `exifInfo` field.
1516
#' @param overwrite default `FALSE`. A
1617
#' @rdname attachments
1718
#' @references [ArcGIS REST API Documentation](https://developers.arcgis.com/rest/services-reference/enterprise/query-attachments-feature-service-layer/)
@@ -49,6 +50,7 @@ query_layer_attachments <- function(
4950
global_ids = NULL,
5051
attachment_types = NULL,
5152
keywords = NULL,
53+
return_metadata = TRUE,
5254
...,
5355
token = arc_token()
5456
# Ignored arguments for now:
@@ -93,7 +95,7 @@ query_layer_attachments <- function(
9395
attachmentsDefinitionExpression = attachments_definition_expression,
9496
keywords = keywords,
9597
returnUrl = TRUE,
96-
returnMetadata = TRUE,
98+
returnMetadata = return_metadata,
9799
f = "json"
98100
)
99101

@@ -125,7 +127,6 @@ unnest_attachment_groups <- function(x) {
125127
}
126128

127129

128-
129130
# Attachment types
130131
possible_attachment_types <- c(
131132
"7z", "aif", "avi", "bmp", "csv", "doc", "docx", "dot", "ecw", "emf", "eps",

Diff for: man/arc_open.Rd

+28-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: man/attachments.Rd

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tests/testthat/test-attachments.R

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
furl <- "https://services1.arcgis.com/hLJbHVT9ZrDIzK0I/arcgis/rest/services/v8_Wide_Area_Search_Form_Feature_Layer___a2fe9c/FeatureServer/0"
2+
layer <- arc_open(furl)
3+
4+
test_that("query_layer_attachments() default args", {
5+
# connect to the layer
6+
expect_no_error()
7+
})
8+
9+
10+
test_that("query_layer_attachments() no metadata", {
11+
att <- query_layer_attachments(layer, return_metadata = FALSE)
12+
expect_true(all(is.na(att$exifInfo)))
13+
})
14+
15+
16+
test_that("query_layer_attachments() filter on layer field", {
17+
att <- query_layer_attachments(layer, "followup_status = 'needs_followup'")
18+
expect_equal(nrow(att), 24L)
19+
})
20+
21+
test_that("query_layer_attachments() filter on attachment field", {
22+
att <-
23+
query_layer_attachments(
24+
layer,
25+
attachments_definition_expression = "att_name like 'image0%'"
26+
)
27+
expect_true(all(grepl("image0*", att$name)))
28+
})
29+
30+
31+
test_that("download_attachments()", {
32+
tmp <- tempdir()
33+
att <-
34+
query_layer_attachments(
35+
layer,
36+
attachments_definition_expression = "att_name like 'image0%'"
37+
)
38+
res <- download_attachments(att, tmp)
39+
expect_true(all(basename(unlist(res)) %in% list.files(tmp)))
40+
})

0 commit comments

Comments
 (0)