Skip to content
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

Make esri url checks more general #40

Merged
merged 16 commits into from
May 11, 2022
Merged
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
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