Skip to content

Commit

Permalink
styler corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
datapumpernickel committed Dec 22, 2023
1 parent b353e63 commit 7916019
Show file tree
Hide file tree
Showing 18 changed files with 532 additions and 437 deletions.
44 changes: 23 additions & 21 deletions R/ct_build_request.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@
#'
#' @examplesIf interactive()
#' # Build request from checked parameters
#' comtradr:::ct_build_request(comtradr:::ct_check_params(type = 'goods',
#' frequency = 'A',
#' commodity_classification = 'HS',
#' commodity_code = 'TOTAL',
#' flow_direction = 'all',
#' reporter = 'all',
#' partner = 'World',
#' start_date = 2020,
#' end_date = 2022,
#' process = TRUE,
#' tidy_cols = TRUE,
#' verbose = FALSE,
#' primary_token = 'xxxx',
#' mode_of_transport = '0',
#' partner_2 = 'World',
#' customs_code ='C00',
#' update = FALSE ))
#' comtradr:::ct_build_request(comtradr:::ct_check_params(
#' type = "goods",
#' frequency = "A",
#' commodity_classification = "HS",
#' commodity_code = "TOTAL",
#' flow_direction = "all",
#' reporter = "all",
#' partner = "World",
#' start_date = 2020,
#' end_date = 2022,
#' process = TRUE,
#' tidy_cols = TRUE,
#' verbose = FALSE,
#' primary_token = "xxxx",
#' mode_of_transport = "0",
#' partner_2 = "World",
#' customs_code = "C00",
#' update = FALSE
#' ))
#'
#' @returns a httr2 request object
#' @inheritParams ct_get_data
ct_build_request <- function(params,
primary_token = NULL,
verbose = FALSE) {
primary_token = NULL,
verbose = FALSE) {
query_params <- params$query_params

extra_params <- params$extra_params |>
Expand All @@ -52,12 +54,12 @@ ct_build_request <- function(params,
httr2::req_headers(`Ocp-Apim-Subscription-Key` = primary_token) |>
httr2::req_url_query(!!!query_params)

if(stringr::str_length(res$url)>4095){
if (stringr::str_length(res$url) > 4095) {
rlang::abort("Your request exceeds 4KB or 4096 characters, which is the upper limit of the Comtrade API.") # nolint
}

if (verbose) {
cli::cli_inform(c("i" = paste0("URL that will be queried: ",res$url)))
cli::cli_inform(c("i" = paste0("URL that will be queried: ", res$url)))
}

return(res)
Expand Down
Loading

0 comments on commit 7916019

Please sign in to comment.