R/pxweb_build_pxweb_urls.R

Defines functions build_pxweb_config_url.url build_pxweb_config_url.pxweb build_pxweb_config_url.list build_pxweb_config_url build_pxweb_url.url build_pxweb_url.pxweb_api_catalogue_entry build_pxweb_url.pxweb build_pxweb_url.character build_pxweb_url.list build_pxweb_url

Documented in build_pxweb_config_url build_pxweb_config_url.list build_pxweb_config_url.pxweb build_pxweb_config_url.url build_pxweb_url build_pxweb_url.character build_pxweb_url.list build_pxweb_url.pxweb build_pxweb_url.pxweb_api_catalogue_entry build_pxweb_url.url

#' Build the url to a PXWEB api
#' 
#' @keywords internal
#' 
build_pxweb_url <- function(x){
  UseMethod("build_pxweb_url")
}

#' @rdname build_pxweb_url
#' @keywords internal
build_pxweb_url.list <- function(x) {
  assert_pxweb_url(x)
  build_pxweb_url(x$url)
}

#' @rdname build_pxweb_url
#' @keywords internal
build_pxweb_url.character <- function(x) {
  build_pxweb_url(httr::parse_url(x))
}

#' @rdname build_pxweb_url
#' @keywords internal
build_pxweb_url.pxweb <- function(x) {
  build_pxweb_url(x$url)
}

#' @rdname build_pxweb_url
#' @keywords internal
build_pxweb_url.pxweb_api_catalogue_entry <- function(x) {
  base_url <- x$url
  base_url <- gsub("\\[version\\]", base_url, replacement = x$version[1])
  base_url <- gsub("\\[lang\\]", base_url, replacement = x$lang[1])
  build_pxweb_url(base_url)
}

#' @rdname build_pxweb_config_url
#' @keywords internal
build_pxweb_url.url <- function(x) {
  scheme <- x$scheme
  hostname <- x$hostname
  if (!is.null(x$port)) {
    port <- paste0(":", x$port)
  } else {
    port <- NULL
  }
  path <- paste(gsub("^/", "", x$path), collapse = "/")
  paste0(scheme, "://", hostname, port, "/", path)
}


#' Build the url to get the config from a PXWEB api
#' 
#' @keywords internal
#' 
build_pxweb_config_url <- function(x){
  UseMethod("build_pxweb_config_url")
}

#' @rdname build_pxweb_config_url
#' @keywords internal
build_pxweb_config_url.list <- function(x) {
  assert_pxweb_url(x)
  build_pxweb_config_url(x$url)
}

#' @rdname build_pxweb_config_url
#' @keywords internal
build_pxweb_config_url.pxweb <- function(x) {
  build_pxweb_config_url(x$url)
}

#' @rdname build_pxweb_config_url
#' @keywords internal
build_pxweb_config_url.url <- function(x) {
  paste0(build_pxweb_url(x), "?config")
}

Try the pxweb package in your browser

Any scripts or data that you put into this service are public.

pxweb documentation built on Oct. 31, 2022, 5:07 p.m.