@@ -54,7 +54,9 @@ construct_api_requests <- function(service,
5454 " computation_identifier" )
5555
5656 if (service %in% c(" monitoring-locations" , " parameter-codes" ,
57- " time-series-metadata" )){
57+ " time-series-metadata" ,
58+ " field-measurements-metadata" ,
59+ " combined-metadata" )){
5860 comma_params <- c(comma_params , " id" )
5961 }
6062
@@ -138,14 +140,19 @@ construct_api_requests <- function(service,
138140 baseURL <- baseURL | >
139141 httr2 :: req_headers(`Content-Type` = " application/query-cql-json" )
140142
141- post_params <- list (
142- " params" = unname(post_params )
143- )
144-
145- template_path_post <- system.file(" templates/post.CQL2" , package = " dataRetrieval" )
146- template_post <- readChar(template_path_post , file.info(template_path_post )$ size )
143+ if (length(post_params ) > 1 ){
144+ post_params <- list (
145+ " params" = unname(post_params )
146+ )
147+
148+ template_path_post <- system.file(" templates/post.CQL2" , package = " dataRetrieval" )
149+ template_post <- readChar(template_path_post , file.info(template_path_post )$ size )
150+
151+ x <- whisker :: whisker.render(template_post , post_params )
152+ } else {
153+ x <- post_params [[1 ]]
154+ }
147155
148- x <- whisker :: whisker.render(template_post , post_params )
149156 baseURL <- httr2 :: req_body_raw(baseURL , x )
150157
151158 } else {
@@ -442,14 +449,39 @@ explode_post <- function(ls){
442449# ' dataRetrieval:::cql2_param(parameter)
443450# '
444451cql2_param <- function (parameter ){
445- template_path <- system.file(" templates/param.CQL2" , package = " dataRetrieval" )
446- template <- readChar(template_path , file.info(template_path )$ size )
447-
448- parameters <- paste0(unlist(parameter ), collapse = ' ", "' )
449- parameters <- paste0(' "' , parameters , ' "' )
450- parameter_list <- list (" property" = names(parameter ),
451- " parameter" = parameters )
452- return (whisker :: whisker.render(template , parameter_list ))
452+
453+ # Wildcards:
454+ if (names(parameter ) %in% c(" hydrologic_unit_code" )){
455+ template_path <- system.file(" templates/param.CQL2.like" , package = " dataRetrieval" )
456+ template <- readChar(template_path , file.info(template_path )$ size )
457+
458+ params <- c()
459+ for (i in parameter [[1 ]]){
460+ parameter_list <- list (" property" = names(parameter ),
461+ " parameter" = i )
462+ params <- c(params ,
463+ whisker :: whisker.render(template , parameter_list ))
464+ }
465+ template_path_or <- system.file(" templates/post.CQL2.or" , package = " dataRetrieval" )
466+ template_or <- readChar(template_path_or , file.info(template_path_or )$ size )
467+
468+ post_params <- list (
469+ " params" = paste0(params , collapse = " , " )
470+ )
471+ cql_text <- whisker :: whisker.render(template_or , post_params )
472+ } else { # INs
473+ parameters <- paste0(unlist(parameter ), collapse = ' ", "' )
474+ parameters <- paste0(' "' , parameters , ' "' )
475+ parameter_list <- list (" property" = names(parameter ),
476+ " parameter" = parameters )
477+
478+ template_path <- system.file(" templates/param.CQL2" , package = " dataRetrieval" )
479+ template <- readChar(template_path , file.info(template_path )$ size )
480+
481+ cql_text <- whisker :: whisker.render(template , parameter_list )
482+ }
483+
484+ return (cql_text )
453485}
454486
455487
0 commit comments