mkearney / tweetbotornot2
Showing 1 of 3 files from the diff.
Other files ignored by Codecov
.Rbuildignore has changed.
.gitignore has changed.

@@ -4,20 +4,34 @@
Loading
4 4
  xgboost::xgb.Booster.complete(tweetbotornot_xgb_model)
5 5
}
6 6
7 -
get_secret <- function(x) {
7 +
get_secret <- function(x, ...) {
8 +
  stopifnot(
9 +
    is.character(x),
10 +
    length(x) == 1L
11 +
  )
8 12
  if ((key <- Sys.getenv(x)) != "") {
9 13
    return(key)
10 14
  }
11 -
  if (grepl("(TOKEN|KEY)$", x)) {
12 -
    x <- paste0(sub("_(KEY|PAT|TOKEN|SECRET)$", "", x), c("", "_KEY", "_PAT", "_TOKEN"))
13 -
  } else {
14 -
    x <- paste0(sub("_(KEY|PAT|TOKEN|SECRET)$", "", x), c("", "_KEY", "_PAT", "_SECRET"))
15 +
  e <- Sys.getenv()
16 +
  x <- grep(x, names(e), ..., value = TRUE)
17 +
  if (length(x) == 0) {
18 +
    return("")
19 +
  }
20 +
  if (length(x) > 1L) {
21 +
    warning("Found multiple environment variables")
22 +
    x <- x[1]
23 +
  }
24 +
  Sys.getenv(x)
25 +
}
26 +
27 +
check_token_or_create_from_access_keys <- function(token = NULL) {
28 +
  if (!is.null(token)) {
29 +
    return(token)
15 30
  }
16 -
  x <- Sys.getenv(x)
17 -
  if (any(x != "")) {
18 -
    return(x[x != ""][1])
31 +
  if (eval(parse(text = 'exists("twitter_tokens", envir = rtweet:::.state)'))) {
32 +
    return(token)
19 33
  }
20 -
  ""
34 +
  create_token_from_secrets()
21 35
}
22 36
23 37
create_token_from_secrets <- function() {
@@ -25,8 +39,17 @@
Loading
25 39
      !isFALSE(x <- tryCatch(readRDS("rtweet_token.rds"), error = function(e) FALSE))) {
26 40
    return(x)
27 41
  }
28 -
  if (file.exists("rtweet_token.rds") &&
29 -
      !isFALSE(x <- tryCatch(readRDS("rtweet_token.rds"), error = function(e) FALSE))) {
42 +
  if (file.exists(".rtweet_token.rds") &&
43 +
      !isFALSE(x <- tryCatch(readRDS(".rtweet_token.rds"), error = function(e) FALSE))) {
44 +
    return(x)
45 +
  }
46 +
  home <- normalizePath("~")
47 +
  if (file.exists(file.path(home, ".rtweet_token.rds")) &&
48 +
      !isFALSE(x <- tryCatch(readRDS(file.path(home, ".rtweet_token.rds")), error = function(e) FALSE))) {
49 +
    return(x)
50 +
  }
51 +
  if (file.exists(file.path(home, "rtweet_token.rds")) &&
52 +
      !isFALSE(x <- tryCatch(readRDS(file.path(home, "rtweet_token.rds")), error = function(e) FALSE))) {
30 53
    return(x)
31 54
  }
32 55
  rtweet_token()
@@ -230,7 +253,7 @@
Loading
230 253
231 254
rtweet_token <- function(access_token = NULL, access_secret = NULL) {
232 255
  if (is.null(access_token)) {
233 -
    access_token <- unname(get_secret("TWITTER_ACCESS_TOKEN"))
256 +
    access_token <- unname(get_secret("TWITTER_ACCESS_(TOKEN|KEY)"))
234 257
  }
235 258
  if (is.null(access_secret)) {
236 259
    access_secret <- unname(get_secret("TWITTER_ACCESS_SECRET"))
Files Coverage
R 80.67%
Project Totals (5 files) 80.67%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
    patch:
10
      default:
11
        target: auto
12
        threshold: 1%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading