Skip to content

Commit a7bb656

Browse files
committed
Update to match latest OpenAPI Spec
1 parent 6a00188 commit a7bb656

17 files changed

Lines changed: 905 additions & 296 deletions

R/aggregate.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
#'
33
#' Retrieves aggregated travel time data over a date range and stop pair.
44
#' Common query parameters include `from_stop`, `to_stop`, `start_date`, and
5-
#' `end_date`.
5+
#' `end_date`. `from_stop` and `to_stop` take **stop IDs** (as returned by
6+
#' [tm_stop_id()], [tm_bus_stop_id()], or [tm_cr_stop_id()]), not place IDs.
7+
#' Multiple stop IDs for the same station can be passed by repeating the
8+
#' argument (e.g. `from_stop = c("70076", "70077")`).
69
#'
710
#' @param ... Named query parameters passed to the API (e.g., `from_stop`,
811
#' `to_stop`, `start_date`, `end_date`).
@@ -13,8 +16,8 @@
1316
#' @examples
1417
#' \dontrun{
1518
#' tm_aggregate_travel_times(
16-
#' from_stop = "place-pktrm",
17-
#' to_stop = "place-davis",
19+
#' from_stop = "70076",
20+
#' to_stop = "70061",
1821
#' start_date = "2024-01-01",
1922
#' end_date = "2024-01-31"
2023
#' )
@@ -34,8 +37,8 @@ tm_aggregate_travel_times <- function(..., base_url = tm_base_url()) {
3437
#' @examples
3538
#' \dontrun{
3639
#' tm_aggregate_travel_times2(
37-
#' from_stop = "place-pktrm",
38-
#' to_stop = "place-davis",
40+
#' from_stop = "70076",
41+
#' to_stop = "70061",
3942
#' start_date = "2024-01-01",
4043
#' end_date = "2024-01-31"
4144
#' )

R/dated.R

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,32 @@ tm_travel_times <- function(user_date, from_stop, to_stop,
5959
#' Get MBTA service alerts
6060
#'
6161
#' When `user_date` is `NULL` the undated `/api/alerts` endpoint is called,
62-
#' returning current alerts. Pass a date to retrieve alerts for a specific day.
62+
#' returning current live alerts (no parameters accepted). Pass a date to
63+
#' retrieve historical alerts for a specific day, optionally filtered by route.
6364
#'
6465
#' @param user_date A `Date` object, a `"YYYY-MM-DD"` string, or `NULL`
6566
#' (default) for current alerts.
66-
#' @param route One or more MBTA route IDs (e.g. `"Red"`, `"Orange"`). Required.
67-
#' Use [tm_routes()] to list valid IDs.
67+
#' @param route One or more MBTA route IDs (e.g. `"Red"`, `"Orange"`). Only
68+
#' used when `user_date` is provided. Use [tm_routes()] to list valid IDs.
6869
#' @param base_url Base URL of the TransitMatters API. Defaults to
6970
#' `getOption("tm_dashboard_base_url")` or the production host.
7071
#' @return A list with an `alerts` element.
7172
#' @export
7273
#' @examples
7374
#' \dontrun{
74-
#' tm_alerts(route = "Red")
75+
#' tm_alerts()
7576
#' tm_alerts("2024-01-15", route = "Red")
7677
#' }
77-
tm_alerts <- function(user_date = NULL, route, base_url = tm_base_url()) {
78-
path <- if (is.null(user_date)) "api/alerts"
79-
else c("api", "alerts", .tm_date(user_date))
80-
tm_request(path, query = list(route = route), base_url = base_url)
78+
tm_alerts <- function(user_date = NULL, route = NULL, base_url = tm_base_url()) {
79+
if (is.null(user_date)) {
80+
tm_request("api/alerts", base_url = base_url)
81+
} else {
82+
tm_request(
83+
c("api", "alerts", .tm_date(user_date)),
84+
query = list(route = route),
85+
base_url = base_url
86+
)
87+
}
8188
}
8289

8390
#' Get stops for a route

R/parameterized.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,11 @@ tm_ridership <- function(start_date, end_date, line_id = NULL,
139139
#' Get slow zone / speed restriction data
140140
#'
141141
#' Returns current or historical speed restrictions for an MBTA line on a given
142-
#' date.
142+
#' date. Only rapid transit lines are supported.
143143
#'
144-
#' @param line_id MBTA line identifier. Accepts any of `"Red"`, `"red"`,
145-
#' `"line-red"`, or `"line-Red"` — all are equivalent.
144+
#' @param line_id Rapid transit line identifier. Valid lines: `"Red"`,
145+
#' `"Orange"`, `"Blue"`, `"Green"`. Also accepts `"red"`, `"line-red"`,
146+
#' `"line-Red"`, etc. — all are normalized internally.
146147
#' @param on_date The date to query. A `Date` object or `"YYYY-MM-DD"` string.
147148
#' @param base_url Base URL of the TransitMatters API. Defaults to
148149
#' `getOption("tm_dashboard_base_url")` or the production host.

R/stops.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ tm_stop_id <- function(line, stop_name, direction) {
7878

7979
#' Look up the GTFS place ID for a rapid transit station
8080
#'
81-
#' Returns the GTFS place identifier used by the aggregate travel-time
82-
#' endpoints (e.g. `"place-alfcl"`, `"place-davis"`).
81+
#' Returns the GTFS parent-station identifier (e.g. `"place-alfcl"`,
82+
#' `"place-davis"`). These are provided for cross-referencing with the MBTA v3
83+
#' API. The TransitMatters aggregate endpoints expect stop IDs from
84+
#' [tm_stop_id()], not place IDs.
8385
#'
8486
#' @inheritParams tm_stop_id
8587
#' @return A single GTFS place ID string.
@@ -187,7 +189,7 @@ tm_line_directions <- function(line) {
187189
#' @export
188190
#' @examples
189191
#' tm_bus_stop_id("1", "Harvard", "inbound")
190-
#' tm_bus_stop_id("66", "Harvard Square", "outbound")
192+
#' tm_bus_stop_id("66", "Harvard", "outbound")
191193
tm_bus_stop_id <- function(route, stop_name, direction) {
192194
key <- .tm_normalize_route(route, .tm_bus_stations, "bus", "tm_bus_routes")
193195
rd <- .tm_bus_stations[[key]]
@@ -246,6 +248,10 @@ tm_cr_stop_id <- function(route, stop_name, direction) {
246248

247249
#' Look up the GTFS place ID for a commuter rail station
248250
#'
251+
#' Returns the GTFS parent-station identifier (e.g. `"place-sstat"`). These
252+
#' are provided for cross-referencing with the MBTA v3 API. The TransitMatters
253+
#' aggregate endpoints expect stop IDs from [tm_cr_stop_id()], not place IDs.
254+
#'
249255
#' @param route CR route ID. Use [tm_cr_routes()] to see all valid IDs.
250256
#' @param stop_name Station name (case-insensitive).
251257
#' @return A single GTFS place ID string (e.g. `"place-sstat"`).

man/tm_aggregate_travel_times.Rd

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tm_aggregate_travel_times2.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tm_alerts.Rd

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tm_bus_stop_id.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tm_cr_place_id.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tm_line_delays.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)