From 975653c784184d7ea4d7454894891f6a258fc896 Mon Sep 17 00:00:00 2001 From: Josiah Parry Date: Fri, 9 Feb 2024 14:53:54 -0500 Subject: [PATCH 1/3] remove user argument. Use arcgisutils check_token_has_user() --- NEWS.md | 1 + R/add_item.R | 17 ++++++++++++----- R/create-service.R | 9 +++++++-- man/create_feature_server.Rd | 7 +++---- man/publish.Rd | 9 +++------ 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7a65001..b5752bb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ - **Breaking**: - `token` arguments are required to be a valid `httr2_token` object (strings are not supported). - all `host` arguments are removed. Instead, the host is fetched from the `token`. + - all `user` arguments are removed. Instead, the username is fetched from the `token`. If it is not found, an error is thrown. - Add support for `GroupLayer`s - Add `arc_read()` with support for `name_repair` argument using `{vctrs}` (#108) - Add `get_layer_estimates()` to retrieve estimate info such as the number of features and the extent of the layer diff --git a/R/add_item.R b/R/add_item.R index 5c39715..55e5817 100644 --- a/R/add_item.R +++ b/R/add_item.R @@ -61,7 +61,6 @@ add_item <- function( x, title, - user = Sys.getenv("ARCGIS_USER"), description = "", tags = character(0), snippet = "", @@ -75,6 +74,12 @@ add_item <- function( # validate the token obj_check_token(token) + # check that there is a user associated with the token + check_token_has_user(token) + + # extract username + user <- token[["username"]] + # fetch the host from the token host <- token[["arcgis_host"]] @@ -175,7 +180,6 @@ add_item <- function( #' @rdname publish publish_item <- function( item_id, - user = Sys.getenv("ARCGIS_USER"), publish_params = .publish_params(), file_type = "featureCollection", token = arc_token() @@ -184,6 +188,12 @@ publish_item <- function( # validate the token obj_check_token(token) + # check that there is a user associated with the token + check_token_has_user(token) + + # extract username + user <- token[["username"]] + # fetch the host host <- token[["arcgis_host"]] @@ -221,7 +231,6 @@ publish_layer <- function( x, title, ..., - user = Sys.getenv("ARCGIS_USER"), publish_params = .publish_params(title, target_crs = sf::st_crs(x)), token = arc_token() ) { @@ -232,7 +241,6 @@ publish_layer <- function( add_item( x, title, - user = user, token = token, !!!adtl_args ) @@ -244,7 +252,6 @@ publish_layer <- function( published_item <- publish_item( item_id, - user = user, publish_params = publish_params, token = token ) diff --git a/R/create-service.R b/R/create-service.R index 76e3473..2b69553 100644 --- a/R/create-service.R +++ b/R/create-service.R @@ -30,13 +30,12 @@ #' #' @export #' @examples -#' if (interactive()) { +#' \donttest{ #' set_arc_token(auth_code()) #' create_feature_server("My empty feature server") #' } create_feature_server <- function( service_name, - user = Sys.getenv("ARCGIS_USER"), description = "", crs = 3857, capabilities = c("create", "delete", "query", "update", "editing"), @@ -57,6 +56,12 @@ create_feature_server <- function( # validate the token obj_check_token(token) + # check that there is a user associated with the token + check_token_has_user(token) + + # extract username + user <- token[["username"]] + # fetch the host host <- token[["arcgis_host"]] diff --git a/man/create_feature_server.Rd b/man/create_feature_server.Rd index 17f1ba8..efbf977 100644 --- a/man/create_feature_server.Rd +++ b/man/create_feature_server.Rd @@ -7,7 +7,6 @@ \usage{ create_feature_server( service_name, - user = Sys.getenv("ARCGIS_USER"), description = "", crs = 3857, capabilities = c("create", "delete", "query", "update", "editing"), @@ -26,8 +25,6 @@ xss_defaults() \arguments{ \item{service_name}{Feature Service name.} -\item{user}{default \code{Sys.getenv("ARCGIS_USER")}. Your account's username.} - \item{description}{default blank. The description of the feature server.} \item{crs}{default \code{3857}. A coordinate reference system to set for the feature server. @@ -53,6 +50,8 @@ retrieved from a layer in one request.} See details for more.} \item{token}{an \code{httr2_token} as created by \code{auth_code()} or similar} + +\item{user}{default \code{Sys.getenv("ARCGIS_USER")}. Your account's username.} } \value{ If a \code{FeatureServer} is created successfully, a \code{FeatureServer} object is returned @@ -65,7 +64,7 @@ Creates an empty FeatureServer with no additional layers. \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} } \examples{ -if (interactive()) { +\donttest{ set_arc_token(auth_code()) create_feature_server("My empty feature server") } diff --git a/man/publish.Rd b/man/publish.Rd index 79f1158..2523c8d 100644 --- a/man/publish.Rd +++ b/man/publish.Rd @@ -10,7 +10,6 @@ add_item( x, title, - user = Sys.getenv("ARCGIS_USER"), description = "", tags = character(0), snippet = "", @@ -22,7 +21,6 @@ add_item( publish_item( item_id, - user = Sys.getenv("ARCGIS_USER"), publish_params = .publish_params(), file_type = "featureCollection", token = arc_token() @@ -32,7 +30,6 @@ publish_layer( x, title, ..., - user = Sys.getenv("ARCGIS_USER"), publish_params = .publish_params(title, target_crs = sf::st_crs(x)), token = arc_token() ) @@ -52,9 +49,6 @@ any other subclass of \code{data.frame}.} \item{title}{A user-friendly string title for the layer that can be used in a table of contents.} -\item{user}{default environment variable \code{Sys.getenv("ARCGIS_USER")}. -The username to publish the item under.} - \item{description}{a length 1 character vector containing the description of the item that is being added. Note that the value cannot be larger than 64kb.} @@ -89,6 +83,9 @@ add to the published Feature Service.} \item{max_record_count}{the maximum number of records that can be returned from the created Feature Service.} + +\item{user}{default environment variable \code{Sys.getenv("ARCGIS_USER")}. +The username to publish the item under.} } \value{ A named list containing the url of the newly published service. From ea2dd0331b4a0d250205930ca02e72da4993e64d Mon Sep 17 00:00:00 2001 From: Josiah Parry Date: Fri, 9 Feb 2024 15:48:20 -0500 Subject: [PATCH 2/3] remove user param from docs --- R/add_item.R | 2 -- R/create-service.R | 1 - man/create_feature_server.Rd | 2 -- man/publish.Rd | 3 --- 4 files changed, 8 deletions(-) diff --git a/R/add_item.R b/R/add_item.R index 55e5817..269edb5 100644 --- a/R/add_item.R +++ b/R/add_item.R @@ -32,8 +32,6 @@ #' `add_item()`. #' #' @inheritParams arcgisutils::as_layer -#' @param user default environment variable `Sys.getenv("ARCGIS_USER")`. -#' The username to publish the item under. #' @param description a length 1 character vector containing the description of #' the item that is being added. Note that the value cannot be larger than 64kb. #' @param tags a character vector of tags to add to the item. diff --git a/R/create-service.R b/R/create-service.R index 2b69553..410cd5e 100644 --- a/R/create-service.R +++ b/R/create-service.R @@ -3,7 +3,6 @@ #' Creates an empty FeatureServer with no additional layers. #' #' @param service_name Feature Service name. -#' @param user default `Sys.getenv("ARCGIS_USER")`. Your account's username. #' @param description default blank. The description of the feature server. #' @param crs default `3857`. A coordinate reference system to set for the feature server. #' Must be compatible with `sf::st_crs()`. diff --git a/man/create_feature_server.Rd b/man/create_feature_server.Rd index efbf977..d21a7a3 100644 --- a/man/create_feature_server.Rd +++ b/man/create_feature_server.Rd @@ -50,8 +50,6 @@ retrieved from a layer in one request.} See details for more.} \item{token}{an \code{httr2_token} as created by \code{auth_code()} or similar} - -\item{user}{default \code{Sys.getenv("ARCGIS_USER")}. Your account's username.} } \value{ If a \code{FeatureServer} is created successfully, a \code{FeatureServer} object is returned diff --git a/man/publish.Rd b/man/publish.Rd index 2523c8d..c5fe79e 100644 --- a/man/publish.Rd +++ b/man/publish.Rd @@ -83,9 +83,6 @@ add to the published Feature Service.} \item{max_record_count}{the maximum number of records that can be returned from the created Feature Service.} - -\item{user}{default environment variable \code{Sys.getenv("ARCGIS_USER")}. -The username to publish the item under.} } \value{ A named list containing the url of the newly published service. From 0b60f785989a9b01c779066f7936ad022b2c0b65 Mon Sep 17 00:00:00 2001 From: Josiah Parry Date: Fri, 9 Feb 2024 16:33:09 -0500 Subject: [PATCH 3/3] include if interactive() --- R/create-service.R | 2 ++ man/create_feature_server.Rd | 2 ++ 2 files changed, 4 insertions(+) diff --git a/R/create-service.R b/R/create-service.R index 410cd5e..6a3d827 100644 --- a/R/create-service.R +++ b/R/create-service.R @@ -30,9 +30,11 @@ #' @export #' @examples #' \donttest{ +#' if (interactive()) { #' set_arc_token(auth_code()) #' create_feature_server("My empty feature server") #' } +#' } create_feature_server <- function( service_name, description = "", diff --git a/man/create_feature_server.Rd b/man/create_feature_server.Rd index d21a7a3..4fa5569 100644 --- a/man/create_feature_server.Rd +++ b/man/create_feature_server.Rd @@ -63,7 +63,9 @@ Creates an empty FeatureServer with no additional layers. } \examples{ \donttest{ +if (interactive()) { set_arc_token(auth_code()) create_feature_server("My empty feature server") } } +}