From 0b1884fa2ae370cad8c9f9c79dc5e045fa7e6df8 Mon Sep 17 00:00:00 2001 From: Josiah Parry Date: Sat, 16 Mar 2024 07:00:26 -0700 Subject: [PATCH 1/2] add arc_self_meta --- NAMESPACE | 1 + NEWS.md | 1 + R/self.R | 43 +++++++++++++++++++++++++++++++++++++++++++ man/arc_self_meta.Rd | 31 +++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 R/self.R create mode 100644 man/arc_self_meta.Rd diff --git a/NAMESPACE b/NAMESPACE index afdc35e..97bbad3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/NEWS.md b/NEWS.md index 1f34bfc..908b3b3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/R/self.R b/R/self.R new file mode 100644 index 0000000..96179ee --- /dev/null +++ b/R/self.R @@ -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. +#' +#' @return +#' +#' A named list. +#' +#' @inheritParams arc_base_req +#' @export +#' @examples +#' self <- arc_self_meta() +#' names(self) +arc_self_meta <- function(token = arc_token(), 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 = call) + + res <- RcppSimdJson::fparse( + httr2::resp_body_string(resp) + ) + + res + +} diff --git a/man/arc_self_meta.Rd b/man/arc_self_meta.Rd new file mode 100644 index 0000000..c987fa7 --- /dev/null +++ b/man/arc_self_meta.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/self.R +\name{arc_self_meta} +\alias{arc_self_meta} +\title{Access the Self Resource} +\usage{ +arc_self_meta(token = arc_token(), call = rlang::current_call()) +} +\arguments{ +\item{token}{an object of class \code{httr2_token} as generated by \code{\link[=auth_code]{auth_code()}} +or related function} +} +\value{ +A named list. +} +\description{ +The function returns the \href{https://developers.arcgis.com/rest/users-groups-and-items/portal-self.htm}{\verb{/self}} resource from the ArcGIS REST API. The \verb{/self} endpoint +returns the view of the portal as seen by the current user, whether anonymous +or signed in. +} +\details{ +See the \href{https://developers.arcgis.com/rest/users-groups-and-items/portal-self.htm}{endpoint documentation} 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. +} +\examples{ +self <- arc_self_meta() +names(self) +} From ed86f570c7d6d19f0b383414d97b44c2bf924780 Mon Sep 17 00:00:00 2001 From: Josiah Parry Date: Sat, 16 Mar 2024 07:08:43 -0700 Subject: [PATCH 2/2] inherit the call parameter --- R/self.R | 6 +++--- man/arc_self_meta.Rd | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/R/self.R b/R/self.R index 96179ee..7921876 100644 --- a/R/self.R +++ b/R/self.R @@ -12,7 +12,7 @@ #' #' 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. #' -#' @return +#' @returns #' #' A named list. #' @@ -21,7 +21,7 @@ #' @examples #' self <- arc_self_meta() #' names(self) -arc_self_meta <- function(token = arc_token(), call = rlang::current_call()) { +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 @@ -32,7 +32,7 @@ arc_self_meta <- function(token = arc_token(), call = rlang::current_call()) { b_req <- arc_base_req(burl, token) req <- httr2::req_body_form(b_req, f = "json") - resp <- httr2::req_perform(req, error_call = call) + resp <- httr2::req_perform(req, error_call = error_call) res <- RcppSimdJson::fparse( httr2::resp_body_string(resp) diff --git a/man/arc_self_meta.Rd b/man/arc_self_meta.Rd index c987fa7..12c88eb 100644 --- a/man/arc_self_meta.Rd +++ b/man/arc_self_meta.Rd @@ -4,11 +4,13 @@ \alias{arc_self_meta} \title{Access the Self Resource} \usage{ -arc_self_meta(token = arc_token(), call = rlang::current_call()) +arc_self_meta(token = arc_token(), error_call = rlang::current_call()) } \arguments{ \item{token}{an object of class \code{httr2_token} as generated by \code{\link[=auth_code]{auth_code()}} or related function} + +\item{error_call}{the caller environment to be used when propagating errors.} } \value{ A named list.