Skip to content

Commit 2643678

Browse files
committed
fix #185
1 parent 2745c21 commit 2643678

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

R/SDMXServiceProvider-methods.R

+64-1
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,69 @@ setSDMXServiceProviders <- function(){ # nocov start
387387
# )
388388
#)
389389

390+
#Bundesbank
391+
BBK <- SDMXServiceProvider(
392+
agencyId = "BBK", name = "Bundesbank",
393+
scale = "national", country = "DEU",
394+
builder = SDMXRequestBuilder(
395+
regUrl = "https://api.statistiken.bundesbank.de/rest/metadata",
396+
repoUrl = "https://api.statistiken.bundesbank.de/rest",
397+
formatter = list(
398+
dataflow = function(obj){return(obj)},
399+
datastructure = function(obj){return(obj)},
400+
data = function(obj){return(obj)}
401+
),
402+
#resource handler
403+
handler = list(
404+
405+
#dataflow resource (dataflow/agencyID/resourceID/version)
406+
#-----------------------------------------------------------------------
407+
dataflow = function(obj){
408+
req <- sprintf("%s/dataflow/%s",obj@regUrl, obj@providerId)
409+
if(!is.null(obj@resourceId)) req <- paste(req, obj@resourceId, sep = "/")
410+
return(req)
411+
},
412+
413+
#datastructure resource (datastructure/agencyID/resourceID/version)
414+
#--------------------------------------------------------------------------------
415+
datastructure = function(obj){
416+
req <- sprintf("%s/datastructure/%s",obj@regUrl, obj@providerId)
417+
if(!is.null(obj@resourceId)) req <- paste(req, obj@resourceId, sep = "/")
418+
req <- paste0(req, "?references=children") #TODO to see later to have arg for this
419+
return(req)
420+
},
421+
422+
#data resource (data/flowRef/key/providerRef)
423+
#----------------------------------------------------------
424+
data = function(obj){
425+
if(is.null(obj@flowRef)) stop("Missing flowRef value")
426+
req <- sprintf("%s/data/%s/%s",obj@repoUrl, obj@flowRef, obj@key)
427+
428+
#DataQuery
429+
#-> temporal extent (if any)
430+
addParams = FALSE
431+
if(!is.null(obj@start)){
432+
req <- paste0(req, "?")
433+
addParams = TRUE
434+
req <- paste0(req, "startPeriod=", obj@start)
435+
}
436+
if(!is.null(obj@end)){
437+
if(!addParams){
438+
req <- paste0(req, "?")
439+
}else{
440+
req <- paste0(req, "&")
441+
}
442+
req <- paste0(req, "endPeriod=", obj@end)
443+
}
444+
445+
return(req)
446+
}
447+
),
448+
compliant = FALSE
449+
)
450+
)
451+
452+
390453
#other data providers
391454
#--------------------
392455

@@ -440,7 +503,7 @@ setSDMXServiceProviders <- function(){ # nocov start
440503
#international
441504
BIS, ECB, ESTAT, IMF, OECD, UNICEF, CD2030, UNSD, ILO_Legacy, ILO, WBG_WITS, WB, PDH,
442505
#national
443-
ABS, NBB, INSEE, INEGI, ISTAT, NOMIS, LSD, NCSI, STAT_EE,
506+
ABS, NBB, INSEE, INEGI, ISTAT, NOMIS, LSD, NCSI, STAT_EE, BBK,
444507
#others
445508
KNOEMA
446509
)

R/SDMXServiceProviders-methods.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ as.data.frame.SDMXServiceProviders <- function(x, ...){
3131
}
3232

3333
setAs("SDMXGenericData", "data.frame",
34-
function(from) {as.data.frame.SDMXServiceProviders(from)});
34+
function(from) {as.data.frame.SDMXServiceProviders(from)})

tests/testthat/test_Main_Helpers.R

+28
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,34 @@ test_that("STAT_EE - data",{
729729
})
730730

731731

732+
#BBK (Bundesbank)
733+
#-------------
734+
#-> dataflow
735+
test_that("BBK - dataflow",{
736+
testthat::skip_on_cran()
737+
sdmx <- readSDMX(providerId = "BBK", resource = "dataflow")
738+
if(!is.null(sdmx)){
739+
expect_is(sdmx, "SDMXDataFlows")
740+
}
741+
})
742+
743+
test_that("BBK - datastructure",{
744+
testthat::skip_on_cran()
745+
sdmx <- readSDMX(providerId = "BBK", resource = "datastructure", resourceId = "BBK_SEDI")
746+
if(!is.null(sdmx)){
747+
expect_is(sdmx, "SDMXDataStructureDefinition")
748+
}
749+
})
750+
751+
test_that("BBK - data",{
752+
testthat::skip_on_cran()
753+
sdmx <- readSDMX(providerId = "BBK", resource = "data", flowRef = "BBSIS", key = "D.I.ZST.B0.EUR.S1311.B.A604._Z.R.A.A._Z._Z.A")
754+
if(!is.null(sdmx)){
755+
expect_is(sdmx, "SDMXGenericData")
756+
}
757+
})
758+
759+
732760
#other data providers
733761

734762
#KNOEMA

0 commit comments

Comments
 (0)