-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from worldbank/httr2_gc_2
fixes to httr2, new endpoints, nowcast, attempt 2
- Loading branch information
Showing
51 changed files
with
2,039 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#' Build request version 2 | ||
#' | ||
#' @param server character: Server. For WB internal use only | ||
#' @param api_version character: API version | ||
#' @param endpoint character: PIP API endpoint | ||
#' @param ... other parameters | ||
#' | ||
#' @return httr2 request | ||
#' | ||
build_request <- function(server, | ||
api_version, | ||
endpoint, | ||
...) { | ||
|
||
|
||
|
||
base_url <- select_base_url(server = server) | ||
params <- list(...) | ||
|
||
req <- httr2::request(base_url) |> | ||
httr2::req_url_path_append(api_version) |> | ||
httr2::req_url_path_append(endpoint) |> | ||
# .multi = "comma" works fine without applying fix_params | ||
httr2::req_url_query(!!!params, .multi = "comma") |> | ||
httr2::req_cache(tools::R_user_dir("pipr", which = "cache"), | ||
use_on_error = TRUE, | ||
debug = TRUE) |> | ||
httr2::req_user_agent(pipr_user_agent) |> | ||
httr2::req_error(body = parse_error_body) |> | ||
httr2::req_retry( | ||
is_transient = pip_is_transient, | ||
after = retry_after, | ||
max_seconds = 60 | ||
) | ||
|
||
|
||
return(req) | ||
|
||
} | ||
|
||
|
||
|
||
|
||
#' build_request, OLD version | ||
#' | ||
#' @param server character: Server. For WB internal use only | ||
#' @param api_version character: API version | ||
#' @param endpoint character: PIP API endpoint | ||
#' @param ... other parameters | ||
#' | ||
#' @return httr2 request | ||
#' | ||
build_request_old <- function(server, | ||
api_version, | ||
endpoint, | ||
...) { | ||
|
||
base_url <- select_base_url(server = server) | ||
|
||
params <- list(...) | ||
params <- lapply(params, fix_params) | ||
|
||
req <- httr2::request(base_url) |> | ||
httr2::req_url_path_append(api_version) |> | ||
httr2::req_url_path_append(endpoint) |> | ||
httr2::req_url_query(!!!params) |> | ||
httr2::req_cache(tools::R_user_dir("pipr", which = "cache"), | ||
use_on_error = TRUE, | ||
debug = TRUE) |> | ||
httr2::req_user_agent(pipr_user_agent) |> | ||
httr2::req_error(body = parse_error_body) |> | ||
httr2::req_retry( | ||
is_transient = pip_is_transient, | ||
after = retry_after, | ||
max_seconds = 60 | ||
) | ||
|
||
return(req) | ||
|
||
} | ||
|
||
fix_params <- function(param) { | ||
if (length(param) > 1) { | ||
return(paste(param, collapse = ",")) | ||
} else { | ||
return(param) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#' Datt (1998) grouped data for rural india, 1983 | ||
#' | ||
#' Dataset from Datt (1998) with grouped data for rural India in 1983. | ||
#' | ||
#' @format A data frame with 13 observations on the following 6 variables: | ||
#' \describe{ | ||
#' \item{monthly_pc_exp}{Welfare range class} | ||
#' \item{mean_monthly_pc_exp}{Mean welfare for given welfare range class} | ||
#' \item{percentage_of_persons}{Percentage of individuals in given welfare class} | ||
#' \item{L}{Cumulative welfare} | ||
#' \item{p}{Cumulative population} | ||
#' \item{area}{rural} | ||
#' } | ||
#' | ||
#' @source Datt, G. (1998). See get_cp vignette. | ||
#' | ||
"datt_rural" | ||
|
||
#' Grouped data for urban india, 1983 | ||
#' | ||
#' Dataset from Sarvekshana N26 Vol 9 N 4, created by the author following | ||
#' Datt(1998) methodology with grouped data for urban India in 1983. | ||
#' | ||
#' @format A data frame with 13 observations on the following 6 variables: | ||
#' \describe{ | ||
#' \item{monthly_pc_exp}{Welfare range class} | ||
#' \item{mean_monthly_pc_exp}{Mean welfare for given welfare range class} | ||
#' \item{percentage_of_persons}{Percentage of individuals in given welfare class} | ||
#' \item{L}{Cumulative welfare} | ||
#' \item{p}{Cumulative population} | ||
#' \item{area}{urban} | ||
#' } | ||
#' | ||
#' @source Sarvekshana N26 Vol 9 N 4, and Datt, G. (1998) for methodology. See get_cp vignette. | ||
#' | ||
"datt_urban" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.