Skip to content

Commit

Permalink
Merge pull request #40 from jacpete/MakeEsriUrlChecksMoreGeneral
Browse files Browse the repository at this point in the history
Make esri url checks more general
  • Loading branch information
jacpete authored May 11, 2022
2 parents 9abb560 + 6745aa3 commit e8b2756
Show file tree
Hide file tree
Showing 11 changed files with 3,364 additions and 148 deletions.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ export(esri2sf)
export(esriLayers)
export(esriUrl_ServerUrl)
export(esriUrl_isValid)
export(esriUrl_isValidFeature)
export(esriUrl_isValidFolder)
export(esriUrl_isValidID)
export(esriUrl_isValidRoot)
export(esriUrl_isValidService)
export(esriUrl_parseUrl)
export(esriUrl_serviceUrl)
export(esrimeta)
6 changes: 3 additions & 3 deletions R/esri2sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ esri2sf <- function(url, outFields = c("*"), where = "1=1", bbox = NULL, token =
#make sure url is valid and error otherwise
tryCatch(
{
esriUrl_isValidID(url, displayReason = TRUE)
esriUrl_isValidFeature(url, token = token, displayReason = TRUE)
}, message = function(m) {
stop(m$message)
}
Expand Down Expand Up @@ -103,7 +103,7 @@ esri2df <- function(url, outFields = c("*"), where = "1=1", token = "", progress
#make sure url is valid and error otherwise
tryCatch(
{
esriUrl_isValidID(url, displayReason = TRUE)
esriUrl_isValidFeature(url, token = token, displayReason = TRUE)
}, message = function(m) {
stop(m$message)
}
Expand Down Expand Up @@ -132,7 +132,7 @@ esrimeta <- function(url, token = "", fields = FALSE) {
#make sure url is valid and error otherwise
tryCatch(
{
esriUrl_isValid(url, displayReason = TRUE)
esriUrl_isValid(url, token = token, displayReason = TRUE)
}, message = function(m) {
stop(m$message)
}
Expand Down
13 changes: 10 additions & 3 deletions R/esriLayers.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' @title Get All Layers and Tables for the whole server
#' @title Get All Layers and Tables for the whole service
#'
#' @description Retrieve JSON for all layers and tables as specified in
#' [https://si-pweb-vecmap.si.edu/vectormap/sdk/rest/index.html#/All_Layers_and_Tables/02ss0000005t000000/](https://si-pweb-vecmap.si.edu/vectormap/sdk/rest/index.html#/All_Layers_and_Tables/02ss0000005t000000/).
#' Service type must either be a MapServer or FeatureServer.
#' Performs a POST request towards the server url in one of the following the
#' forms:
#' * `https://<host>/<instance>/rest/services/<folderName>/serviceName>/MapServer/layers`
Expand All @@ -11,15 +12,21 @@
#'
#' @param url The url for the Map/Feature server. If given a url specifying a
#' layer or table ID it will truncate it.
#' @param token String for authentication token (if needed).
#'
#' @return A list from the JSON return.
#' @export
esriLayers <- function(url) {
esriLayers <- function(url, token = "") {
#Format url (remove layer.table ID and check it is valid)
urlServer <- esriUrl_ServerUrl(url)
urlServer <- esriUrl_serviceUrl(url, token = token)

if (!grepl("/(FeatureServer|MapServer)/?$", urlServer)) {
stop("Url is not valid.\n Service type is not either 'MapServer' or 'FeatureServer'")
}

query <- list(
f = "json",
token = token,
returnDomainNames = TRUE
)

Expand Down
Loading

0 comments on commit e8b2756

Please sign in to comment.