## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", eval = FALSE)

## ----checked-catalog, eval=TRUE-----------------------------------------------
library(tampaBayOpenData)

tampaBayOpenData::tbod_list_portals()[, c("id", "publisher", "jurisdiction")]
tampaBayOpenData::tbod_list_datasets(source = "checked")[,
  c("id", "title", "jurisdiction", "validation_status")]
tampaBayOpenData::tbod_search_datasets(
  "park", source = "checked", spatial = TRUE,
  jurisdiction = c("stpete", "clearwater")
)
tampaBayOpenData::tbod_dataset_info("construction-permits")[
  c("title", "scope_note", "verified")]

## ----live-search--------------------------------------------------------------
# found <- tbod_search_datasets("housing", source = "live", portals = "city")
# found[, c("id", "title", "publisher", "validation_status", "modified")]
# 
# # A one-row result carries the source needed for inspection or retrieval.
# if (nrow(found)) {
#   selected <- found[1, ]
#   selected[, c("item_id", "service_url", "layer_id", "portal")]
#   tbod_dataset_info(selected)
# }

## ----custom-discovery---------------------------------------------------------
# # Replace this example address with your portal's public sharing REST root.
# portal <- "https://example.maps.arcgis.com/sharing/rest"
# other <- tbod_discover(portal, query = "parks", max_items = 10)
# if (nrow(other)) {
#   data <- tbod_get_dataset(other[1, ], limit = 100)
#   # A stable ArcGIS ID can also be resolved later through its own portal.
#   same_layer <- tbod_get_dataset(other$id[[1]], portal = portal, limit = 100)
# }

## ----county-search------------------------------------------------------------
# county_transport <- tbod_search_datasets(
#   "road", source = "live", jurisdiction = "pinellas", spatial = TRUE,
#   topic = "transportation", modified_after = as.Date("2025-01-01"),
#   max_items = 10
# )
# county_transport[, c("id", "title", "publisher", "modified", "modified_source")]

## ----scan-metadata------------------------------------------------------------
# results <- tbod_list_datasets(source = "live", portals = "stpete", max_items = 10)
# attr(results, "discovery_complete")
# attr(results, "discovery_truncated_portals")
# attr(results, "discovery_scanned_items")
# attr(results, "discovery_issues")
# attr(results, "discovery_failed_portals")

