# NOTE: This file is auto generated by OpenAPI Generator 7.1.0 (https://openapi-generator.tech).
# Do not edit this file manually.
defmodule MBTA.Api.Prediction do
@moduledoc """
API calls for all endpoints tagged `Prediction`.
"""
alias MBTA.Connection
import MBTA.RequestBuilder
@doc """
**NOTE:** A filter **MUST** be present for any predictions to be returned. List of predictions for trips. To get the scheduled times instead of the predictions, use `/schedules`. The predicted arrival time (`//data/{index}/attributes/arrival_time`) and departure time (`/data/{index}/attributes/departure_time`) to/from a stop (`/data/{index}/relationships/stop/data/id`) at a given sequence (`/data/{index}/attriutes/stop_sequence`) along a trip (`/data/{index}/relationships/trip/data/id`) going a direction (`/data/{index}/attributes/direction_id`) along a route (`/data/{index}/relationships/route/data/id`). See [GTFS Realtime `FeedMesage` `FeedEntity` `TripUpdate` `TripDescriptor`](https://github.com/google/transit/blob/master/gtfs-realtime/spec/en/reference.md#message-tripdescriptor) See [GTFS Realtime `FeedMesage` `FeedEntity` `TripUpdate` `StopTimeUpdate`](https://github.com/google/transit/blob/master/gtfs-realtime/spec/en/reference.md#message-stoptimeupdate) ## When a vehicle is predicted to be at a stop `/predictions?filter[stop]=STOP_ID` ## The predicted schedule for one route `/predictions?filter[route]=ROUTE_ID` ## The predicted schedule for a whole trip `/predictions?filter[trip]=TRIP_ID`
### Parameters
- `connection` (MBTA.Connection): Connection to server
- `opts` (keyword): Optional parameters
- `:"page[offset]"` (integer()): Offset (0-based) of first element in the page
- `:"page[limit]"` (integer()): Max number of elements to return
- `:sort` (String.t): Results can be [sorted](http://jsonapi.org/format/#fetching-sorting) by the id or any `/data/{index}/attributes` key. | JSON pointer | Direction | `sort` | |--------------|-----------|------------| | `/data/{index}/attributes/arrival_time` | ascending | `arrival_time` | | `/data/{index}/attributes/arrival_time` | descending | `-arrival_time` | | `/data/{index}/attributes/departure_time` | ascending | `departure_time` | | `/data/{index}/attributes/departure_time` | descending | `-departure_time` | | `/data/{index}/attributes/direction_id` | ascending | `direction_id` | | `/data/{index}/attributes/direction_id` | descending | `-direction_id` | | `/data/{index}/attributes/schedule_relationship` | ascending | `schedule_relationship` | | `/data/{index}/attributes/schedule_relationship` | descending | `-schedule_relationship` | | `/data/{index}/attributes/status` | ascending | `status` | | `/data/{index}/attributes/status` | descending | `-status` | | `/data/{index}/attributes/stop_sequence` | ascending | `stop_sequence` | | `/data/{index}/attributes/stop_sequence` | descending | `-stop_sequence` | | `/data/{index}/attributes/arrival_time` if present, otherwise `/data/{index}/attributes/departure_time` | ascending | `time` | | `/data/{index}/attributes/arrival_time` if present, otherwise `/data/{index}/attributes/departure_time` | descending | `-time` |
- `:"fields[prediction]"` (String.t): Fields to include with the response. Multiple fields **MUST** be a comma-separated (U+002C COMMA, \",\") list. Note that fields can also be selected for included data types: see the [V3 API Best Practices](https://www.mbta.com/developers/v3-api/best-practices) for an example.
- `:include` (String.t): Relationships to include. * `schedule` * `stop` * `route` * `trip` * `vehicle` * `alerts` The value of the include parameter **MUST** be a comma-separated (U+002C COMMA, \",\") list of relationship paths. A relationship path is a dot-separated (U+002E FULL-STOP, \".\") list of relationship names. [JSONAPI \"include\" behavior](http://jsonapi.org/format/#fetching-includes) ## Example `https://api-v3.mbta.com/predictions?filter%5Bstop%5D=place-sstat&filter%5Bdirection_id%5D=0&include=stop` returns predictions from South Station with direction_id=0, below is a truncated response with only relevant fields displayed: ``` { \"data\": [ { \"id\": \"prediction-CR-Weekday-Fall-18-743-South Station-02-1\", \"relationships\": { \"stop\": { \"data\": { \"id\": \"South Station-02\", \"type\": \"stop\" } }, }, \"type\": \"prediction\" } ], \"included\": [ { \"attributes\": { \"platform_code\": \"2\", }, \"id\": \"South Station-02\", \"type\": \"stop\" } ], } ``` Note the stop relationship; use it to cross-reference stop-id with the included stops to retrieve the platform_code for the given prediction. ## Note on trips A Vehicle's `trip` is what is currently being served. A Prediction also has a `vehicle`: this is the vehicle we predict will serve this trip/stop. Since we know vehicles make future trips, the trip the vehicle is currently servicing can be different from the trips we're making predictions for. For example: * Vehicle 1234 is currently serving trip A * The block is Trip A → Trip B → Trip C We'll be making predictions for the rest of trip A, as well as all the stops of trip B and trip C. The `trip` for the Vehicle is always `A`, and all of the Predictions will reference Vehicle 1234.
- `:"filter[latitude]"` (String.t): Latitude/Longitude must be both present or both absent.
- `:"filter[longitude]"` (String.t): Latitude/Longitude must be both present or both absent.
- `:"filter[radius]"` (Date.t): Radius accepts a floating point number, and the default is 0.01. For example, if you query for: latitude: 42, longitude: -71, radius: 0.05 then you will filter between latitudes 41.95 and 42.05, and longitudes -70.95 and -71.05.
- `:"filter[direction_id]"` (String.t): Filter by direction of travel along the route. Must be used in conjuction with `filter[route]` to apply. The meaning of `direction_id` varies based on the route. You can programmatically get the direction names from `/routes` `/data/{index}/attributes/direction_names` or `/routes/{id}` `/data/attributes/direction_names`.
- `:"filter[route_type]"` (String.t): Filter by route_type: https://developers.google.com/transit/gtfs/reference/routes-file. Multiple `route_type` **MUST** be a comma-separated (U+002C COMMA, \",\") list. Must be used in conjunction with another filter.
- `:"filter[stop]"` (String.t): Filter by `/data/{index}/relationships/stop/data/id`. Multiple IDs **MUST** be a comma-separated (U+002C COMMA, \",\") list. Parent station IDs are treated as though their child stops were also included.
- `:"filter[route]"` (String.t): Filter by `/data/{index}/relationships/route/data/id`. Multiple IDs **MUST** be a comma-separated (U+002C COMMA, \",\") list.
- `:"filter[trip]"` (String.t): Filter by `/data/{index}/relationships/trip/data/id`. Multiple IDs **MUST** be a comma-separated (U+002C COMMA, \",\") list.
- `:"filter[route_pattern]"` (String.t): Filter by `/included/{index}/relationships/route_pattern/data/id` of a trip. Multiple `route_pattern_id` **MUST** be a comma-separated (U+002C COMMA, \",\") list.
### Returns
- `{:ok, MBTA.Model.Predictions.t}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec api_web_prediction_controller_index(Tesla.Env.client, keyword()) :: {:ok, MBTA.Model.Forbidden.t} | {:ok, MBTA.Model.TooManyRequests.t} | {:ok, MBTA.Model.Predictions.t} | {:ok, MBTA.Model.BadRequest.t} | {:error, Tesla.Env.t}
def api_web_prediction_controller_index(connection, opts \\ []) do
optional_params = %{
:"page[offset]" => :query,
:"page[limit]" => :query,
:sort => :query,
:"fields[prediction]" => :query,
:include => :query,
:"filter[latitude]" => :query,
:"filter[longitude]" => :query,
:"filter[radius]" => :query,
:"filter[direction_id]" => :query,
:"filter[route_type]" => :query,
:"filter[stop]" => :query,
:"filter[route]" => :query,
:"filter[trip]" => :query,
:"filter[route_pattern]" => :query
}
request =
%{}
|> method(:get)
|> url("/predictions")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{429, MBTA.Model.TooManyRequests},
{403, MBTA.Model.Forbidden},
{400, MBTA.Model.BadRequest},
{200, MBTA.Model.Predictions}
])
end
end