Skip to content

Commit

Permalink
Merge pull request #35 from USEPA/34-api-key-check-helper-function
Browse files Browse the repository at this point in the history
34 api key check helper function
  • Loading branch information
rachmaninoffpk authored Nov 21, 2024
2 parents 3d57d54 + 33f1207 commit cfac9c6
Show file tree
Hide file tree
Showing 81 changed files with 5,967 additions and 6,209 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}


- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected]
Expand Down
33 changes: 12 additions & 21 deletions R/bioactivity-APIs-batch.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ get_bioactivity_details_batch <- function(DTXSID = NULL,
Server = NULL,
rate_limit = 0L,
verbose = FALSE){
if (is.null(API_key) || !is.character(API_key)){
if (has_ctx_key()) {
API_key <- ctx_key()
if (verbose) {
message('Using stored API key!')
}
}
API_key <- check_api_key(API_key = API_key, verbose = verbose)
if (is.null(API_key) & verbose){
warning('Missing API key. Please supply during function call or save using `register_ctx_api_key()`!')
}

if (!is.numeric(rate_limit) | (rate_limit < 0)){
warning('Setting rate limit to 0 seconds between requests!')
rate_limit <- 0L
Expand Down Expand Up @@ -218,14 +215,11 @@ get_bioactivity_summary_batch <- function(AEID = NULL,
Server = NULL,
rate_limit = 0L,
verbose = FALSE){
if (is.null(API_key) || !is.character(API_key)){
if (has_ctx_key()) {
API_key <- ctx_key()
if (verbose) {
message('Using stored API key!')
}
}
API_key <- check_api_key(API_key = API_key, verbose = verbose)
if (is.null(API_key) & verbose){
warning('Missing API key. Please supply during function call or save using `register_ctx_api_key()`!')
}

if (!is.numeric(rate_limit) | (rate_limit < 0)){
warning('Setting rate limit to 0 seconds between requests!')
rate_limit <- 0L
Expand Down Expand Up @@ -296,14 +290,11 @@ get_annotation_by_aeid_batch <- function(AEID = NULL,
Server = NULL,
rate_limit = 0L,
verbose = FALSE){
if (is.null(API_key) || !is.character(API_key)){
if (has_ctx_key()) {
API_key <- ctx_key()
if (verbose) {
message('Using stored API key!')
}
}
API_key <- check_api_key(API_key = API_key, verbose = verbose)
if (is.null(API_key) & verbose){
warning('Missing API key. Please supply during function call or save using `register_ctx_api_key()`!')
}

if (!is.numeric(rate_limit) | (rate_limit < 0)){
warning('Setting rate limit to 0 seconds between requests!')
rate_limit <- 0L
Expand Down
43 changes: 15 additions & 28 deletions R/bioactivity-APIs.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ get_bioactivity_details <- function(DTXSID = NULL,
#else if (!is.null(DTXSID) & !is.null(AEID))
else if (length(which(!sapply(list(DTXSID, AEID, SPID, m4id), is.null))) > 1)
stop('Please input a value for only one of DTXSID, AEID, SPID, or m4id, but not multiple!')
else if (is.null(API_key)){
if (has_ctx_key()) {
API_key <- ctx_key()
if (verbose) {
message('Using stored API key!')
}
}

API_key <- check_api_key(API_key = API_key, verbose = verbose)
if (is.null(API_key) & verbose){
warning('Missing API key. Please supply during function call or save using `register_ctx_api_key()`!')
}

data_index <- which(!sapply(list(DTXSID, AEID, SPID, m4id), is.null))
Expand Down Expand Up @@ -140,13 +137,10 @@ get_bioactivity_summary <- function(AEID = NULL,
#return()
if (is.null(AEID))
stop('Please input an AEID!')
else if (is.null(API_key)){
if (has_ctx_key()){
API_key <- ctx_key()
if (verbose) {
message('Using stored API key!')
}
}

API_key <- check_api_key(API_key = API_key, verbose = verbose)
if (is.null(API_key) & verbose){
warning('Missing API key. Please supply during function call or save using `register_ctx_api_key()`!')
}

response <- httr::GET(url = paste0(Server, '/data/summary/search/by-aeid/', AEID),
Expand Down Expand Up @@ -203,13 +197,9 @@ get_all_assays <- function(API_key = NULL,
Server = bioactivity_api_server,
verbose = FALSE){

if (is.null(API_key)){
if (has_ctx_key()){
API_key <- ctx_key()
if (verbose) {
message('Using stored API key!')
}
}
API_key <- check_api_key(API_key = API_key, verbose = verbose)
if (is.null(API_key) & verbose){
warning('Missing API key. Please supply during function call or save using `register_ctx_api_key()`!')
}

response <- httr::GET(url = paste0(Server, '/assay/'),
Expand Down Expand Up @@ -255,13 +245,10 @@ get_annotation_by_aeid <- function(AEID = NULL,
verbose = FALSE){
if (is.null(AEID))
stop('Please input an AEID!')
else if (is.null(API_key)){
if (has_ctx_key()){
API_key <- ctx_key()
if (verbose) {
message('Using stored API key!')
}
}

API_key <- check_api_key(API_key = API_key, verbose = verbose)
if (is.null(API_key) & verbose){
warning('Missing API key. Please supply during function call or save using `register_ctx_api_key()`!')
}

response <- httr::GET(url = paste0(Server, '/assay/search/by-aeid/', AEID),
Expand Down
Loading

0 comments on commit cfac9c6

Please sign in to comment.