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

Attachments #196

Merged
merged 4 commits into from
Jul 5, 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
4 changes: 1 addition & 3 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ jobs:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
# use 4.1 to check with rtools40's older compiler
- {os: windows-latest, r: '4.1'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: arcgislayers
Type: Package
Title: An Interface to ArcGIS Data Services
Version: 0.2.0
Version: 0.2.1
Authors@R: c(
person("Josiah", "Parry", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-9910-865X")),
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# arcgislayers (development)
# arcgislayers 0.3.0

- New `query_layer_attachments()` and `download_attachments()` help you access and download attachments to a layer
- `arc_raster()` now downloads the exported image to a temp file instead of creating a connection to the url returned. This fixes an issue where rasters would stop working after the url had been removed.
Expand Down
22 changes: 12 additions & 10 deletions R/attachments.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
#'
#' @inheritParams arc_select
#' @param definition_expression default `1 = 1`. A SQL where clause that is applied to the layer. Only those records that conform to this expression will be returned. This parameter is required if neither `object_ids` or `global_ids` have been defined.
#' @param attachments_definition_expression default `NULL`. A SQL where calsue that is applied to the attachment metadata.
#' only attachments that conform to this expression will be returned.
#' @param object_ids mutually exclusive with `definition_expression` and `global_ids`. The object IDs of the features to query attachments of.
#' @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 overwrite default `FALSE`. A
#' @rdname attachments
#' @references [ArcGIS REST API Documentation](https://developers.arcgis.com/rest/services-reference/enterprise/query-attachments-feature-service-layer/)
#' @export
Expand Down Expand Up @@ -61,8 +64,6 @@ query_layer_attachments <- function(
cli::cli_abort("{.arg layer} does not support attachments.")
}

b_req <- arc_base_req(x[["url"]], token = token, path = "queryAttachments")

# check that only one of definition_expression, object_ids, and global_ids is provided
rlang::check_exclusive(definition_expression, object_ids, global_ids, .require = FALSE)

Expand All @@ -79,18 +80,15 @@ query_layer_attachments <- function(
keywords <- paste(keywords, collapse = ",")
}

# create the base request
b_req <- arc_base_req(x[["url"]], token = token, path = "queryAttachments")

# Fill the body of the request
req <- httr2::req_body_form(
b_req,
# TODO test these why aren't these working?!!
objectIds = paste(object_ids, collapse = ","),
# TODO create a test for this
globalIds = paste(global_ids, collapse = ","),
attachmentTypes = attachment_types,
# TODO document common examples:
# filter based on
# - date
# - common prefix
# - numeric value
definitionExpression = definition_expression,
attachmentsDefinitionExpression = attachments_definition_expression,
keywords = keywords,
Expand All @@ -99,10 +97,12 @@ query_layer_attachments <- function(
f = "json"
)

# send request
resp <- httr2::req_perform(req)
# parse response
res <- RcppSimdJson::fparse(httr2::resp_body_string(resp))
# throw an error if they are there
arcgisutils::detect_errors(res)
# TODO assert that attachmentGroups are present
# TODO consider importing {heck} for name cleaning later
unnest_attachment_groups(res$attachmentGroups)
}
Expand Down Expand Up @@ -157,6 +157,8 @@ download_attachments <- function(
# df, col ~ check_character, col ~ check_numeric
# )
check_data_frame(attachments)
check_bool(overwrite)
check_bool(.progress)

if (is.null(attachments[["name"]])) {
cli::cli_abort(
Expand Down
6 changes: 5 additions & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

0 errors | 0 warnings | 1 note

* This is a new release.
* This is a new release with small bug fixes and 2 minor new functions.

-----

Previous notes:

* ArcGIS is a brand name and not a software name which is why it is unquoted some places in the DESCRIPTION's. These being the `Title` field and in the `Description` where it says "ArcGIS location services."
* REST is not a software but an architecture so it is not quoted.
Expand Down
2 changes: 1 addition & 1 deletion dev/attachments-demo.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# install the development version
# install.packages("pak")
# pak::pak("r-arcgis/arcgislayers")
library(pillar)

# for authorizing to your portal
library(arcgisutils)
Expand Down Expand Up @@ -53,7 +54,6 @@ query_layer_attachments(
attachments_definition_expression = "att_name like '%20221005%'"
)


# to download the attachments:
# res <- download_attachments(
# att,
Expand Down
7 changes: 7 additions & 0 deletions man/attachments.Rd

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

Loading