Skip to content

Commit

Permalink
Merge pull request #39 from worldbank/DEV
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
tonyfujs authored Sep 20, 2022
2 parents c8899c9 + 1d5f393 commit ff9b598
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 23 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: pipr
Title: Client for the PIP API
Version: 0.0.2
Version: 0.0.3
Authors@R:
c(person(given = "Tony",
family = "Fujs",
Expand Down Expand Up @@ -28,7 +28,7 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.1
URL: https://github.com/worldbank/pipr,
https://worldbank.github.io/pipr/
BugReports: https://github.com/worldbank/pipr/issues
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(check_api)
export(get_aux)
export(get_countries)
export(get_cpi)
Expand All @@ -18,4 +19,3 @@ export(get_stats)
export(get_survey_means)
export(get_versions)
export(get_wb)
export(health_check)
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# pipr 0.0.3

* [Add new ppp_version and release_version parameters](https://github.com/worldbank/pipr/pull/38)
* [Remove systematic check_api() call in get_stats()](https://github.com/worldbank/pipr/pull/38)

# pipr 0.0.2

## Bug fixes
Expand Down
12 changes: 6 additions & 6 deletions R/get_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#' @param welfare_type character: Welfare type either of c("all", "income", "consumption")
#' @param reporting_level character: Geographical reporting level either of c("all", "national", "urban", "rural")
#' @param version character: Data version. See `get_versions()`
#' @param ppp_version ppp year to be used
#' @param release_version date when the data was published in YYYYMMDD format
#' @param api_version character: API version
#' @param format character: Response format either of c("rds", "json", "csv")
#' @param simplify logical: If TRUE (the default) the response is returned as a
Expand Down Expand Up @@ -60,6 +62,8 @@ get_stats <- function(country = "all",
welfare_type = c("all", "income", "consumption"),
reporting_level = c("all", "national", "urban", "rural"),
version = NULL,
ppp_version = NULL,
release_version = NULL,
api_version = "v1",
format = c("rds", "json", "csv"),
simplify = TRUE,
Expand All @@ -69,7 +73,6 @@ get_stats <- function(country = "all",
reporting_level <- match.arg(reporting_level)
api_version <- match.arg(api_version)
format <- match.arg(format)

# popshare can't be used together with povline
if (!is.null(popshare)) povline <- NULL

Expand All @@ -87,10 +90,6 @@ get_stats <- function(country = "all",
group_by <- NULL
}

# Check connection
check_internet()
check_api(api_version, server)

# Build query string
args <- build_args(
country = country,
Expand All @@ -102,10 +101,11 @@ get_stats <- function(country = "all",
welfare_type = welfare_type,
reporting_level = reporting_level,
version = version,
ppp_version = ppp_version,
release_version = release_version,
format = format
)
u <- build_url(server, endpoint, api_version)

# Send query
res <- httr::GET(u, query = args, httr::user_agent(pipr_user_agent))

Expand Down
8 changes: 4 additions & 4 deletions R/other.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#' Check API status
#' Check internet connection and API status
#' @inheritParams get_stats
#' @return character
#' @export
#' @examples
#' \dontrun{
#' health_check()
#' check_api()
#' }
health_check <- function(api_version = "v1", server = NULL) {
check_api <- function(api_version = "v1", server = NULL) {
check_internet()
res <- check_api(api_version, server = server)
res <- health_check(api_version, server = server)
parse_response(res, simplify = FALSE)$content
}

Expand Down
11 changes: 7 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ check_internet <- function() {
invisible(TRUE)
}

#' check_api
#' @inheritParams get_stats
#' health_check
#' @inheritParams check_api
#' @noRd
check_api <- function(api_version, server = NULL) {
health_check <- function(api_version, server = NULL) {
u <- build_url(server, "health-check", api_version)
res <- httr::GET(u)
attempt::stop_if_not(
Expand Down Expand Up @@ -70,6 +70,8 @@ build_args <- function(country = NULL,
reporting_level = NULL,
table = NULL,
version = NULL,
ppp_version = ppp_version,
release_version = release_version,
format = NULL) {

# Collapse to a single string
Expand All @@ -82,7 +84,8 @@ build_args <- function(country = NULL,
welfare_type = welfare_type,
reporting_level = reporting_level,
group_by = group_by, table = table,
version = version, format = format
version = version, ppp_version = ppp_version,
release_version = release_version,format = format
)
attempt::stop_if_all(args, is.null, "You need to specify at least one argument")

Expand Down
12 changes: 6 additions & 6 deletions man/health_check.Rd → man/check_api.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions man/get_stats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ff9b598

Please sign in to comment.