132 |
132 |
|
return(x) |
133 |
133 |
|
} |
134 |
134 |
|
|
|
135 |
+ |
|
|
136 |
+ |
#' Convert a parameter name to a different format |
|
137 |
+ |
#' |
|
138 |
+ |
#' The names of the parameters that are used in the R functions do not perfectly correspond with the parameter name expected by the API. This |
|
139 |
+ |
#' function converts an argument parameter name (e.g. `settlement_date`) to the URL argument name (e.g. `SettlementDate`) or the other way around |
|
140 |
+ |
#' @param parameter character; name of the parameter provided to the relevant `build()` function |
|
141 |
+ |
#' @param from character; one of "argument" or "url" depending on whether `parameter` is in the argument or URL format |
|
142 |
+ |
#' @param to character; one of "argument" or "url" |
|
143 |
+ |
#' @return character; name of the parameter used in the URL request or `build()` function. If no match is found, `character(0)` |
|
144 |
+ |
#' @export |
|
145 |
+ |
change_parameter_name <- function(parameter, from = c("argument", "url"), to = c("url", "argument")) { |
|
146 |
+ |
from <- match.arg(from) |
|
147 |
+ |
to <- match.arg(to) |
|
148 |
+ |
from_col <- rlang::sym(paste0(from, "_name")) |
|
149 |
+ |
to_col <- rlang::sym(paste0(to, "_name")) |
|
150 |
+ |
results <- dplyr::filter(parameter_name_map, {{ from_col }} == parameter) |
|
151 |
+ |
dplyr::pull(results, {{ to_col }}) |
|
152 |
+ |
} |
|
153 |
+ |
|
|
154 |
+ |
#' Get the cleaning function required for a parameter |
|
155 |
+ |
#' |
|
156 |
+ |
#' Before a parameter can be added to a request, it often needs to be cleaned. This function returns the appropriate function for a parameter. |
|
157 |
+ |
#' Parameters can be supplied with their name used in the `build()` functions ("argument") or in the URL |
|
158 |
+ |
#' @param character; name of the parameter. Either the parameter as it's passed to the `build()` functions or the name of the parameter in the URL |
|
159 |
+ |
#' depending on the value of `format` |
|
160 |
+ |
#' @param format character; what format is `parameter` in? One of "argument" (default) or "url" |
|
161 |
+ |
#' @return character; name of the cleaning function |
|
162 |
+ |
#' @export |
|
163 |
+ |
get_cleaning_function <- function(parameter, format = c("argument", "url")) { |
|
164 |
+ |
format <- match.arg(format) |
|
165 |
+ |
if (format == "url") { |
|
166 |
+ |
parameter <- change_parameter_name(parameter, from = "url", to = "argument") |
|
167 |
+ |
} |
|
168 |
+ |
dplyr::filter(parameter_clean_functions_map, name == parameter)[["function"]] |
|
169 |
+ |
} |