-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
59 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,42 +3,50 @@ | |
#' This is the main function to retrieve comprehensive open acccess status | ||
#' information from the oaDOI service. Please play nice with the API. At the | ||
#' moment only 10k request are allowed per user and day. | ||
#' For more info see \url{http://oadoi.org/api} | ||
#' For more info see \url{http://oadoi.org/api}. | ||
#' | ||
#' @param dois character vector, search by a single DOI or many DOIs. A maximum | ||
#' of 10,000 DOIs are allowed per request. | ||
#' @param email character verctor, tell oaDOI your email adress and get notified | ||
#' @param dois character vector, search by a single DOI or many DOIs. The API is limited | ||
#' to 10,000 requests per day. If you need more, get in touch with | ||
#' [email protected]. | ||
#' @param email character verctor, tell oaDOI your email adress to get notified | ||
#' if something breaks. It also helps oaDOI to keep track of usage! | ||
#' @param .progress Shows the \code{plyr}-style progress bar. Options are "none", "text", | ||
#' "tk", "win", and "time". See \code{\link[plyr]{create_progress_bar}} for details | ||
#' of each. By default, no progress bar is displayed. | ||
#' "tk", "win", and "time". See \code{\link[plyr]{create_progress_bar}} for details | ||
#' of each. By default, no progress bar is displayed. | ||
#' | ||
#' @return A tibble | ||
#' | ||
#' @examples \dontrun{ | ||
#' oadoi_fetch("10.1016/j.shpsc.2013.03.020") | ||
#' oadoi_fetch(dois = c("10.1016/j.jbiotec.2010.07.030", | ||
#' "10.1186/1471-2164-11-245")) | ||
#' } | ||
#' | ||
#' @export | ||
oadoi_fetch <- function(dois = NULL, email = NULL, .progress = "none") { | ||
# limit | ||
if (length(dois) > api_limit) | ||
stop("The rate limit is 10k requests per day. | ||
Get in touch with [email protected] to get an upgrade.", .call = FALSE) | ||
# validate dois | ||
dois <- plyr::ldply(dois, doi_validate) | ||
if (nrow(dois[dois$is_valid == FALSE,]) > 0) | ||
warning("Found mal-formed DOIs, which will not be send to oaDOI") | ||
dois <- dplyr::filter(dois, is_valid == TRUE) %>% | ||
.$doi %>% | ||
as.character() | ||
plyr::ldply(dois, oadoi_api_, .progress = .progress) %>% | ||
# wrap as tibble | ||
dplyr::as_data_frame() | ||
} | ||
oadoi_fetch <- | ||
function(dois = NULL, | ||
email = NULL, | ||
.progress = "none") { | ||
# limit | ||
if (length(dois) > api_limit) | ||
stop( | ||
"The rate limit is 10k requests per day. | ||
Get in touch with [email protected] to get an upgrade.", | ||
.call = FALSE | ||
) | ||
# validate dois | ||
dois <- plyr::ldply(dois, doi_validate) | ||
if (nrow(dois[dois$is_valid == FALSE, ]) > 0) | ||
warning("Found mal-formed DOIs, which will not be send to oaDOI") | ||
dois <- dplyr::filter(dois, is_valid == TRUE) %>% | ||
.$doi %>% | ||
as.character() | ||
plyr::ldply(dois, oadoi_api_, .progress = .progress) %>% | ||
# wrap as tibble | ||
dplyr::as_data_frame() | ||
} | ||
|
||
#' Post one DOI to access open access status information. | ||
#' Get open access status information. | ||
#' | ||
#' In general, use oadoi_fetch instead. It calls this method, returning open | ||
#' access status information from all your requests. | ||
|
@@ -53,17 +61,17 @@ oadoi_api_ <- function(dois = NULL, email = NULL) { | |
u <- httr::modify_url(oadoi_baseurl(), | ||
query = args_(email = email), | ||
path = dois) | ||
resp <- httr::GET( | ||
u, | ||
ua, | ||
# be explicit about the API version roadoi has to request | ||
add_headers( | ||
Accept = paste0("application/x.oadoi.", oadoi_api_version(), "+json"))) | ||
resp <- httr::GET(u, | ||
ua, | ||
# be explicit about the API version roadoi has to request | ||
add_headers( | ||
Accept = paste0("application/x.oadoi.", oadoi_api_version(), "+json") | ||
)) | ||
|
||
# parse json | ||
if (httr::http_type(resp) != "application/json") { | ||
stop("Ups, something went wrong, because API did not return json", | ||
call. = FALSE) | ||
} | ||
jsonlite::fromJSON(content(resp, "text", encoding = "UTF-8"))$results | ||
# parse json | ||
if (httr::http_type(resp) != "application/json") { | ||
stop("Ups, something went wrong, because API did not return json", | ||
call. = FALSE) | ||
} | ||
jsonlite::fromJSON(content(resp, "text", encoding = "UTF-8"))$results | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,14 +4,17 @@ test_that("oadoi_fetch returns", { | |
a <- oadoi_fetch(dois = "10.7717/peerj.2323") | ||
b <- oadoi_fetch(dois = c("10.1038/ng.919", "10.1105/tpc.111.088682"), | ||
email = "[email protected]") | ||
c <- oadoi_fetch("10.1016/j.shpsc.2013.03.020") | ||
|
||
# correct classes | ||
expect_is(a, "tbl_df") | ||
expect_is(b, "tbl_df") | ||
expect_is(c, "tbl_df") | ||
|
||
# correct dimensions | ||
expect_equal(nrow(a), 1) | ||
expect_equal(nrow(b), 2) | ||
expect_equal(nrow(c), 1) | ||
|
||
|
||
expect_warning(oadoi_fetch(dois = c("ldld", "10.1038/ng.3260"))) | ||
|