gar_batch: Turn a list of gar_fetch_functions into batch functions

View source: R/batch.R

gar_batchR Documentation

Turn a list of gar_fetch_functions into batch functions

Description

Turn a list of gar_fetch_functions into batch functions

Usage

gar_batch(
  function_list,
  ...,
  batch_endpoint = getOption("googleAuthR.batch_endpoint", default =
    "https://www.googleapis.com/batch")
)

Arguments

function_list

a list of functions from gar_api_generator

...

further arguments passed to the data parse function of f

batch_endpoint

the batch API endpoint to send to

Details

This function will turn all the individual Google API functions into one POST request to /batch.

If you need to pass multiple data parse function arguments its probably best to do it in separate batches to avoid confusion.

Value

A list of the Google API responses

See Also

https://developers.google.com/webmaster-tools/v3/how-tos/batch

Documentation on doing batch requests for the search console API. Other Google APIs are similar.

Walk through API calls changing parameters using gar_batch_walk

Other batch functions: gar_batch_walk()

Examples


## Not run: 

## usually set on package load
options(googleAuthR.batch_endpoint = "https://www.googleapis.com/batch/urlshortener/v1")

## from goo.gl API
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)
}


## from goo.gl API
user_history <- function(){
  f <- gar_api_generator("https://www.googleapis.com/urlshortener/v1/url/history",
                      "GET",
                      data_parse_function = function(x) x$items)
                      
  f()
}

gar_batch(list(shorten_url("http://markedmondson.me"), user_history()))


## End(Not run)

googleAuthR documentation built on May 29, 2024, 7:22 a.m.