Skip to content

Commit

Permalink
Add examples (7 of 9 must be in a \dontrun{})
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed May 13, 2019
1 parent eb3a4cd commit a23bced
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 4 deletions.
7 changes: 7 additions & 0 deletions R/AuthState-class.R
Expand Up @@ -16,6 +16,13 @@
#'
#' @return An object of class [AuthState].
#' @export
#' @examples
#' init_AuthState(
#' package = "mypkg",
#' app = gargle_app(),
#' api_key = gargle_api_key(),
#' auth_active = TRUE
#' )
## FIXME(jennybc): Analogous functions for the Gargle2.0 class default to the
## gargle oauth app. Should we do same in both places? If so, which way?
## Default to gargle app or have no default?
Expand Down
4 changes: 4 additions & 0 deletions R/Gargle-class.R
Expand Up @@ -25,6 +25,10 @@
#' Not used.
#' @return An object of class [Gargle2.0], either new or loaded from the cache.
#' @export
#' @examples
#' \dontrun{
#' gargle2.0_token()
#' }
gargle2.0_token <- function(email = gargle_oauth_email(),
app = gargle_app(),
package = "gargle",
Expand Down
3 changes: 3 additions & 0 deletions R/credential-function-registry.R
Expand Up @@ -25,6 +25,9 @@ gargle_env$cred_funs <- list()
#'
#' @param f A function to check.
#' @keywords internal
#' @example
#' f <- function(scopes, ...) {}
#' is_cred_fun(f)
is_cred_fun <- function(f) {
if (!is.function(f)) {
return(FALSE)
Expand Down
4 changes: 4 additions & 0 deletions R/credentials_app_default.R
Expand Up @@ -30,6 +30,10 @@
#' [`httr::Token2.0`][httr::Token-class] or `NULL`.
#' @family credential functions
#' @export
#' @examples
#' \dontrun{
#' credentials_app_default()
#' }
credentials_app_default <- function(scopes = NULL, ...) {
cat_line("trying credentials_app_default()")
# In general, application default credentials only include the cloud-platform
Expand Down
4 changes: 4 additions & 0 deletions R/credentials_gce.R
Expand Up @@ -10,6 +10,10 @@
#' @return A [GceToken()] or `NULL`.
#' @family credential functions
#' @export
#' @examples
#' \dontrun{
#' credentials_gce()
#' }
credentials_gce <- function(scopes = NULL, service_account = "default", ...) {
cat_line("trying credentials_gce()")
if (!detect_gce() || is.null(scopes)) {
Expand Down
2 changes: 2 additions & 0 deletions R/gargle-api-key.R
Expand Up @@ -11,6 +11,7 @@
#' @return A Google API key
#' @export
#' @examples
#' \dontrun{
#' ## see the key
#' gargle_api_key()
#'
Expand All @@ -30,6 +31,7 @@
#' resp <- request_make(req)
#' out <- response_process(resp)
#' vapply(out$results, function(x) x$name, character(1))
#' }
gargle_api_key <- function() {
paste0(
"AIzaSyDXic",
Expand Down
9 changes: 9 additions & 0 deletions R/request-make.R
Expand Up @@ -17,6 +17,15 @@
#' @return Object of class `response` from [httr].
#' @export
#' @family requests and responses
#' @examples
#' \dontrun{
#' req <- gargle::request_build(
#' method = "GET",
#' path = "path/to/the/resource",
#' token = "PRETEND_I_AM_TOKEN"
#' )
#' gargle::request_make(req)
#' }
request_make <- function(x, ..., user_agent = gargle_user_agent()) {
stopifnot(is.character(x$method))
method <- switch(
Expand Down
25 changes: 25 additions & 0 deletions R/response_process.R
Expand Up @@ -38,6 +38,31 @@
#' content) is a special case returning `TRUE`.
#' @family requests and responses
#' @export
#' @examples
#' \dontrun{
#' # get an OAuth2 token with 'userinfo.email' scope
#' token <- token_fetch(scopes = "https://www.googleapis.com/auth/userinfo.email")
#'
#' # see the email associated with this token
#' req <- gargle::request_build(
#' method = "GET",
#' path = "v1/userinfo",
#' token = token,
#' base_url = "https://openidconnect.googleapis.com"
#' )
#' resp <- gargle::request_make(req)
#' response_process(resp)
#'
#' # make a bad request (this token has incorrect scope)
#' req <- gargle::request_build(
#' method = "GET",
#' path = "fitness/v1/users/{userId}/dataSources",
#' token = token,
#' params = list(userId = 12345)
#' )
#' resp <- gargle::request_make(req)
#' response_process(resp)
#' }
response_process <- function(resp, error_message = gargle_error_message) {
code <- httr::status_code(resp)

Expand Down
4 changes: 4 additions & 0 deletions R/token-fetch.R
Expand Up @@ -14,6 +14,10 @@
#' @return An [`httr::Token`][httr::Token-class] or `NULL`.
#' @family credential functions
#' @export
#' @examples
#' \dontrun{
#' token_fetch(scopes = "https://www.googleapis.com/auth/userinfo.email")
#' }
token_fetch <- function(scopes = NULL, ...) {
cat_line("trying token_fetch()")
for (f in gargle_env$cred_funs) {
Expand Down
5 changes: 5 additions & 0 deletions man/credentials_app_default.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions man/credentials_gce.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/gargle-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions man/gargle2.0_token.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/gargle_api_key.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions man/init_AuthState.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/request_make.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions man/response_process.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions man/token_fetch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a23bced

Please sign in to comment.