Skip to content

Commit

Permalink
feat: initial support for metadata endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
m-muecke committed Jan 6, 2024
1 parent 6732088 commit a192091
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 0 deletions.
12 changes: 12 additions & 0 deletions NAMESPACE
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)
69 changes: 69 additions & 0 deletions R/api.R
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)
}
Empty file removed R/bb.R
Empty file.
14 changes: 14 additions & 0 deletions R/bundesbank-package.R
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
4 changes: 4 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ You can install the development version of bundesbank from [GitHub](https://gith
# install.packages("pak")
pak::pak("m-muecke/bundesbank")
```

## Other Bundesbank API packages

* [bundesbank](https://github.com/enricoschumann/bundesbank)
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ You can install the development version of bundesbank from
# install.packages("pak")
pak::pak("m-muecke/bundesbank")
```

## Other Bundesbank API packages

- [bundesbank](https://github.com/enricoschumann/bundesbank)
20 changes: 20 additions & 0 deletions man/bb_codelist.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions man/bb_data_structure.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions man/bb_dataflow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions man/bundesbank-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a192091

Please sign in to comment.