Skip to content

Commit

Permalink
fix bug in ct_register_token(), issue #21
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisMuir committed Jun 8, 2019
1 parent 8767c9f commit a91d20e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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")),
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
====================

Expand Down
6 changes: 4 additions & 2 deletions R/rate_limit.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit a91d20e

Please sign in to comment.