Skip to content

Commit b61a676

Browse files
authored
Merge pull request #126 from kbvernon/arc_token
2 parents 203bbbc + 643cf35 commit b61a676

22 files changed

+45
-60
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ License: Apache License (>= 2)
2323
Encoding: UTF-8
2424
LazyData: true
2525
Imports:
26-
arcgisutils (>= 0.1.0),
26+
arcgisutils (>= 0.1.1.9000),
2727
cli,
2828
httr2 (>= 1.0.0),
2929
jsonify,
@@ -34,7 +34,7 @@ Imports:
3434
terra,
3535
utils
3636
Roxygen: list(markdown = TRUE)
37-
RoxygenNote: 7.2.3
37+
RoxygenNote: 7.3.0
3838
Suggests:
3939
dbplyr,
4040
dplyr,

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
- adds cli as an explicit import (has been implicitly imported by httr2)
1515
- repository made public
1616
- add lifecycle badges to all exported functions <https://github.com/R-ArcGIS/arcgislayers/pull/101>
17+
- Use `arcgisutils::arc_token()` to get "ARCGIS_TOKEN" environment variable. This ensures that empty strings do not cause HTTP 498 "invalid token" error.

R/add_item.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ add_item <- function(
6969
async = FALSE,
7070
type = "Feature Service",
7171
host = arc_host(),
72-
token = Sys.getenv("ARCGIS_TOKEN")
72+
token = arc_token()
7373
) {
7474

7575
# if async = TRUE stop
@@ -171,7 +171,7 @@ publish_item <- function(
171171
publish_params = .publish_params(),
172172
file_type = "featureCollection",
173173
host = arc_host(),
174-
token = Sys.getenv("ARCGIS_TOKEN")
174+
token = arc_token()
175175
) {
176176

177177
# create request URL
@@ -208,7 +208,7 @@ publish_layer <- function(
208208
user = Sys.getenv("ARCGIS_USER"),
209209
publish_params = .publish_params(title, target_crs = sf::st_crs(x)),
210210
host = arc_host(),
211-
token = Sys.getenv("ARCGIS_TOKEN")
211+
token = arc_token()
212212
) {
213213

214214
adtl_args <- rlang::list2(...)

R/arc-add-update-delete.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ add_features <- function(
5454
chunk_size = 2000,
5555
match_on = c("name", "alias"),
5656
rollback_on_failure = TRUE,
57-
token = Sys.getenv("ARCGIS_TOKEN")
57+
token = arc_token()
5858
) {
5959

6060
# initial check for type of `x`
@@ -180,7 +180,7 @@ update_features <- function(
180180
x,
181181
.data,
182182
match_on = c("name", "alias"),
183-
token = Sys.getenv("ARCGIS_TOKEN"),
183+
token = arc_token(),
184184
rollback_on_failure = TRUE,
185185
...
186186
) {
@@ -293,7 +293,7 @@ delete_features <- function(
293293
filter_geom = NULL,
294294
predicate = "intersects",
295295
rollback_on_failure = TRUE,
296-
token = Sys.getenv("ARCGIS_TOKEN"),
296+
token = arc_token(),
297297
...
298298
) {
299299

R/arc-open.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#' arc_open(map_url)
5858
#'
5959
#'}
60-
arc_open <- function(url, token = Sys.getenv("ARCGIS_TOKEN")) {
60+
arc_open <- function(url, token = arc_token()) {
6161

6262
stopifnot("`url` must be of length 1" = length(url) == 1)
6363

R/arc-raster.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ arc_raster <- function(
5454
width = NULL,
5555
height = NULL,
5656
format = "tiff",
57-
token = Sys.getenv("ARCGIS_TOKEN")
57+
token = arc_token()
5858
) {
5959

6060

R/arc-read.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ arc_read <- function(
6262
crs = NULL,
6363
...,
6464
fields = NULL,
65-
token = Sys.getenv("ARCGIS_TOKEN")
65+
token = arc_token()
6666
) {
6767
service <- arc_open(url = url, token = token)
6868

R/arc-select.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ arc_select <- function(
5757
filter_geom = NULL,
5858
predicate = "intersects",
5959
n_max = Inf,
60-
token = Sys.getenv("ARCGIS_TOKEN"),
60+
token = arc_token(),
6161
...
6262
) {
6363
# Developer note:
@@ -132,7 +132,7 @@ arc_select <- function(
132132
#' @noRd
133133
collect_layer <- function(x,
134134
n_max = Inf,
135-
token = Sys.getenv("ARCGIS_TOKEN"),
135+
token = arc_token(),
136136
...,
137137
error_call = rlang::caller_env()) {
138138
check_inherits_any(

R/create-service.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ create_feature_server <- function(
4848
has_static_data = FALSE,
4949
xss_prevention = xss_defaults(),
5050
host = arc_host(),
51-
token = Sys.getenv("ARCGIS_TOKEN")
51+
token = arc_token()
5252
) {
5353

5454
match.arg(capabilities, several.ok = TRUE)

R/get-estimates.R

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#' @returns
1616
#' A named list containing all estimate info. If `extent` is present,
1717
#' it is available as an object of class `bbox`.
18-
get_layer_estimates <- function(x, token = Sys.getenv("ARCGIS_TOKEN")) {
18+
get_layer_estimates <- function(x, token = arc_token()) {
1919

2020
# check if its a supported layer
2121
obj_check_layer(x)
@@ -35,20 +35,9 @@ get_layer_estimates <- function(x, token = Sys.getenv("ARCGIS_TOKEN")) {
3535
"getEstimates"
3636
)
3737

38-
# token bug :[
39-
if (token != "") {
40-
req <-
41-
httr2::req_auth_bearer_token(
42-
httr2::req_url_query(est_req, f = "json"),
43-
token
44-
)
45-
resp <- httr2::req_perform(req)
46-
} else {
47-
resp <-
48-
httr2::req_perform(
49-
httr2::req_url_query(est_req, f = "json")
50-
)
51-
}
38+
resp <- httr2::req_perform(
39+
httr2::req_url_query(est_req, f = "json")
40+
)
5241

5342
# process json string
5443
res_raw <- RcppSimdJson::fparse(httr2::resp_body_string(resp))

R/truncate.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ truncate_layer <- function(
3333
x,
3434
async = FALSE,
3535
attachment_only = FALSE,
36-
token = Sys.getenv("ARCGIS_TOKEN")
36+
token = arc_token()
3737
) {
3838

3939
# check to see if it is a compatible class

R/utils-feature-server.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#' get_layers(fserv, name = c("Tracts", "ZCTAs"))
3737
#' get_all_layers(fserv)
3838
#' }
39-
get_layer <- function(x, id = NULL, name = NULL, token = Sys.getenv("ARCGIS_TOKEN")) {
39+
get_layer <- function(x, id = NULL, name = NULL, token = arc_token()) {
4040
# check for mutual exclusivity between id and name
4141
if (is.null(id) && is.null(name)) {
4242
cli::cli_abort("{.arg id} or {.arg name} must be provided.")
@@ -55,7 +55,7 @@ get_layer <- function(x, id = NULL, name = NULL, token = Sys.getenv("ARCGIS_TOKE
5555
}
5656

5757
#' @export
58-
get_layer.default <- function(x, id = NULL, name = NULL, token = Sys.getenv("ARCGIS_TOKEN")) {
58+
get_layer.default <- function(x, id = NULL, name = NULL, token = arc_token()) {
5959

6060
if (!is.null(name)) {
6161

@@ -104,7 +104,7 @@ get_layer.GroupLayer <- function(
104104
x,
105105
id = NULL,
106106
name = NULL,
107-
token = Sys.getenv("ARCGIS_TOKEN")
107+
token = arc_token()
108108
) {
109109
if (!is.null(name)) {
110110

@@ -148,12 +148,12 @@ get_layer.GroupLayer <- function(
148148

149149
#' @rdname get_layer
150150
#' @export
151-
get_all_layers <- function(x, token = Sys.getenv("ARCGIS_TOKEN")) {
151+
get_all_layers <- function(x, token = arc_token()) {
152152
UseMethod("get_all_layers")
153153
}
154154

155155
#' @export
156-
get_all_layers.default <- function(x, token = Sys.getenv("ARCGIS_TOKEN")) {
156+
get_all_layers.default <- function(x, token = arc_token()) {
157157
layer_ids <- x[["layers"]][["id"]]
158158
table_ids <- x[["tables"]][["id"]]
159159
layers <- lapply(file.path(x[["url"]], layer_ids), arc_open, token = token)
@@ -168,7 +168,7 @@ get_all_layers.default <- function(x, token = Sys.getenv("ARCGIS_TOKEN")) {
168168
}
169169

170170
#' @export
171-
get_all_layers.GroupLayer <- function(x, token = Sys.getenv("ARCGIS_TOKEN")) {
171+
get_all_layers.GroupLayer <- function(x, token = arc_token()) {
172172
all_layer_ids <- x[["subLayers"]][["id"]]
173173

174174
all_layer_paths <- vapply(
@@ -187,7 +187,7 @@ get_layers <- function(
187187
x,
188188
id = NULL,
189189
name = NULL,
190-
token = Sys.getenv("ARCGIS_TOKEN")
190+
token = arc_token()
191191
) {
192192
if (is.null(id) && is.null(name)) {
193193
cli::cli_abort("{.arg id} or {.arg name} must be provided.")
@@ -204,7 +204,7 @@ get_layers <- function(
204204
}
205205

206206
#' @export
207-
get_layers.default <- function(x, id = NULL, name = NULL, token = Sys.getenv("ARCGIS_TOKEN")) {
207+
get_layers.default <- function(x, id = NULL, name = NULL, token = arc_token()) {
208208

209209
if (!is.null(id)) {
210210
# cast as integer
@@ -260,7 +260,7 @@ get_layers.GroupLayer <- function(
260260
x,
261261
id = NULL,
262262
name = NULL,
263-
token = Sys.getenv("ARCGIS_TOKEN")
263+
token = arc_token()
264264
) {
265265
if (!is.null(id)) {
266266
# cast as integer

man/arc_open.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/arc_raster.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/arc_read.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/arc_select.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/create_feature_server.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_layer.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_layer_estimates.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/modify.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/publish.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/truncate_layer.Rd

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)