gar_batch: Turn a list of gar_fetch_functions into batch functions

Description Usage Arguments Details Value See Also Examples

View source: R/batch.R

Description

Turn a list of gar_fetch_functions into batch functions

Usage

1
2
3
gar_batch(call_list, ...,
  batch_endpoint = getOption("googleAuthR.batch_endpoint", default =
  "https://www.googleapis.com/batch"))

Arguments

call_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

 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
28
29
## 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 June 21, 2018, 5:05 p.m.