From 75b4098a47aa956ff5988b73b68b96c90fbcb6d1 Mon Sep 17 00:00:00 2001 From: eblondel Date: Thu, 9 Jan 2025 21:23:56 +0100 Subject: [PATCH] #216 support formatter arg in SDMXREST20RequestBuilder,SDMXREST21RequestBuilder --- R/SDMXREST20RequestBuilder-methods.R | 21 ++++++++++++--------- R/SDMXREST21RequestBuilder-methods.R | 21 ++++++++++++--------- man/SDMXREST20RequestBuilder.Rd | 4 ++++ man/SDMXREST21RequestBuilder.Rd | 4 ++++ 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/R/SDMXREST20RequestBuilder-methods.R b/R/SDMXREST20RequestBuilder-methods.R index f59d84f..8beb1b1 100644 --- a/R/SDMXREST20RequestBuilder-methods.R +++ b/R/SDMXREST20RequestBuilder-methods.R @@ -13,6 +13,9 @@ #' service repository #' @param accessKey an object of class "character" indicating the name of request parameter for which #' an authentication or subscription user key/token has to be provided to perform requests +#' @param formatter an object of class "list" giving a formatting function (for each resource) that +#' takes an object of class "SDMXRequestParams" as single argument. Such parameter allows +#' to customize eventual params (e.g. specific data provider rules) #' @param compliant an object of class "logical" indicating if the web-service #' is compliant with the SDMX REST web-service specifications #' @param unsupportedResources an object of class "list" giving eventual unsupported @@ -34,20 +37,20 @@ #' repoUrl = "http://www.myorg/repository", compliant = FALSE) #' @export #' -SDMXREST20RequestBuilder <- function(regUrl, repoUrl, accessKey = NULL, compliant, +SDMXREST20RequestBuilder <- function(regUrl, repoUrl, accessKey = NULL, + formatter = NULL,compliant, unsupportedResources = list(), skipProviderId = FALSE, forceProviderId = FALSE, headers = list()){ #params formatter - formatter = list( - #dataflow - dataflow = function(obj){return(obj)}, - #datastructure - datastructure = function(obj){ return(obj)}, - #data - data = function(obj){return(obj)} - ) + if(is.null(formatter)) formatter = list() + #dataflow + if(is.null(formatter$dataflow)) formatter$dataflow = function(obj){return(obj)} + #datastructure + if(is.null(formatter$datastructure)) formatter$datastructure = function(obj){ return(obj)} + #data + if(is.null(formatter$data)) formatter$data = function(obj){return(obj)} #resource handler handler <- list( diff --git a/R/SDMXREST21RequestBuilder-methods.R b/R/SDMXREST21RequestBuilder-methods.R index e575a00..f9dae7f 100644 --- a/R/SDMXREST21RequestBuilder-methods.R +++ b/R/SDMXREST21RequestBuilder-methods.R @@ -13,6 +13,9 @@ #' service repository #' @param accessKey an object of class "character" indicating the name of request parameter for which #' an authentication or subscription user key/token has to be provided to perform requests +#' @param formatter an object of class "list" giving a formatting function (for each resource) that +#' takes an object of class "SDMXRequestParams" as single argument. Such parameter allows +#' to customize eventual params (e.g. specific data provider rules) #' @param compliant an object of class "logical" indicating if the web-service #' is compliant with the SDMX REST web-service specifications #' @param unsupportedResources an object of class "list" giving eventual unsupported @@ -35,20 +38,20 @@ #' compliant = TRUE) #' @export #' -SDMXREST21RequestBuilder <- function(regUrl, repoUrl, accessKey = NULL, compliant, +SDMXREST21RequestBuilder <- function(regUrl, repoUrl, accessKey = NULL, + formatter = NULL, compliant, unsupportedResources = list(), skipProviderId = FALSE, forceProviderId = FALSE, headers = list()){ #params formatter - formatter = list( - #dataflow - dataflow = function(obj){return(obj)}, - #datastructure - datastructure = function(obj){ return(obj)}, - #data - data = function(obj){return(obj)} - ) + if(is.null(formatter)) formatter = list() + #dataflow + if(is.null(formatter$dataflow)) formatter$dataflow = function(obj){return(obj)} + #datastructure + if(is.null(formatter$datastructure)) formatter$datastructure = function(obj){ return(obj)} + #data + if(is.null(formatter$data)) formatter$data = function(obj){return(obj)} #resource handler handler <- list( diff --git a/man/SDMXREST20RequestBuilder.Rd b/man/SDMXREST20RequestBuilder.Rd index f09f22a..ef91362 100644 --- a/man/SDMXREST20RequestBuilder.Rd +++ b/man/SDMXREST20RequestBuilder.Rd @@ -22,6 +22,10 @@ service repository} \item{accessKey}{an object of class "character" indicating the name of request parameter for which an authentication or subscription user key/token has to be provided to perform requests} +\item{formatter}{an object of class "list" giving a formatting function (for each resource) that +takes an object of class "SDMXRequestParams" as single argument. Such parameter allows +to customize eventual params (e.g. specific data provider rules)} + \item{compliant}{an object of class "logical" indicating if the web-service is compliant with the SDMX REST web-service specifications} diff --git a/man/SDMXREST21RequestBuilder.Rd b/man/SDMXREST21RequestBuilder.Rd index 0397440..9775893 100644 --- a/man/SDMXREST21RequestBuilder.Rd +++ b/man/SDMXREST21RequestBuilder.Rd @@ -22,6 +22,10 @@ service repository} \item{accessKey}{an object of class "character" indicating the name of request parameter for which an authentication or subscription user key/token has to be provided to perform requests} +\item{formatter}{an object of class "list" giving a formatting function (for each resource) that +takes an object of class "SDMXRequestParams" as single argument. Such parameter allows +to customize eventual params (e.g. specific data provider rules)} + \item{compliant}{an object of class "logical" indicating if the web-service is compliant with the SDMX REST web-service specifications}