arcgislayers icon indicating copy to clipboard operation
arcgislayers copied to clipboard

ArcGIS Hub Feed

Open JosiahParry opened this issue 8 months ago • 1 comments

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

Inspired by esri2sf::esrihub()

https://github.com/elipousson/esri2sf/blob/master/R/esrihub.R

Describe the solution you'd like Function to return ArcGIS Hub feeds

What's needed?

This function will return feeds of all types except OGC. We need an example to test against. We do not take the liberty to process XML. Leave that to the user who decides to use an RSS feed (only masochists dabble in xml).

  • Write function reference
  • Add tests for each feed-type
# https://doc.arcgis.com/en/hub/content/federate-data-with-external-catalogs.htm
# url <- "https://data.baltimorecity.gov"

arc_hub_feed <- function(url, feed_type = c("dcat-us", "dcat-ap", "rss", "ogc")) {
  feed_type <- match.arg(feed_type)
  
  switch(
    feed_type,
    "dcat-us" = hub_dcat_us(url),
    "dcat-ap" = hub_dcat_ap(url),
    "rss" = hub_rss(url),
    # i can't find an example that uses OGC so cannot test
    "ogc" = todo()
  )
  
}
  
hub_dcat_us <- function(url) {
  req <- httr2::req_url_path_append(
    httr2::request(url),
    "api/feed/dcat-us/1.1.json"
  )
  resp <- httr2::req_perform(req)
  resp_str <- httr2::resp_body_string(resp)
  RcppSimdJson::fparse(resp_str)
}

hub_dcat_ap <- function(url) {
  req <- httr2::req_url_path_append(
    httr2::request(url),
    "api/feed/dcat-ap/2.0.1.json"
  )
  resp <- httr2::req_perform(req)
  resp_str <- httr2::resp_body_string(resp)
  RcppSimdJson::fparse(resp_str)
}

hub_rss <- function(url) {
  req <- httr2::req_url_path_append(
    httr2::request(url),
    "api/feed/rss/2.0"
  )
  resp <- httr2::req_perform(req)
  httr2::resp_body_xml(resp)
}

todo <- function() {
  cli::cli_abort(
    "TODO! not implemented",
    call = rlang::caller_env()
  )
}

CC @elipousson

JosiahParry avatar Dec 08 '23 20:12 JosiahParry