Skip to content

Commit 1a8688b

Browse files
committed
Add pxweb_table_response_v2
1 parent 72cc870 commit 1a8688b

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed

R/pxweb_table_response_v2.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#' Construct a \code{table_response_v2} object.
2+
#'
3+
#' @description
4+
#' An object that contain the data for a given PXWEB TableResponse (API v2).
5+
#'
6+
#' @param x a list returned from a PXWEB API to convert to a \code{table_response_v2} object.
7+
#'
8+
#' @return
9+
#' a \code{pxweb_table_v2} object.
10+
#'
11+
#' @keywords internal
12+
pxweb_table_response_v2 <- function(x) {
13+
checkmate::assert_class(x, "list")
14+
assert_pxweb_table_response_v2(x)
15+
class(x) <- c("pxweb_table_response_v2", "list")
16+
x
17+
}
18+
19+
#' Assert that x is a correct \code{pxweb_data_jsonstat} object.
20+
#' Assert a json-stat version 1.0 or later object
21+
#' @param x an object to check.
22+
#' @keywords internal
23+
assert_pxweb_table_response_v2 <- function(x) {
24+
checkmate::assert_class(x, c("list"))
25+
checkmate::assert_names(names(x), must.include = c("language", "id", "label", "updated", "firstPeriod", "lastPeriod", "variableNames", "links"))
26+
}
27+

man/assert_pxweb_table_response_v2.Rd

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/pxweb_table_response_v2.Rd

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
test_that(desc = "pxweb API v2", {
3+
# Keep same style as existing live API tests.
4+
skip_on_cran()
5+
skip_if_offline()
6+
7+
r <- readRDS(test_path("test_data/pxweb_table_response_v2.rds"))
8+
x <- suppressWarnings(httr::content(r, as = "parsed"))
9+
expect_silent(x <- pxweb_table_response_v2(x))
10+
expect_s3_class(x, "pxweb_table_response_v2")
11+
12+
# pxapi_v2 <- pxweb_get(url = "https://statistikdatabasen.scb.se/api/v2/tables/TAB5974/")
13+
})
14+
15+
16+
1.33 KB
Binary file not shown.

0 commit comments

Comments
 (0)