Skip to content

Commit

Permalink
use httr::RETRY to wrap POST (#135)
Browse files Browse the repository at this point in the history
* use httr::RETRY to wrap POST

* add RETRY to test_request()

* get oauth2.0_token to work insistently

Fixes #131
  • Loading branch information
nathancday authored Nov 13, 2019
1 parent dd605dc commit 4ae5ca6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions R/boxr_auth.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ box_auth <- function(client_id = NULL, client_secret = NULL,
base_url = "https://app.box.com/api/oauth2"
)

insistent_token <- purrr::insistently(httr::oauth2.0_token, quiet = FALSE)

box_token <-
httr::oauth2.0_token(
insistent_token(
box_endpoint,
box_app,
use_oob = getOption("httr_oob_default"),
Expand Down Expand Up @@ -451,7 +453,7 @@ box_auth_service <- function(token_file = NULL, token_text = NULL) {
"client_secret" = config$boxAppSettings$clientSecret
)

req <- httr::POST(auth_url, body = params, encode = "form")
req <- httr::RETRY("POST", auth_url, body = params, encode = "form")

box_token <- httr::content(req)$access_token
box_token_bearer <- httr::add_headers(Authorization = paste("Bearer", box_token))
Expand Down Expand Up @@ -493,7 +495,9 @@ skip_if_no_token <- function() {
# make a test request, indicate success, return content
test_request <- function() {

test_response <- httr::GET("https://api.box.com/2.0/folders/0", get_token())
test_response <- httr::RETRY("GET",
"https://api.box.com/2.0/folders/0",
get_token())

httr::stop_for_status(test_response, task = "connect to box.com API")

Expand Down

0 comments on commit 4ae5ca6

Please sign in to comment.