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

related_items() #97

Open
JosiahParry opened this issue Nov 15, 2023 · 0 comments
Open

related_items() #97

JosiahParry opened this issue Nov 15, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@JosiahParry
Copy link
Collaborator

Is your feature request related to a problem? Please describe.

This adds a feature to identify related items for a given item ID

Describe the solution you'd like

This is a draft! It does not handle pagination which should be handled!!!

#' Find Related Items
#'
#' @param x an object created with [`arc_open()`]
#' @param direction default `"reverse"`. One of `"reverse"` or `"forward"` defining the direction of the relationship.
#' @inheritParams add_item
#' @references [`/relatedItems` API Doc](https://developers.arcgis.com/rest/users-groups-and-items/related-items.htm)
related_items <- function(
    x,
    direction = c("reverse", "forward"),
    sort_order = c("asc", "desc"),
    host = arc_host(),
    token = Sys.getenv("ARCGIS_TOKEN")
) {

  # validate args
  .dir <- rlang::arg_match(direction)
  sort_order <- rlang::arg_match(sort_order)

  item_id <- x[["serviceItemId"]]

  # https://[root]/content/items/[itemID]/relatedItems
  req <- httr2::req_url_path_append(
    httr2::request(host),
    "sharing/rest/content/items",
    item_id,
    "relatedItems"
  )

  req_body <- httr2::req_body_form(
    req,
    direction = .dir,
    sordOrder = sort_order,
    token = token,
    f = "json"
  )

  # perform request
  resp <- httr2::req_perform(req_body)

  # parse body
  RcppSimdJson::fparse(
    httr2::resp_body_string(resp)
  )
}

Additional context

Need to migrate to httr2 v.1.0 first for pagination helpers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant