wmata_api: Call the WMATA API

View source: R/api.R

wmata_apiR Documentation

Call the WMATA API

Description

Use httr::GET() to make a request to the WMATA API and return the parsed list from the JSON data. The function uses httr::RETRY(), so the call will repeat up to three times if there is a failure (often from a rate limit).

Usage

wmata_api(path, query = NULL, ..., level, api_key = wmata_key())

Arguments

path

The path to an API endpoint (e.g., "Bus.svc/json/jStopSchedule")

query

Additional queries also passed, possibly your key if need be.

...

Arguments passed to jsonlite::fromJSON() for parsing.

level

If parsed JSON is a list, select only this element. Useful if the list is length one containing a data frame or some other object.

api_key

Subscription key which provides access to this API. Defaults Sys.getenv("WMATA_KEY") via wmata_key().

Details

This function was modified from 'zamorarr/wmata' on GitHub: https://github.com/zamorarr/wmata/blob/master/R/api.r

Value

A single JSON string.

Examples

## Not run: 
wmata_api("Rail.svc/json/jLines", query = list(LineCode = "RD"))

## End(Not run)

metro documentation built on Nov. 2, 2023, 6:06 p.m.