Skip to content

Commit

Permalink
Merge pull request #36 from R-ArcGIS/self-meta
Browse files Browse the repository at this point in the history
Access `/self` endpoint
  • Loading branch information
JosiahParry authored Mar 16, 2024
2 parents 1bfd01e + ed86f57 commit b8be833
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export("%||%")
export(arc_agent)
export(arc_base_req)
export(arc_host)
export(arc_self_meta)
export(arc_token)
export(as_esri_features)
export(as_esri_featureset)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# arcgisutils (development version)

- `arc_self_meta()` is a new function to provide access to the [`/self`](https://developers.arcgis.com/rest/users-groups-and-items/portal-self.htm) endpoint. Closes [#32](https://github.com/R-ArcGIS/arcgisutils/issues/32)
- Null geometries are parsed into empty Geometry Collections using `sf::st_geometrycollection()` Fixed [#168](https://github.com/R-ArcGIS/arcgislayers/issues/168)
- When Esri JSON contains 0 features, `parse_esri_json()` will create an empty `data.frame` with the fields that are returned with the appropriate R type.

Expand Down
43 changes: 43 additions & 0 deletions R/self.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#' Access the Self Resource
#'
#' The function returns the [`/self`](https://developers.arcgis.com/rest/users-groups-and-items/portal-self.htm) resource from the ArcGIS REST API. The `/self` endpoint
#' returns the view of the portal as seen by the current user, whether anonymous
#' or signed in.
#'
#' @details
#'
#' See the [endpoint documentation](https://developers.arcgis.com/rest/users-groups-and-items/portal-self.htm) for more details.
#'
#' The Portal Self response can vary based on whether it's called by a user, an app, or both.
#'
#' The response includes user and appinfo properties, and the variations in responses are primarily related to these two properties. As the names indicate, the user property includes information about the user making the call, and the appinfo property includes information pertaining to the app that made the call.
#'
#' @returns
#'
#' A named list.
#'
#' @inheritParams arc_base_req
#' @export
#' @examples
#' self <- arc_self_meta()
#' names(self)
arc_self_meta <- function(token = arc_token(), error_call = rlang::current_call()) {

burl <- file.path(
# use the host from a token if set, otherwise default
token[["arcgis_host"]] %||% arc_host(),
"sharing", "rest", "portals", "self",
fsep = "/"
)

b_req <- arc_base_req(burl, token)
req <- httr2::req_body_form(b_req, f = "json")
resp <- httr2::req_perform(req, error_call = error_call)

res <- RcppSimdJson::fparse(
httr2::resp_body_string(resp)
)

res

}
33 changes: 33 additions & 0 deletions man/arc_self_meta.Rd

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

0 comments on commit b8be833

Please sign in to comment.