Skip to content

Commit

Permalink
Removal of revision_list and package_revision_list in CKAN 2.9 (#200)
Browse files Browse the repository at this point in the history
* revision_list and package_revision_list return NULL if CKAN version is greater than 2.9

* add definition of ver variable with ckan version
  • Loading branch information
fjuniorr authored Mar 14, 2023
1 parent c557c01 commit 6eb2a6d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 31 deletions.
16 changes: 14 additions & 2 deletions R/package_revision_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,19 @@
package_revision_list <- function(id, url = get_default_url(),
key = get_default_key(), as = "list", ...) {

res <- ckan_GET(url, 'package_revision_list', list(id = id),
ver <- try(ckan_version(url)$version_num, silent = TRUE)
if (inherits(ver, "try-error")) {
ver <- NA
}

if (ver >= 29.0) {
warning('The ckan.logic.action.get.package_revision_list endpoint was removed in CKAN 2.9. Returning NULL.')
result <- NULL
} else {
res <- ckan_GET(url, 'package_revision_list', list(id = id),
key = key, opts = list(...))
switch(as, json = res, list = jsl(res), table = jsd(res))
result <- switch(as, json = res, list = jsl(res), table = jsd(res))
}

result
}
15 changes: 13 additions & 2 deletions R/revision_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
revision_list <- function(url = get_default_url(), key = get_default_key(),
as = "list", ...) {

res <- ckan_GET(url, 'revision_list', key = key, opts = list(...))
switch(as, json = res, list = jsl(res), table = jsd(res))
ver <- try(ckan_version(url)$version_num, silent = TRUE)
if (inherits(ver, "try-error")) {
ver <- NA
}

if (ver >= 29.0) {
warning('The ckan.logic.action.get.revision_list endpoint was removed in CKAN 2.9. Returning NULL.')
result <- NULL
} else {
res <- ckan_GET(url, 'revision_list', key = key, opts = list(...))
result <- switch(as, json = res, list = jsl(res), table = jsd(res))
}
result
}
40 changes: 25 additions & 15 deletions tests/testthat/test-package_revision_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,30 @@ context("package_revision_list")
skip_on_cran()

u <- get_test_url()
ver <- try(ckan_version(u)$version_num, silent = TRUE)

test_that("package_revision_list gives back expected class types", {
check_ckan(u)
.a <- package_list_current(limit=1, url=u)
a <- package_revision_list(.a[[1]]$id, url=u)
expect_is(a, "list")
})
if (ver >= 29.0) {
test_that("removal of package_revision_list endpoint", {
check_ckan(u)
a <- expect_warning(package_revision_list(url=u), "The ckan.logic.action.get.package_revision_list endpoint was removed in CKAN 2.9. Returning NULL.")
expect_null(a)
})
} else {
test_that("package_revision_list gives back expected class types", {
check_ckan(u)
.a <- package_list_current(limit=1, url=u)
a <- package_revision_list(.a[[1]]$id, url=u)
expect_is(a, "list")
})

test_that("package_revision_list works giving back json output", {
check_ckan(u)
.b <- package_list_current(limit=1, url=u)
b <- package_revision_list(.b[[1]]$id, url=u, as="json")
b_df <- jsonlite::fromJSON(b)
expect_is(b, "character")
expect_is(b_df, "list")
expect_is(b_df$result, "data.frame")
})
}

test_that("package_revision_list works giving back json output", {
check_ckan(u)
.b <- package_list_current(limit=1, url=u)
b <- package_revision_list(.b[[1]]$id, url=u, as="json")
b_df <- jsonlite::fromJSON(b)
expect_is(b, "character")
expect_is(b_df, "list")
expect_is(b_df$result, "data.frame")
})
34 changes: 22 additions & 12 deletions tests/testthat/test-revision_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@ context("revision_list")
skip_on_cran()

u <- get_test_url()
ver <- try(ckan_version(u)$version_num, silent = TRUE)

test_that("revision_list gives back expected class types", {
check_ckan(u)
a <- revision_list(url=u)
expect_is(a, "list")
})
if(ver >= 29.0) {
test_that("removal of revision_list endpoint", {
check_ckan(u)
a <- expect_warning(revision_list(url=u), "The ckan.logic.action.get.revision_list endpoint was removed in CKAN 2.9. Returning NULL.")
expect_null(a)
})
} else {
test_that("revision_list gives back expected class types", {
check_ckan(u)
a <- revision_list(url=u)
expect_is(a, "list")
})

test_that("revision_list works giving back json output", {
check_ckan(u)
b <- revision_list(url=u, as="json")
expect_is(b, "character")
b_df <- jsonlite::fromJSON(b)
expect_is(b_df, "list")
})
}

test_that("revision_list works giving back json output", {
check_ckan(u)
b <- revision_list(url=u, as="json")
expect_is(b, "character")
b_df <- jsonlite::fromJSON(b)
expect_is(b_df, "list")
})

0 comments on commit 6eb2a6d

Please sign in to comment.