gar_api_generator: googleAuthR data fetch function generator

Description Usage Arguments Details Value Examples

View source: R/googleAuthR_generator.R

Description

This function generates other functions for use with Google APIs

Usage

1
2
3
4
gar_api_generator(baseURI, http_header = c("GET", "POST", "PUT", "DELETE",
  "PATCH"), path_args = NULL, pars_args = NULL,
  data_parse_function = NULL, customConfig = NULL,
  simplifyVector = getOption("googleAuthR.jsonlite.simplifyVector"))

Arguments

baseURI

The stem of the API call.

http_header

Type of http request.

path_args

A named list with name=folder in request URI, value=the function variable.

pars_args

A named list with name=parameter in request URI, value=the function variable.

data_parse_function

A function that takes a request response, parses it and returns the data you need.

customConfig

list of httr options such as httr::use_proxy or httr::add_headers that will be added to the request.

simplifyVector

Passed to jsonlite::fromJSON for response parsing

Details

path_args and pars_args add default values to the baseURI. NULL entries are removed. Use "" if you want an empty argument.

You don't need to supply access_token for OAuth2 requests in pars_args, this is dealt with in gar_auth()

Add custom configurations to the request in this syntax: customConfig = list(httr::add_headers("From" = "[email protected]")

Value

A function that can fetch the Google API data you specify

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## Not run: 
library(googleAuthR)
## change the native googleAuthR scopes to the one needed.
options("googleAuthR.scopes.selected" =
  c("https://www.googleapis.com/auth/urlshortener"))

shorten_url <- function(url){

  body = list(
    longUrl = url
    )

  f <- gar_api_generator("https://www.googleapis.com/urlshortener/v1/url",
                      "POST",
                      data_parse_function = function(x) x$id)

   f(the_body = body)
 }

To use the above functions:
library(googleAuthR)
# go through authentication flow
gar_auth()
s <- shorten_url("http://markedmondson.me")
s

## End(Not run)

googleAuthR documentation built on May 30, 2017, 2:10 a.m.