@@ -45,31 +45,41 @@ construct_api_requests <- function(service,
4545
4646 POST <- FALSE
4747
48- single_params <- c(" datetime" , " last_modified" , " begin" , " end" , " time" , " limit" )
48+ single_params <- c(" datetime" , " last_modified" ,
49+ " begin" , " end" , " time" , " limit" ,
50+ " begin_utc" , " end_utc" )
51+ comma_params <- c(" monitoring_location_id" , " parameter_code" ,
52+ " statistic_id" , " time_series_id" ,
53+ " computation_period_identifier" ,
54+ " computation_identifier" )
55+
56+ if (service %in% c(" monitoring-locations" , # "parameter-codes",
57+ " time-series-metadata" )){
58+ comma_params <- c(comma_params , " id" )
59+ }
4960
5061 full_list <- list (... )
5162
5263 if (all(is.na(full_list )) & all(is.na(bbox ))){
5364 warning(" No filtering arguments specified." )
5465 }
55-
56- # GET list refers to arguments that will go in the URL no matter what (not POST)
57- get_list <- full_list [names(full_list ) %in% single_params ]
66+ # Figure out if the GET request will be > 2048 characters
67+ comma_params_filtered <- Filter(Negate(anyNA ), full_list [comma_params ])
5868
59- get_list [[" skipGeometry" ]] <- skipGeometry
60-
61- # POST list are the arguments that need to be in the POST body
62- post_list <- full_list [! names(full_list ) %in% single_params ]
63-
64- post_params <- explode_post(post_list )
69+ force_post <- nchar(paste0(unlist(comma_params_filtered ), collapse = " ," )) > 2048
6570
66- if (length(post_params ) > 0 ){
67- POST = TRUE
71+ if (force_post ){
72+ get_list <- full_list [names(full_list ) %in% c(single_params )]
73+ } else {
74+ # GET list refers to arguments that will go in the URL no matter what (not POST)
75+ get_list <- full_list [names(full_list ) %in% c(single_params , comma_params )]
6876 }
77+
78+ get_list [[" skipGeometry" ]] <- skipGeometry
6979
7080 get_list <- get_list [! is.na(get_list )]
7181
72- time_periods <- c(" last_modified" , " datetime" , " time" , " begin" , " end" )
82+ time_periods <- c(" last_modified" , " datetime" , " time" , " begin" , " end" , " begin_utc " , " end_utc " )
7383 if (any(time_periods %in% names(get_list ))){
7484
7585 for (i in time_periods [time_periods %in% names(get_list )]){
@@ -85,7 +95,7 @@ construct_api_requests <- function(service,
8595 format_type <- ifelse(isTRUE(no_paging ), " csv" , " json" )
8696
8797 baseURL <- setup_api(service , format = format_type )
88- baseURL <- explode_query(baseURL , POST = FALSE , get_list )
98+ baseURL <- explode_query(baseURL , POST = FALSE , get_list , multi = " comma " )
8999
90100 if (all(! is.na(bbox ))){
91101 baseURL <- httr2 :: req_url_query(baseURL ,
@@ -111,7 +121,15 @@ construct_api_requests <- function(service,
111121 .multi = " comma" )
112122 }
113123
114- if (POST ){
124+ # POST list are the arguments that need to be in the POST body
125+ post_list <- full_list [! names(full_list ) %in% names(get_list )]
126+
127+ post_params <- explode_post(post_list )
128+
129+ # Should we do a POST?
130+ POST = length(post_params ) > 0
131+
132+ if (POST ){
115133 baseURL <- baseURL | >
116134 httr2 :: req_headers(`Content-Type` = " application/query-cql-json" )
117135
@@ -126,7 +144,7 @@ construct_api_requests <- function(service,
126144 baseURL <- httr2 :: req_body_raw(baseURL , x )
127145
128146 } else {
129- baseURL <- explode_query(baseURL , POST = FALSE , full_list )
147+ baseURL <- explode_query(baseURL , POST = FALSE , full_list , multi = " comma " )
130148 }
131149
132150 return (baseURL )
0 commit comments