Skip to content

Commit

Permalink
Allow multiple parameter/country/city/location inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeLydeamore committed May 29, 2024
1 parent a12ecaa commit 3977413
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
13 changes: 11 additions & 2 deletions R/client.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@ get_measurements_for_location <- function(

attr(date_from, "tzone") <- "UTC"
attr(date_to, "tzone") <- "UTC"

country <- restify_vector(country)
city <- restify_vector(city)
location <- restify_vector(location)

additional_args <- list(...)
parsed_args <- lapply(seq_along(additional_args), function(i) {
restify_vector(input = additional_args[[i]], name = names(additional_args)[i])
})
names(parsed_args) <- names(additional_args)

query_params <- list(
country = country,
city = city,
Expand All @@ -46,8 +56,7 @@ get_measurements_for_location <- function(
limit = as.character(max_observations)
)

query_params <- modifyList(query_params, list(...))

query_params <- modifyList(query_params, parsed_args)
api_response <- run_query(
endpoint_name = "measurements",
query_params = query_params
Expand Down
8 changes: 8 additions & 0 deletions R/util.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
restify_vector <- function(input, name = NULL) {
if (is.null(name)) {
name <- deparse(substitute(input))
}
string <- paste0("&", name, "=")

paste0(input, collapse=string)
}
2 changes: 1 addition & 1 deletion example/example1.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ tb <- get_measures(qr)
unique(tb$parameter)
nrow(tb)

a <- get_measurements_for_location(country = "AU", city = "Melbourne", location = "Footscray", max_observations = 100, date_from = lubridate::ymd("2024-05-24"), parameter = "pm10")
a <- get_measurements_for_location(country = "AU", city = "Melbourne", location = "Footscray", max_observations = 100, date_from = lubridate::ymd("2024-05-24"), parameter = c("pm10", "pm25"))

0 comments on commit 3977413

Please sign in to comment.