-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial support for metadata endpoints
- Loading branch information
Showing
10 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(bb_codelist) | ||
export(bb_concept_scheme) | ||
export(bb_data_structure) | ||
export(bb_dataflow) | ||
importFrom(httr2,req_error) | ||
importFrom(httr2,req_headers) | ||
importFrom(httr2,req_perform) | ||
importFrom(httr2,req_url_path_append) | ||
importFrom(httr2,req_user_agent) | ||
importFrom(httr2,request) | ||
importFrom(httr2,resp_body_json) | ||
importFrom(httr2,resp_body_xml) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
bbundesbank <- function(flow, key) { | ||
stopifnot(is.character(flow), is.character(key)) | ||
flow <- toupper(flow) | ||
key <- toupper(key) | ||
|
||
request("https://api.statistiken.bundesbank.de/rest/data") |> | ||
req_user_agent("worldbank (https://m-muecke.github.io/worldbank)") |> | ||
req_headers(Accept = "application/json") |> | ||
req_url_path_append(flow, key) |> | ||
req_perform() |> | ||
resp_body_json() | ||
} | ||
|
||
bundesbank <- function(resource) { | ||
request("https://api.statistiken.bundesbank.de/rest") |> | ||
req_user_agent("worldbank (https://m-muecke.github.io/worldbank)") |> | ||
req_url_path_append(resource) |> | ||
req_error(body = \(resp) resp_body_json(resp)$title) |> | ||
req_perform() | ||
} | ||
|
||
bb_metadata <- function(resource, id = NULL) { | ||
stopifnot(is.null(id) || is.character(id) && length(id) == 1) | ||
# only supports xml return format | ||
resource <- "metadata/datastructure/BBK" | ||
if (!is.null(id)) { | ||
resource <- paste(resource, toupper(id), sep = "/") | ||
} | ||
res <- bundesbank(resource) |> | ||
resp_body_xml() | ||
res | ||
} | ||
|
||
#' Returns available data structures | ||
#' | ||
#' @references <https://www.bundesbank.de/en/statistics/time-series-databases/help-for-sdmx-web-service/web-service-interface-metadata> # nolint | ||
#' @family metadata | ||
#' @export | ||
bb_data_structure <- function(id = NULL) { | ||
bb_metadata("metadata/datastructure/BBK", id) | ||
} | ||
|
||
#' Returns available dataflows | ||
#' | ||
#' @references <https://www.bundesbank.de/en/statistics/time-series-databases/help-for-sdmx-web-service/web-service-interface-metadata> # nolint | ||
#' @family metadata | ||
#' @export | ||
bb_dataflow <- function(id = NULL) { | ||
bb_metadata("metadata/dataflow/BBK", id) | ||
} | ||
|
||
#' Returns available code lists | ||
#' | ||
#' @references <https://www.bundesbank.de/en/statistics/time-series-databases/help-for-sdmx-web-service/web-service-interface-metadata> # nolint | ||
#' @family metadata | ||
#' @export | ||
bb_codelist <- function(id = NULL) { | ||
# TODO: check if supports json return format | ||
bb_metadata("metadata/codelist/BBK", id) | ||
} | ||
|
||
#' | ||
#' | ||
#' @references <https://www.bundesbank.de/en/statistics/time-series-databases/help-for-sdmx-web-service/web-service-interface-metadata> # nolint | ||
#' @family metadata | ||
#' @export | ||
bb_concept_scheme <- function(id = NULL) { | ||
bb_metadata("metadata/conceptscheme/BBK", id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#' @keywords internal | ||
"_PACKAGE" | ||
|
||
## usethis namespace: start | ||
#' @importFrom httr2 req_error | ||
#' @importFrom httr2 req_headers | ||
#' @importFrom httr2 req_perform | ||
#' @importFrom httr2 req_url_path_append | ||
#' @importFrom httr2 req_user_agent | ||
#' @importFrom httr2 request | ||
#' @importFrom httr2 resp_body_json | ||
#' @importFrom httr2 resp_body_xml | ||
## usethis namespace: end | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.