From a91d20e41f001f6052219f7e1a9a944add4f74bb Mon Sep 17 00:00:00 2001 From: ChrisMuir Date: Sat, 8 Jun 2019 19:09:59 -0400 Subject: [PATCH] fix bug in ct_register_token(), issue #21 --- DESCRIPTION | 2 +- NEWS.md | 8 ++++++++ R/rate_limit.R | 6 ++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 690d62a..15c2f97 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: comtradr Title: Interface with the United Nations Comtrade API -Version: 0.2.2 +Version: 0.2.2.09000 Authors@R: c(person("Chris", "Muir", email = "chrismuirRVA@gmail.com", role = c("aut", "cre")), diff --git a/NEWS.md b/NEWS.md index b109f0a..d445efb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,11 @@ +comtradr 0.2.2.09000 +==================== + +## BUG FIXES + +* Passing an API token string to `ct_register_token()` now properly bumps the hourly rate limit up to 10,000 +([#21](https://github.com/ropensci/comtradr/issues/21)). + comtradr 0.2.2 ==================== diff --git a/R/rate_limit.R b/R/rate_limit.R index d28664e..0093637 100644 --- a/R/rate_limit.R +++ b/R/rate_limit.R @@ -111,6 +111,9 @@ ct_register_token <- function(token) { return(invisible()) } + # Get the current account type. + curr_account_type <- getOption("comtradr")$comtrade$account_type + # Set token within options. ct_options <- getOption("comtradr") ct_options$comtrade$token <- token @@ -121,11 +124,10 @@ ct_register_token <- function(token) { # Change the hourly limit within the env ct_env. Subtract the number of # queries already performed this hour from the update value. - curr_account_type <- getOption("comtradr")$comtrade$account_type if (curr_account_type == "standard") { new_hr_limit <- 10000 - (100 - queries_this_hour) } else if (curr_account_type == "premium") { - new_hr_limit <- 10000 - (10000 - queries_this_hour) + new_hr_limit <- queries_this_hour } assign("queries_this_hour", new_hr_limit, envir = ct_env)