Skip to content

Commit

Permalink
move api urls to r environ
Browse files Browse the repository at this point in the history
  • Loading branch information
yannikbuhl committed Sep 27, 2024
1 parent 66dffcd commit 4b2a011
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 31 deletions.
1 change: 1 addition & 0 deletions R/gen_alternative_terms.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ gen_alternative_terms <- function(term = NULL,
database = c("all", "genesis", "zensus", "regio"),
verbose = TRUE,
...) {

caller <- as.character(match.call()[1])

gen_fun <- test_database_function(database,
Expand Down
14 changes: 3 additions & 11 deletions R/gen_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
#' }
#'
gen_genesis_api <- function(endpoint,
overwrite_url,
...) {

url <- ifelse(is.null(overwrite_url),
"https://www-genesis.destatis.de/genesisWS/rest/2020",
overwrite_url)
url <- Sys.getenv("RESTATIS_GENESIS_URL")

user_agent <- "https://github.com/CorrelAid/restatis"

Expand Down Expand Up @@ -75,9 +72,7 @@ gen_regio_api <- function(endpoint,
overwrite_url,
...) {

url <- ifelse(is.null(overwrite),
"https://www.regionalstatistik.de/genesisws/rest/2020/",
overwrite_url)
url <- Sys.getenv("RESTATIS_REGIO_URL")

httr2::request(url) %>%
httr2::req_user_agent("https://github.com/CorrelAid/restatis") %>%
Expand Down Expand Up @@ -109,12 +104,9 @@ gen_regio_api <- function(endpoint,
#' }
#'
gen_zensus_api <- function(endpoint,
overwrite_url,
...) {

url <- ifelse(is.null(overwrite_url),
"https://ergebnisse.zensus2022.de/api/rest/2020",
overwrite_url)
url <- Sys.getenv("RESTATIS_ZENSUS_URL")

user_agent <- "https://github.com/CorrelAid/restatis"

Expand Down
1 change: 1 addition & 0 deletions R/gen_catalogue.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ gen_catalogue <- function(code = NULL,
error.ignore = FALSE,
verbose = TRUE,
...) {

caller <- as.character(match.call()[1])

gen_fun <- test_database_function(database,
Expand Down
3 changes: 2 additions & 1 deletion R/gen_cube.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ gen_cube_ <- function(name,
classifyingvariable3 = NULL,
classifyingkey3 = NULL,
stand = NULL,
language = Sys.getenv("GENESIS_LANG")) {
language = Sys.getenv("RESTATIS_LANG")) {

area <- match.arg(area)
database <- match.arg(database)

Expand Down
1 change: 1 addition & 0 deletions R/gen_find.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ gen_find <- function(term = NULL,
error.ignore = TRUE,
verbose = TRUE,
...) {

caller <- as.character(match.call()[1])

gen_fun <- test_database_function(database,
Expand Down
2 changes: 1 addition & 1 deletion R/gen_jobs.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ gen_download_job <- function(name,
database = c("genesis", "regio"),
area = c("all", "public", "user"),
compress = FALSE,
language = Sys.getenv("GENESIS_LANG"),
language = Sys.getenv("RESTATIS_LANG"),
all_character = TRUE) {

#-----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions R/gen_objects2var.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ gen_objects2var <- function(code = NULL,
error.ignore = FALSE,
verbose = TRUE,
...) {

caller <- as.character(match.call()[1])

gen_fun <- test_database_function(database,
Expand Down
22 changes: 5 additions & 17 deletions R/gen_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ gen_table_ <- function(name,
classifyingvariable3 = NULL,
classifyingkey3 = NULL,
stand = NULL,
language = Sys.getenv("GENESIS_LANG"),
language = Sys.getenv("RESTATIS_LANG"),
job = FALSE,
all_character = TRUE,
overwrite_url = NULL) {
all_character = TRUE) {

#-----------------------------------------------------------------------------
# Parameter processing
Expand All @@ -88,14 +87,6 @@ gen_table_ <- function(name,

}

if (!is.null(overwrite_url) &
(!is.character(overwrite_url) | length(overwrite_url) != 1)) {

stop("The parameter 'overwrite_url' has to be of type 'character' and of length 1.",
call. = FALSE)

}

database <- match.arg(database)

area <- match.arg(area)
Expand Down Expand Up @@ -141,8 +132,7 @@ gen_table_ <- function(name,
stand = stand,
language = language,
format = "ffcsv",
job = FALSE,
overwrite_url = overwrite_url)
job = FALSE)

#-----------------------------------------------------------------------------

Expand All @@ -166,8 +156,7 @@ gen_table_ <- function(name,
stand = stand,
language = language,
format = "ffcsv",
job = job,
overwrite_url = overwrite_url)
job = job)

#-----------------------------------------------------------------------------

Expand All @@ -191,8 +180,7 @@ gen_table_ <- function(name,
stand = stand,
language = language,
format = "ffcsv",
job = job,
overwrite_url = overwrite_url)
job = job)

#-----------------------------------------------------------------------------

Expand Down
25 changes: 24 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
.onLoad <- function(libname, pkgname) {

# Set the functions whose results are to be cached
gen_genesis_api <<- memoise::memoise(gen_genesis_api)
gen_zensus_api <<- memoise::memoise(gen_zensus_api)
gen_regio_api <<- memoise::memoise(gen_regio_api)

if (!nzchar(Sys.getenv("GENESIS_LANG"))) Sys.setenv(GENESIS_LANG = "en")
# Set the default language of the package
if (!nzchar(Sys.getenv("RESTATIS_LANG"))) Sys.setenv(GENESIS_LANG = "en")

# Set the default URL for the GENESIS database
if (!nzchar(Sys.getenv("RESTATIS_GENESIS_URL"))) {

Sys.setenv(RESTATIS_GENESIS_URL = "https://www-genesis.destatis.de/genesisWS/rest/2020")

}

# Set the default URL for the www.regionalstatistik.de database
if (!nzchar(Sys.getenv("RESTATIS_REGIO_URL"))) {

Sys.setenv(RESTATIS_REGIO_URL = "https://www.regionalstatistik.de/genesisws/rest/2020/")

}

# Set the default URL for the ZENSUS 2022 database
if (!nzchar(Sys.getenv("RESTATIS_ZENSUS_URL"))) {

Sys.setenv(RESTATIS_ZENSUS_URL = "https://ergebnisse.zensus2022.de/api/rest/2020")

}

}

0 comments on commit 4b2a011

Please sign in to comment.