Skip to content

Fix #60 #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions R/utils-url.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Parse aan ArcGIS service or content URL into its components
#' Parse an ArcGIS service or content URL into its components
#'
#' [arc_url_parse()] uses [httr2::url_parse()] to parse URL components and
#' combine the components with a service or content URL `type` and a `layer`
Expand Down Expand Up @@ -32,10 +32,7 @@ arc_url_parse <- function(url, base_url = NULL) {
# Extract trailing layer number from URL path
layer <- NULL
if (has_arc_url_layer(httr2_url[["path"]])) {
layer <- str_extract(
httr2_url[["path"]],
"(?<=/)([0-9]+(?=/)|[0-9]+$)"
)
layer <- str_extract_layer(httr2_url[["path"]])
}

c(
Expand All @@ -57,13 +54,13 @@ has_arc_url_layer <- function(
) {
layer <- layer %||% "[0-9]+"
pattern <- paste0(
"(?<=(",
"(",
paste0(services, collapse = "|"),
")/)",
")/",
layer,
"/?$"
)
grepl(pattern, url, perl = TRUE)
grepl(pattern, url)
}

#' Vector of valid ArcGIS service types
Expand Down Expand Up @@ -155,3 +152,15 @@ is_url <- function(

grepl(url_pattern, x) & grepl(pattern, x, ...)
}

#' Extract layer number (w/ or w/o trailing slash)
#' @noRd
str_extract_layer <- function(x) {
trailing_txt <- str_extract(
x,
"(?:\\/)([[:digit:]]+)(?:\\/?)$",
perl = FALSE
)

str_extract(trailing_txt, "[[:digit:]]+", perl = FALSE)
}
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ check_dots_named <- function(dots, call = rlang::caller_env()) {

#' Extract matching patterns from a string
#' @noRd
str_extract <- function(string, pattern) {
matches <- regexpr(pattern, string, perl = TRUE)
str_extract <- function(string, pattern, perl = TRUE) {
matches <- regexpr(pattern, string, perl = perl)
regmatches(string, matches)
}
4 changes: 2 additions & 2 deletions man/auth.Rd

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

Loading