Skip to content

Commit

Permalink
def
Browse files Browse the repository at this point in the history
  • Loading branch information
yannikbuhl committed Sep 24, 2024
1 parent 92a9c1b commit 06e5634
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 93 deletions.
44 changes: 26 additions & 18 deletions R/gen_api.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' gen_api
#' gen_genesis_api
#'
#' @description Low-level function to interact with the GENESIS API
#'
Expand All @@ -10,22 +10,11 @@
#'
#' @examples
#' \dontrun{
#' gen_api("helloworld/logincheck") %>%
#' httr2::resp_body_json()
#' gen_genesis_api("helloworld/logincheck") %>%
#' httr2::resp_body_json()
#' }
#'
# gen_api <- function(endpoint, ...) {
#
# httr2::request("https://www-genesis.destatis.de/genesisWS/rest/2020") %>%
# httr2::req_user_agent("https://github.com/CorrelAid/restatis") %>%
# httr2::req_url_path_append(endpoint) %>%
# httr2::req_url_query(!!!gen_auth_get(database = "genesis"), ...) %>%
# httr2::req_retry(max_tries = 3) %>%
# httr2::req_perform()
#
# }

gen_api <- function(endpoint, ...) {
gen_genesis_api <- function(endpoint, ...) {

url <- "https://www-genesis.destatis.de/genesisWS/rest/2020"
user_agent <- "https://github.com/CorrelAid/restatis"
Expand Down Expand Up @@ -104,10 +93,29 @@ gen_regio_api <- function(endpoint, ...) {
#'
gen_zensus_api <- function(endpoint, ...) {

httr2::request("https://ergebnisse.zensus2022.de/api/rest/2020") %>%
httr2::req_user_agent("https://github.com/CorrelAid/restatis") %>%
url <- "https://ergebnisse.zensus2022.de/api/rest/2020"
user_agent <- "https://github.com/CorrelAid/restatis"

body_parameters <- list(...)

if (length(body_parameters) > 0) {

req <- httr2::request(url) %>%
httr2::req_body_form(!!!body_parameters)

} else {

req <- httr2::request(url) %>%
httr2::req_body_form(!!!list("foo" = "bar"))

}

req %>%
httr2::req_user_agent(user_agent) %>%
httr2::req_url_path_append(endpoint) %>%
httr2::req_url_query(!!!gen_auth_get(database = "zensus"), ...) %>%
httr2::req_headers("Content-Type" = "application/x-www-form-urlencoded",
"username" = gen_auth_get(database = "zensus")$username,
"password" = gen_auth_get(database = "zensus")$password) %>%
httr2::req_retry(max_tries = 3) %>%
httr2::req_perform()

Expand Down
2 changes: 1 addition & 1 deletion R/gen_catalogue.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ gen_catalogue <- function(code = NULL,

list_of_cubes <- "There are generally no 'cubes' objects available for the 'zensus' database."

} else if ("cubes" %in% category && (db == "gen_api" | db == "gen_regio_api")) {
} else if ("cubes" %in% category && (db == "gen_genesis_api" | db == "gen_regio_api")) {

results_raw <- do.call(db,
list(endpoint = "catalogue/cubes",
Expand Down
42 changes: 21 additions & 21 deletions R/gen_cube.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,27 @@ gen_cube_ <- function(name,

if (database == "genesis") {

cube_raw <- gen_api("data/cubefile",
name = name,
area = area,
values = values,
metadata = metadata,
additionals = additionals,
startyear = startyear,
endyear = endyear,
timeslices = timeslices,
contents = contents,
regionalvariable = regionalvariable,
regionalkey = regionalkey,
classifyingvariable1 = classifyingvariable1,
classifyingkey1 = classifyingkey1,
classifyingvariable2 = classifyingvariable2,
classifyingkey2 = classifyingkey2,
classifyingvariable3 = classifyingvariable3,
classifyingkey3 = classifyingkey3,
stand = stand,
language = language,
job = FALSE)
cube_raw <- gen_genesis_api("data/cubefile",
name = name,
area = area,
values = values,
metadata = metadata,
additionals = additionals,
startyear = startyear,
endyear = endyear,
timeslices = timeslices,
contents = contents,
regionalvariable = regionalvariable,
regionalkey = regionalkey,
classifyingvariable1 = classifyingvariable1,
classifyingkey1 = classifyingkey1,
classifyingvariable2 = classifyingvariable2,
classifyingkey2 = classifyingkey2,
classifyingvariable3 = classifyingvariable3,
classifyingkey3 = classifyingkey3,
stand = stand,
language = language,
job = FALSE)

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

Expand Down
2 changes: 1 addition & 1 deletion R/gen_find.R
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ gen_find <- function(term = NULL,

if("cubes" %in% category) {

if (db == "gen_api" | db == "gen_regio_api") {
if (db == "gen_genesis_api" | db == "gen_regio_api") {

if(!is.null(results_json$Cubes)) {

Expand Down
14 changes: 7 additions & 7 deletions R/gen_jobs.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ gen_list_jobs <- function(database = c("genesis", "regio"),

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

if (gen_fun == "gen_api"){
if (gen_fun == "gen_genesis_api"){

par_list <- list(endpoint = "catalogue/jobs",
sortcriterion = sortcriterion,
Expand Down Expand Up @@ -169,12 +169,12 @@ gen_download_job <- function(name,

if (database == "genesis") {

response <- gen_api("data/resultfile",
name = name,
area = area,
compress = compress,
format = "ffcsv",
language = language)
response <- gen_genesis_api("data/resultfile",
name = name,
area = area,
compress = compress,
format = "ffcsv",
language = language)

response_type <- resp_check_data(response)

Expand Down
10 changes: 5 additions & 5 deletions R/gen_meta_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ gen_metadata_stats <- function(code = NULL,

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

results_raw <- gen_api("metadata/statistic",
results_raw <- gen_genesis_api("metadata/statistic",
name = code,
...
)
Expand Down Expand Up @@ -91,7 +91,7 @@ gen_metadata_var <- function(code = NULL,

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

results_raw <- gen_api("metadata/variable",
results_raw <- gen_genesis_api("metadata/variable",
name = code,
...
)
Expand Down Expand Up @@ -160,7 +160,7 @@ gen_metadata_val <- function(code = NULL,

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

results_raw <- gen_api("metadata/value",
results_raw <- gen_genesis_api("metadata/value",
name = code,
...
)
Expand Down Expand Up @@ -226,7 +226,7 @@ gen_metadata_tab <- function(code = NULL,

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

results_raw <- gen_api("metadata/table",
results_raw <- gen_genesis_api("metadata/table",
name = code,
...
)
Expand Down Expand Up @@ -372,7 +372,7 @@ gen_metadata_cube <- function(code = NULL,

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

results_raw <- gen_api("metadata/cube",
results_raw <- gen_genesis_api("metadata/cube",
name = code,
...
)
Expand Down
6 changes: 3 additions & 3 deletions R/gen_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ gen_metadata_statistic <- function(code = NULL,
name = code,
...)

if (db == "gen_api" | db == "gen_regio_api") {
if (db == "gen_genesis_api" | db == "gen_regio_api") {

par_list <- append(par_list, list(area = area))

Expand Down Expand Up @@ -187,7 +187,7 @@ gen_metadata_variable <- function(code = NULL,
name = code,
...)

if (db == "gen_api" | db == "gen_regio_api") {
if (db == "gen_genesis_api" | db == "gen_regio_api") {

par_list <- append(par_list, list(area = area))

Expand Down Expand Up @@ -320,7 +320,7 @@ gen_metadata_value <- function(code = NULL,
name = code,
...)

if (db == "gen_api" | db == "gen_regio_api") {
if (db == "gen_genesis_api" | db == "gen_regio_api") {

par_list <- append(par_list, list(area = area))

Expand Down
2 changes: 1 addition & 1 deletion R/gen_modified_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ gen_modified_data <- function(code = "",

if (type == "statisticsUpdates") {

if (db == "gen_api" | db == "gen_api_regio") {
if (db == "gen_genesis_api" | db == "gen_regio_api") {

par_list <- list(endpoint = "catalogue/modifieddata",
username = gen_auth_get(database = rev_database_function(db))$username,
Expand Down
2 changes: 1 addition & 1 deletion R/gen_objects2stat.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ gen_objects2stat <- function(code = NULL,

return(df_cubes)

} else if ("cubes" %in% category && (db == "gen_api" || db == "gen_regio_api")) {
} else if ("cubes" %in% category && (db == "gen_genesis_api" || db == "gen_regio_api")) {

results_raw <- do.call(db, list(endpoint = "catalogue/cubes2statistic",
username = gen_auth_get(database = rev_database_function(db))$username,
Expand Down
2 changes: 1 addition & 1 deletion R/gen_objects2var.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ gen_objects2var <- function(code = NULL,

df_cubes <- "There are generally no 'cubes' objects available for the 'zensus' database."

} else if ("cubes" %in% category && (db == "gen_api" || db == "gen_regio_api")) {
} else if ("cubes" %in% category && (db == "gen_genesis_api" || db == "gen_regio_api")) {

results_raw <- do.call(db, list(endpoint = "catalogue/timeseries2variable",
username = gen_auth_get(database = rev_database_function(db))$username,
Expand Down
38 changes: 19 additions & 19 deletions R/gen_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,25 @@ gen_table_ <- function(name,

} else if (database == "genesis"){

response <- gen_api("data/tablefile",
name = name,
area = area,
compress = compress,
transpose = transpose,
startyear = startyear,
endyear = endyear,
regionalvariable = regionalvariable,
regionalkey = regionalkey,
classifyingvariable1 = classifyingvariable1,
classifyingkey1 = classifyingkey1,
classifyingvariable2 = classifyingvariable2,
classifyingkey2 = classifyingkey2,
classifyingvariable3 = classifyingvariable3,
classifyingkey3 = classifyingkey3,
stand = stand,
language = language,
format = "ffcsv",
job = job)
response <- gen_genesis_api("data/tablefile",
name = name,
area = area,
compress = compress,
transpose = transpose,
startyear = startyear,
endyear = endyear,
regionalvariable = regionalvariable,
regionalkey = regionalkey,
classifyingvariable1 = classifyingvariable1,
classifyingkey1 = classifyingkey1,
classifyingvariable2 = classifyingvariable2,
classifyingkey2 = classifyingkey2,
classifyingvariable3 = classifyingvariable3,
classifyingkey3 = classifyingkey3,
stand = stand,
language = language,
format = "ffcsv",
job = job)

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

Expand Down
6 changes: 3 additions & 3 deletions R/gen_var2-val2.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ gen_var2stat <- function(code = NULL,
name = code,
...)

if (db == "gen_api" | db == "gen_regio_api") {
if (db == "gen_genesis_api" | db == "gen_regio_api") {

par_list <- append(par_list, list(area = area))

Expand Down Expand Up @@ -209,7 +209,7 @@ gen_val2var <- function(code = NULL,
name = code,
...)

if (db == "gen_api" | db == "gen_regio_api") {
if (db == "gen_genesis_api" | db == "gen_regio_api") {

par_list <- append(par_list, list(area = area))

Expand Down Expand Up @@ -456,7 +456,7 @@ gen_search_vars <- function(code = NULL,
area = area,
...)

if (db == "gen_api" | db == "gen_regio_api") {
if (db == "gen_genesis_api" | db == "gen_regio_api") {

par_list <- append(par_list, list(area = area))

Expand Down
Loading

0 comments on commit 06e5634

Please sign in to comment.