Skip to content

Commit a88cc63

Browse files
committed
add support for cert download from ResearchEquals
closes codecheckers/register#162
1 parent 36b7d0a commit a88cc63

File tree

7 files changed

+87
-7
lines changed

7 files changed

+87
-7
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: codecheck
22
Title: Helper Functions for CODECHECK Project
3-
Version: 0.16.0
3+
Version: 0.17.0
44
Authors@R:
55
c(person(given = "Stephen",
66
family = "Eglen",

R/utils_download_certs.R

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ download_cert_pdf <- function(report_link, cert_id){
5252
}
5353
}
5454

55-
#' Retrieves the download link for a certificate file from either Zenodo or OSF.
55+
#' Retrieves the download link for a certificate file from Zenodo, OSF, or ResearchEquals.
5656
#'
57-
#' @param report_link URL of the report to access, either from Zenodo or OSF.
57+
#' @param report_link URL of the report to access, either from Zenodo, OSF, or ResearchEquals.
5858
#' @param cert_id ID of the certificate, used for logging and warnings.
5959
#'
6060
#' @return The download link for the certificate file as a string if found; otherwise, NULL.
@@ -67,6 +67,11 @@ get_cert_link <- function(report_link, cert_id){
6767
else if (grepl("OSF", report_link, ignore.case = TRUE)) {
6868
cert_download_url <- get_osf_cert_link(report_link, cert_id)
6969
}
70+
71+
# use issuer prefix for LibSci, see https://web.archive.org/web/20250504015818/https://www.libscie.org/blog/working-openly-1/minting-dois-for-research-modules-147/
72+
else if (grepl("10.53962", report_link, ignore.case = TRUE)) {
73+
cert_download_url <- get_researchequals_cert_link(report_link, cert_id)
74+
}
7075

7176
else(
7277
return(NULL)
@@ -216,6 +221,30 @@ get_zenodo_cert_link <- function(report_link, cert_id, api_key = "") {
216221
}
217222

218223

224+
#' Accesses a codecheck's ResearchEquals record via its report link and download the main file of the module
225+
#'
226+
#' @param report_link URL of the ResearchEquals report to access.
227+
#' @param cert_id ID of the certificate, used for logging and warnings.
228+
#'
229+
#' @importFrom httr GET status_code content
230+
#' @importFrom jsonlite fromJSON
231+
#'
232+
#' @return The download link for the certificate file as a string if found; otherwise, NULL.
233+
get_researchequals_cert_link <- function(report_link, cert_id) {
234+
# Download link example: https://www.researchequals.com/api/modules/main/wxh7-8yjd
235+
# Let's guess the ID from the report_link
236+
237+
# Checking for redirects and retrieving the record_id from there
238+
response <- httr::GET(report_link)
239+
final_url <- response$url
240+
record_id <- basename(final_url)
241+
242+
# Set the base URL for the ResearchEquals API
243+
record_url <- paste0(CONFIG$CERT_LINKS[["researchequals_api"]], record_id)
244+
245+
return (record_url)
246+
}
247+
219248

220249
#' Downloads a ZIP file from the given URL, searches for "codecheck.pdf" within its contents,
221250
#' renames it to "cert.pdf," and saves it in the specified directory.

inst/extdata/config.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ CONFIG$CERT_LINKS <- list(
196196
osf_api = "https://api.osf.io/v2/",
197197
zenodo_api = "https://zenodo.org/api/records/",
198198
crossref_api = "https://api.crossref.org/works/",
199-
openalex_api = "https://api.openalex.org/works/"
199+
openalex_api = "https://api.openalex.org/works/",
200+
researchequals_api = "https://www.researchequals.com/api/modules/main/"
200201
)
201202

202203
CONFIG$CERTS_URL_PREFIX <- "https://doi.org/"

inst/tinytest/test_cert_download.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
tinytest::using(ttdo)
2+
3+
source(system.file("extdata", "config.R", package = "codecheck"))
4+
5+
tmp <- tempdir()
6+
CONFIG$CERTS_DIR[["cert"]] <- tmp
7+
8+
expect_silent({ result <- codecheck:::download_cert_pdf("https://doi.org/10.17605/osf.io/CSB7R", "9999-000") })
9+
expect_equal(result, 1)
10+
expect_true(file.exists(file.path(tmp, "9999-000", "cert.pdf")))
11+
expect_true(file.size(file.path(tmp, "9999-000", "cert.pdf")) > 300000)
12+
13+
expect_silent({ result <- codecheck:::download_cert_pdf("https://doi.org/10.5281/zenodo.15630442", "9999-001") })
14+
expect_equal(result, 1)
15+
expect_true(file.exists(file.path(tmp, "9999-001", "cert.pdf")))
16+
expect_true( file.size(file.path(tmp, "9999-001", "cert.pdf")) > 500000)
17+
18+
expect_silent({ result <- codecheck:::download_cert_pdf("https://doi.org/10.53962/wgtb-cagt", "9999-002") })
19+
expect_equal(result, 1)
20+
expect_true(file.exists(file.path(tmp, "9999-002", "cert.pdf")))
21+
expect_true( file.size(file.path(tmp, "9999-002", "cert.pdf")) > 200000)

inst/tinytest/test_cert_link.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
tinytest::using(ttdo)
2+
3+
source(system.file("extdata", "config.R", package = "codecheck"))
4+
5+
expect_equal(codecheck:::get_cert_link("https://doi.org/10.17605/osf.io/CSB7R", "999-010"),
6+
"https://osf.io/download/36nsb/")
7+
expect_equal(codecheck:::get_cert_link("https://doi.org/10.5281/zenodo.15630442", "999-020"),
8+
"https://zenodo.org/api/records/15630442/files/CODECHECK_report_FBM.pdf/content")
9+
expect_equal(codecheck:::get_cert_link("https://doi.org/10.53962/wgtb-cagt", "999-030"),
10+
"https://www.researchequals.com/api/modules/main/wgtb-cagt")

man/get_cert_link.Rd

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

man/get_researchequals_cert_link.Rd

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

0 commit comments

Comments
 (0)