Skip to content

Commit

Permalink
Add cu_token arg to internals
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Solymos <[email protected]>
  • Loading branch information
psolymos committed Jan 31, 2024
1 parent 0078c05 commit 52e6ae6
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions R/internals.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
}

## convenience function for GET requests with support for paging
.cu_get <- function(..., query=list(), paging=TRUE) {
.cu_get <- function(..., query=list(), paging=TRUE, cu_token = NULL) {
chunk <- .cu_get_page(..., query = query)
out <- chunk
page <- 0
while (paging && length(chunk) == 1 && length(chunk[[1]]) == 100) {
page <- page + 1
query$page <- page
chunk <- .cu_get_page(..., query = query)
chunk <- .cu_get_page(..., query = query, cu_token = cu_token)
stopifnot(length(chunk) == 1)
out[[1]] <- c(out[[1]], chunk[[1]])
}
Expand All @@ -53,12 +53,12 @@
}

## convenience function for GET requests
.cu_get_page <- function(..., query=list()) {
.cu_get_page <- function(..., query=list(), cu_token = NULL) {
resp <- .rate_insist(httr::GET(
httr::modify_url(getOption("cu_options")$baseurl,
path = .cu_path(...),
query = query),
httr::add_headers(Authorization = cu_get_pat()),
httr::add_headers(Authorization = cu_get_pat(token = cu_token)),
httr::content_type_json(),
httr::accept_json(),
httr::user_agent(getOption("cu_options")$useragent))
Expand All @@ -67,12 +67,12 @@
}

## convenience function for POST requests
.cu_post <- function(..., body=NULL, query=list()) {
.cu_post <- function(..., body=NULL, query=list(), cu_token = NULL) {
resp <- .rate_insist(httr::POST(
httr::modify_url(getOption("cu_options")$baseurl,
path = .cu_path(...),
query = query),
httr::add_headers(Authorization = cu_get_pat()),
httr::add_headers(Authorization = cu_get_pat(token = cu_token)),
httr::content_type_json(),
httr::accept_json(),
body=jsonlite::toJSON(body, auto_unbox=TRUE),
Expand All @@ -85,12 +85,12 @@
}

## convenience function for PUT requests
.cu_put <- function(..., body=NULL, query=list()) {
.cu_put <- function(..., body=NULL, query=list(), cu_token = NULL) {
resp <- .rate_insist(httr::PUT(
httr::modify_url(getOption("cu_options")$baseurl,
path = .cu_path(...),
query = query),
httr::add_headers(Authorization = cu_get_pat()),
httr::add_headers(Authorization = cu_get_pat(token = cu_token)),
httr::content_type_json(),
httr::accept_json(),
body=jsonlite::toJSON(body, auto_unbox=TRUE),
Expand All @@ -103,12 +103,12 @@
}

## convenience function for DELETE requests
.cu_delete <- function(..., body=NULL, query=list()) {
.cu_delete <- function(..., body=NULL, query=list(), cu_token = NULL) {
resp <- .rate_insist(httr::DELETE(
httr::modify_url(getOption("cu_options")$baseurl,
path = .cu_path(...),
query = query),
httr::add_headers(Authorization = cu_get_pat()),
httr::add_headers(Authorization = cu_get_pat(token = cu_token)),
httr::content_type_json(),
httr::accept_json(),
body=jsonlite::toJSON(body, auto_unbox=TRUE),
Expand Down

0 comments on commit 52e6ae6

Please sign in to comment.