Skip to content

Commit 7c1e8b7

Browse files
committed
introduce overwrite_url param
1 parent 06e5634 commit 7c1e8b7

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

R/gen_api.R

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#' @description Low-level function to interact with the GENESIS API
44
#'
55
#' @param endpoint Character string. The endpoint of the API that is to be queried.
6+
#' @param overwrite_url Character string. In certain cases it is required to set a custom URL for the respective API. By specifying the URL in this parameter, the API calls will be directed to this custom URL. But be aware, the URL has to lead to the same database (in this case: GENESIS), else there will be errors. Hence, use with caution.
7+
#' @param ... Further parameters passed on to the final API call.
68
#'
79
#' @importFrom httr2 `%>%`
810
#'
@@ -14,9 +16,14 @@
1416
#' httr2::resp_body_json()
1517
#' }
1618
#'
17-
gen_genesis_api <- function(endpoint, ...) {
19+
gen_genesis_api <- function(endpoint,
20+
overwrite_url,
21+
...) {
22+
23+
url <- ifelse(is.null(overwrite_url),
24+
"https://www-genesis.destatis.de/genesisWS/rest/2020",
25+
overwrite_url)
1826

19-
url <- "https://www-genesis.destatis.de/genesisWS/rest/2020"
2027
user_agent <- "https://github.com/CorrelAid/restatis"
2128

2229
body_parameters <- list(...)
@@ -51,6 +58,8 @@ gen_genesis_api <- function(endpoint, ...) {
5158
#' @description Low-level function to interact with the regionalstatistik.de API
5259
#'
5360
#' @param endpoint Character string. The endpoint of the API that is to be queried.
61+
#' @param overwrite_url Character string. In certain cases it is required to set a custom URL for the respective API. By specifying the URL in this parameter, the API calls will be directed to this custom URL. But be aware, the URL has to lead to the same database (in this case: www.regionalstatistik.de), else there will be errors. Hence, use with caution.
62+
#' @param ... Further parameters passed on to the final API call.
5463
#'
5564
#' @importFrom httr2 `%>%`
5665
#'
@@ -62,9 +71,15 @@ gen_genesis_api <- function(endpoint, ...) {
6271
#' httr2::resp_body_json()
6372
#' }
6473
#'
65-
gen_regio_api <- function(endpoint, ...) {
74+
gen_regio_api <- function(endpoint,
75+
overwrite_url,
76+
...) {
77+
78+
url <- ifelse(is.null(overwrite),
79+
"https://www.regionalstatistik.de/genesisws/rest/2020/",
80+
overwrite_url)
6681

67-
httr2::request("https://www.regionalstatistik.de/genesisws/rest/2020/") %>%
82+
httr2::request(url) %>%
6883
httr2::req_user_agent("https://github.com/CorrelAid/restatis") %>%
6984
httr2::req_url_path_append(endpoint) %>%
7085
httr2::req_url_query(!!!gen_auth_get(database = "regio"), ...) %>%
@@ -80,6 +95,8 @@ gen_regio_api <- function(endpoint, ...) {
8095
#' @description Low-level function to interact with the Zensus 2022 database
8196
#'
8297
#' @param endpoint Character string. The endpoint of the API that is to be queried.
98+
#' @param overwrite_url Character string. In certain cases it is required to set a custom URL for the respective API. By specifying the URL in this parameter, the API calls will be directed to this custom URL. But be aware, the URL has to lead to the same database (in this case: Zensus 2022), else there will be errors. Hence, use with caution.
99+
#' @param ... Further parameters passed on to the final API call.
83100
#'
84101
#' @importFrom httr2 `%>%`
85102
#'
@@ -91,9 +108,14 @@ gen_regio_api <- function(endpoint, ...) {
91108
#' httr2::resp_body_json()
92109
#' }
93110
#'
94-
gen_zensus_api <- function(endpoint, ...) {
111+
gen_zensus_api <- function(endpoint,
112+
overwrite_url,
113+
...) {
114+
115+
url <- ifelse(is.null(overwrite_url),
116+
"https://ergebnisse.zensus2022.de/api/rest/2020",
117+
overwrite_url)
95118

96-
url <- "https://ergebnisse.zensus2022.de/api/rest/2020"
97119
user_agent <- "https://github.com/CorrelAid/restatis"
98120

99121
body_parameters <- list(...)

R/gen_table.R

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050
#' }
5151
#'
5252
gen_table <- function(name, ...) {
53+
5354
gen_table_(name, ...)
55+
5456
}
5557

5658
#-------------------------------------------------------------------------------
@@ -73,7 +75,8 @@ gen_table_ <- function(name,
7375
stand = NULL,
7476
language = Sys.getenv("GENESIS_LANG"),
7577
job = FALSE,
76-
all_character = TRUE) {
78+
all_character = TRUE,
79+
overwrite_url = NULL) {
7780

7881
#-----------------------------------------------------------------------------
7982
# Parameter processing
@@ -85,6 +88,14 @@ gen_table_ <- function(name,
8588

8689
}
8790

91+
if (!is.null(overwrite_url) &
92+
(!is.character(overwrite_url) | length(overwrite_url) != 1)) {
93+
94+
stop("The parameter 'overwrite_url' has to be of type 'character' and of length 1.",
95+
call. = FALSE)
96+
97+
}
98+
8899
database <- match.arg(database)
89100

90101
area <- match.arg(area)
@@ -130,7 +141,8 @@ gen_table_ <- function(name,
130141
stand = stand,
131142
language = language,
132143
format = "ffcsv",
133-
job = FALSE)
144+
job = FALSE,
145+
overwrite_url = overwrite_url)
134146

135147
#-----------------------------------------------------------------------------
136148

@@ -154,7 +166,8 @@ gen_table_ <- function(name,
154166
stand = stand,
155167
language = language,
156168
format = "ffcsv",
157-
job = job)
169+
job = job,
170+
overwrite_url = overwrite_url)
158171

159172
#-----------------------------------------------------------------------------
160173

@@ -178,7 +191,8 @@ gen_table_ <- function(name,
178191
stand = stand,
179192
language = language,
180193
format = "ffcsv",
181-
job = job)
194+
job = job,
195+
overwrite_url = overwrite_url)
182196

183197
#-----------------------------------------------------------------------------
184198

0 commit comments

Comments
 (0)