Skip to content

Commit

Permalink
feat: change response message to english default and add function exa…
Browse files Browse the repository at this point in the history
…mples
  • Loading branch information
m-muecke committed Jan 14, 2024
1 parent 7c9406a commit 6761f6c
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 8 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ repos:
exclude: \.Rd
- id: file-contents-sorter
files: ^\.Rbuildignore$
- id: trailing-whitespace
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.3.2.9027
hooks:
Expand Down
20 changes: 19 additions & 1 deletion R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#' @references <https://www.bundesbank.de/en/statistics/time-series-databases/help-for-sdmx-web-service/web-service-interface-data>
#' @family data
#' @export
#' @examples
#' bb_data("BBSIS", "D.I.ZST.ZI.EUR.S1311.B.A604.R10XX.R.A.A._Z._Z.A")
bb_data <- function(flow, key = NULL) {
stopifnot(is.character(flow), is.null(key) || is.character(key))
flow <- toupper(flow)
Expand Down Expand Up @@ -36,6 +38,8 @@ bb_data <- function(flow, key = NULL) {
#' @references <https://www.bundesbank.de/en/statistics/time-series-databases/help-for-sdmx-web-service/web-service-interface-metadata>
#' @family metadata
#' @export
#' @examples
#' bb_data_structure()
bb_data_structure <- function(id = NULL) {
bb_metadata("metadata/datastructure/BBK", id)
}
Expand All @@ -46,6 +50,8 @@ bb_data_structure <- function(id = NULL) {
#' @references <https://www.bundesbank.de/en/statistics/time-series-databases/help-for-sdmx-web-service/web-service-interface-metadata>
#' @family metadata
#' @export
#' @examples
#' bb_dataflow()
bb_dataflow <- function(id = NULL) {
bb_metadata("metadata/dataflow/BBK", id)
}
Expand All @@ -56,6 +62,8 @@ bb_dataflow <- function(id = NULL) {
#' @references <https://www.bundesbank.de/en/statistics/time-series-databases/help-for-sdmx-web-service/web-service-interface-metadata>
#' @family metadata
#' @export
#' @examples
#' bb_codelist()
bb_codelist <- function(id = NULL) {
bb_metadata("metadata/codelist/BBK", id)
}
Expand All @@ -66,10 +74,19 @@ bb_codelist <- function(id = NULL) {
#' @references <https://www.bundesbank.de/en/statistics/time-series-databases/help-for-sdmx-web-service/web-service-interface-metadata>
#' @family metadata
#' @export
#' @examples
#' bb_concept_scheme()
bb_concept_scheme <- function(id = NULL) {
bb_metadata("metadata/conceptscheme/BBK", id)
}

bb_error_body <- function(resp) {
body <- resp_body_json(resp)
message <- body$title
docs <- "See docs at <https://www.bundesbank.de/en/statistics/time-series-databases/help-for-sdmx-web-service/status-codes/status-codes-855918>"
c(message, docs)
}

bb_metadata <- function(resource, id = NULL) {
stopifnot(is.null(id) || is.character(id) && length(id) == 1)
# only supports xml return format
Expand All @@ -83,8 +100,9 @@ bb_metadata <- function(resource, id = NULL) {
bb_make_request <- function(resource) {
request("https://api.statistiken.bundesbank.de/rest") |>
req_user_agent("worldbank (https://m-muecke.github.io/worldbank)") |>
req_headers(`Accept-Language` = "en") |>
req_url_path_append(resource) |>
req_error(body = \(resp) resp_body_json(resp)$title) |>
req_error(body = bb_error_body) |>
req_perform() |>
resp_body_xml()
}
6 changes: 3 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ knitr::opts_chunk$set(
[![R-CMD-check](https://github.com/m-muecke/bundesbank/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/m-muecke/bundesbank/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

The goal of bundesbank is to provide a simple interface to the [Bundesbank time series database API](https://www.bundesbank.de/en/statistics/time-series-databases/help-for-sdmx-web-service).
The goal of bundesbank is to provide a simple interface to the [Bundesbank API](https://www.bundesbank.de/en/statistics/time-series-databases/help-for-sdmx-web-service).

## Installation
You can install the development version of bundesbank from [GitHub](https://github.com/) with:
Expand All @@ -30,6 +30,6 @@ You can install the development version of bundesbank from [GitHub](https://gith
pak::pak("m-muecke/bundesbank")
```

## Other Bundesbank API packages
## Related work

* [bundesbank](https://github.com/enricoschumann/bundesbank)
* [bundesbank](https://github.com/enricoschumann/bundesbank): R scripts for downloading time-series data from the Bundesbank
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](h
<!-- badges: end -->

The goal of bundesbank is to provide a simple interface to the
[Bundesbank time series database
[Bundesbank
API](https://www.bundesbank.de/en/statistics/time-series-databases/help-for-sdmx-web-service).

## Installation
Expand All @@ -24,6 +24,7 @@ You can install the development version of bundesbank from
pak::pak("m-muecke/bundesbank")
```

## Other Bundesbank API packages
## Related work

- [bundesbank](https://github.com/enricoschumann/bundesbank)
- [bundesbank](https://github.com/enricoschumann/bundesbank): R scripts
for downloading time-series data from the Bundesbank
3 changes: 3 additions & 0 deletions man/bb_codelist.Rd

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

3 changes: 3 additions & 0 deletions man/bb_concept_scheme.Rd

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

3 changes: 3 additions & 0 deletions man/bb_data.Rd

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

3 changes: 3 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.

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

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

0 comments on commit 6761f6c

Please sign in to comment.