mta

package module
v2.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2021 License: MIT Imports: 8 Imported by: 1

README

mta

main

mta is the library that provides an interface to MTA Real-Time Data Feeds.

Subway (GTFS-realtime feeds)

Read and Accept agreement
Example
import "github.com/errornil/mta/v2"

client, err := mta.NewSubwayClient(
    &http.Client{
        Timeout: 30 * time.Second,
    },
    "53b2c13dbc574e8cb4bf964dd2a215e253b2c13d", // API Key (this is a fake one)
    "github.com/errornil/mta:v2.0",
)

resp, err := client.GetFeedMessage(mta.Line123456S)
// check err

resp has type FeedMessage (generated).

ProtoBuf

MTA uses realtime-GTFS with their own extension for subway feeds. To re-regenerate generatated code run following command with protoc:

cd proto
protoc --go_out=../transit_realtime gtfs-realtime.proto nyct-subway.proto

Bus Times

Read and Accept agreement
Request API key
Example
import "github.com/errornil/mta/v2"

client, err := mta.NewBusTimeClient(
    &http.Client{
        Timeout: 30 * time.Second,
    },
    "fa05aa30-3c71-4953-91c8-65b46c6e5f78", // API Key (this is a fake one)
    "github.com/errornil/mta:v2.0",
)

resp, err := client.GetStopMonitoring(400933) // 400933 is the stop ID for "AV OF THE AMERICANS/W 34 ST" bus stop
// check err

resp has type StopMonitoringResponse.

This repository is not endorsed by, directly affiliated with, maintained, authorized, or sponsored by MTA. All product and company names are the registered trademarks of their original owners. The use of any trade name or trademark is for identification and reference purposes only and does not imply any association with the trademark owner.

Documentation

Index

Constants

View Source
const LIRRDepartureURL = "https://traintime.lirr.org/api/Departure"
View Source
const (
	StopMonitoringURL = "http://bustime.mta.info/api/siri/stop-monitoring.json"
)

Variables

View Source
var (
	ErrAPIKeyRequired      = fmt.Errorf("API key required")
	ErrAPIKeyNotAuthorized = fmt.Errorf("API key not authorized")
	ErrClientRequired      = fmt.Errorf("client required")
)

Functions

This section is empty.

Types

type BusTimeClient

type BusTimeClient struct {
	// contains filtered or unexported fields
}

func NewBusTimeClient

func NewBusTimeClient(client HTTPClient, apiKey, userAgent string) (*BusTimeClient, error)

func (*BusTimeClient) GetStopMonitoring

func (c *BusTimeClient) GetStopMonitoring(stopID string) (*StopMonitoringResponse, error)

func (*BusTimeClient) GetStopMonitoringWithDetailLevel

func (c *BusTimeClient) GetStopMonitoringWithDetailLevel(stopID string, detailLevel DetailLevel) (*StopMonitoringResponse, error)

type BusTimeService

type BusTimeService interface {
	GetStopMonitoring(stopID string) (*StopMonitoringResponse, error)
	GetStopMonitoringWithDetailLevel(stopID string, detailLevel DetailLevel) (*StopMonitoringResponse, error)
}

type DeparturesResponse

type DeparturesResponse struct {
	Location string                    `json:"LOC"`    // The three-letter code for that station, e.g.: JAM
	Time     string                    `json:"TIME"`   // The date and time the feed was returned at in mm/dd/yyyy hh:mm:ss format (24-hr time)
	Trains   []DeparturesResponseTrain `json:"TRAINS"` // Countdown items for each arriving train
}

type DeparturesResponseTrain

type DeparturesResponseTrain struct {
	ScheduledTime string   `json:"SCHED"`    // The scheduled date and time the train is supposed to arrive at the station in mm/dd/yyyy hh:mm:ss format (24-hr time)
	TrainID       string   `json:"TRAIN_ID"` // The train number. These are typically 1-4 digit train numbers you can find in the timetables or as the train_id’s in the GTFS feeds, though since this feed shows inserts, they can be up to 8 alphanumeric characters long.
	RunDate       string   `json:"RUN_DATE"` // E.g.: "2019-12-14",
	Destination   string   `json:"DEST"`     // The three-letter station code of the final stop on that train.
	Stops         []string `json:"STOPS"`    // The three-letter station codes of all remaining stops that train is supposed to make. If the countdown is showing at the final destination, the field will be blank for “discharge only” trains. NOTE: Hillside stops are not shown in this field.
	Track         string   `json:"TRACK"`    // The track and platform the train is supposed to depart from. May be blank at terminals when the track is not yet posted.
	Direction     string   `json:"DIR"`      // The direction the train is travelling (E = eastbound, W = westbound)
	HSF           bool     `json:"HSF"`      // Indicates whether or not the train will stop at Hillisde (true = train stops, false = train does not stop)
	JAM           *bool    `json:"JAM"`      // Indicates whether or not the train will stop at Jamaica (ture = train stops, false = train will pass through Jamaica but not stop, null = train won’t pass through Jamaica).
	ETA           string   `json:"ETA"`      // The estimated arrival time of that train, updated to account for all reported schedule deviations. Returned in mm/dd/yyyy hh:mm:ss format (24-hr time). The difference between this time and the ScheduledTime is how late or early the train is.
	Countdown     int      `json:"CD"`       // The number of seconds between now and the time the train is supposed to arrive (a countdown field).
}

DeparturesResponseTrain - part of DeparturesResponse

type DetailLevel

type DetailLevel string

type Distances

type Distances struct {
	// The distance of the stop from the beginning of the trip/route
	CallDistanceAlongRoute float64

	// The distance from the vehicle to the stop along the route, in meters
	DistanceFromCall float64

	// The distance displayed in the UI, see below for an additional note
	PresentableDistance string

	// The number of stops on the vehicle's current trip until the stop in question, starting from 0
	StopsFromCall int
}

type ErrorCondition

type ErrorCondition struct {
	OtherError  OtherError
	Description string
}

type Extensions

type Extensions struct {
	// The MTA Bus Time extensions to show distance of the vehicle from the stop
	Distances Distances
}

type Feed

type Feed string
const (
	Feed123456S Feed = "nyct/gtfs"      // Red
	FeedACEHS   Feed = "nyct/gtfs-ace"  // Blue, Franklin Ave. Shuttle
	FeedNQRW    Feed = "nyct/gtfs-nqrw" // Yellow
	FeedBDFM    Feed = "nyct/gtfs-bdfm" // Orange
	FeedL       Feed = "nyct/gtfs-l"
	FeedSIR     Feed = "nyct/gtfs-si" // StatenIslandRailway
	FeedG       Feed = "nyct/gtfs-g"
	FeedJZ      Feed = "nyct/gtfs-jz" // Brown
	Feed7       Feed = "nyct/gtfs-7"
	FeedLIRR    Feed = "lirr/gtfs-lirr" // Long Island Rail Road
	FeedMNR     Feed = "mnr/gtfs-mnr"   // Metro-North Railroad

	AlertsAll    Feed = "camsys/all-alerts"    // All Service Alerts
	AlertsSubway Feed = "camsys/subway-alerts" // Subway Alerts
	AlertsBus    Feed = "camsys/bus-alerts"    // Bus Alerts
	AlertsLIRR   Feed = "camsys/lirr-alerts"   // Long Island Rail Road Alerts
	AlertsMNR    Feed = "camsys/mnr-alerts"    // Metro-North Railroad Alerts

	FeedURL = "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/"
)

type FeedsClient

type FeedsClient struct {
	// contains filtered or unexported fields
}

FeedsClient provides MTA GTFS-Realtime data Implements FeedsService interface.

func NewFeedsClient

func NewFeedsClient(client HTTPClient, apiKey, userAgent string) (*FeedsClient, error)

NewFeedsClient creates new FeedsClient

func (*FeedsClient) GetFeedMessage

func (f *FeedsClient) GetFeedMessage(feedID Feed) (*gtfs.FeedMessage, error)

GetFeedMessage sends request to MTA server to get latest GTFS-Realtime data from specified feed

type FeedsService

type FeedsService interface {
	GetFeedMessage(feedID Feed) (*gtfs.FeedMessage, error)
}

type FramedVehicleJourneyRef

type FramedVehicleJourneyRef struct {
	// The GTFS service date for the trip the vehicle is serving
	DataFrameRef string

	// The GTFS trip ID for trip the vehicle is serving, prefixed by the GTFS agency ID
	DatedVehicleJourneyRef string
}

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type LIRRClient

type LIRRClient struct {
	// contains filtered or unexported fields
}

func NewLIRRClient

func NewLIRRClient(client HTTPClient, userAgent string) (*LIRRClient, error)

NewLIRRClient creates new LIRRClient

func (*LIRRClient) Departures

func (lc *LIRRClient) Departures(locationCode string) (*DeparturesResponse, error)

Departures gets train departures from specified station locationCode – three-letter code for the station, for example:

"NYK" for NY-Penn Station
"ATL" for Brooklyn-Atlantic Term
"HVL" for Hicksville

Full list of codes: https://github.com/errornil/mta/blob/master/lirr.md

type LIRRService

type LIRRService interface {
	Departures(locationCode string) (*DeparturesResponse, error)
}

type MonitoredCall

type MonitoredCall struct {
	// The GTFS stop ID of the stop prefixed by agency_id
	StopPointRef string

	// The ordinal value of the visit of this vehicle to this stop, always 1 in this implementation
	VisitNumber int

	// Predicted arrival times in ISO8601 format
	ExpectedArrivalTime string

	// Predicted departure times in ISO8601 format
	ExpectedDepartureTime string

	// SIRI container for extensions to the standard
	Extensions Extensions

	ArrivalProximityText string

	DistanceFromStop int

	NumberOfStopsAway int

	StopPointName []string
}

type MonitoredStopVisit

type MonitoredStopVisit struct {
	// The timestamp of the last real-time update from the particular vehicle
	RecordedAtTime string

	// A complete MonitoredVehicleJourney element
	MonitoredVehicleJourney MonitoredVehicleJourney
}

type MonitoredVehicleJourney

type MonitoredVehicleJourney struct {
	// The 'fully qualified' route name (GTFS agency ID + route ID) for the trip the vehicle is serving.
	// Not intended to be customer-facing
	LineRef string

	// The GTFS direction for the trip the vehicle is serving
	DirectionRef string

	// A compound element uniquely identifying the trip the vehicle is serving
	FramedVehicleJourneyRef FramedVehicleJourneyRef

	// The GTFS Shape_ID, prefixed by GTFS Agency ID
	JourneyPatternRef string

	// The GTFS route_short_name
	PublishedLineName []string

	// GTFS Agency_ID
	OperatorRef string

	// The GTFS stop ID for the first stop on the trip the vehicle is serving, prefixed by Agency ID
	OriginRef string

	// The GTFS stop ID for the last stop on the trip the vehicle is serving, prefixed by Agency ID
	DestinationRef string

	// The GTFS trip_headsign for the trip the vehicle is serving
	DestinationName []string

	// If a bus has not yet departed, OriginAimedDepartureTime indicates the scheduled departure time of that bus from that terminal in ISO8601 format
	OriginAimedDepartureTime string

	// SituationRef, present only if there is an active service alert covering this call
	SituationRef []SituationRef

	// Always true
	Monitored bool

	// The most recently recorded or inferred coordinates of this vehicle
	VehicleLocation *VehicleLocation

	// Vehicle bearing: 0 is East, increments counter-clockwise
	Bearing float64

	// Indicator of whether the bus is making progress (i.e. moving, generally),
	// not moving (with value noProgress),
	// laying over before beginning a trip (value layover),
	// or serving a trip prior to one which will arrive (prevTrip).
	ProgressRate string

	// Optional indicator of vehicle progress status.
	// Set to "layover" when the bus is in a layover waiting for its next trip to start at a terminal,
	// and/or "prevTrip" when the bus is currently serving the previous trip
	// and the information presented 'wraps around' to the following scheduled trip
	ProgressStatus []string

	// Optional indicator of whether the bus occupancy is deemed to be "full", "seatsAvailable" or "standingAvailable".
	// If bus occupancy information is not available, this indicator is not shown (aka hidden.)
	Occupancy string

	// The vehicle ID, preceded by the GTFS agency ID
	VehicleRef string

	// Depending on the system's level of confidence, the GTFS block_id the bus is serving.
	// Please see "Transparency of Block vs. Trip-Level Assignment" section below
	BlockRef string

	// Call data about a particular stop
	// In StopMonitoring, it is the stop of interest;
	// in VehicleMonitoring it is the next stop the bus will make.
	MonitoredCall *MonitoredCall

	// The collection of calls that a vehicle is going to make
	OnwardCalls *OnwardCalls
}

type OnwardCall

type OnwardCall struct {
	// The GTFS stop ID of the stop
	StopPointRef string

	// The ordinal value of the visit of this vehicle to this stop, always 1 in this implementation
	VisitNumber int

	// The GTFS stop name of the stop
	StopPointName []string

	Extensions Extensions

	ExpectedArrivalTime string

	ArrivalProximityText string

	DistanceFromStop int

	NumberOfStopsAway int
}

type OnwardCalls

type OnwardCalls struct {
	OnwardCalls []OnwardCall
}

type OtherError

type OtherError struct {
	ErrorText string
}

type ServiceDelivery

type ServiceDelivery struct {
	// The timestamp on the MTA Bus Time server at the time the request was fulfilled
	ResponseTimestamp string

	// SIRI container for VehicleMonitoring response data
	StopMonitoringDelivery []StopMonitoringDelivery

	VehicleMonitoringDelivery []VehicleMonitoringDelivery
}

type Siri

type Siri struct {
	ServiceDelivery ServiceDelivery
}

type SituationRef

type SituationRef struct {
	// SituationRef, present only if there is an active service alert covering this call
	SituationSimpleRef string
}

type StopMonitoringDelivery

type StopMonitoringDelivery struct {
	// Required by the SIRI spec
	ResponseTimestamp string

	// The time until which the response data is valid until
	ValidUntil string

	// SIRI container for data about a particular vehicle service the selected stop
	MonitoredStopVisit []MonitoredStopVisit
}

type StopMonitoringResponse

type StopMonitoringResponse struct {
	Siri Siri
}

type VehicleLocation

type VehicleLocation struct {
	Longitude float64
	Latitude  float64
}

type VehicleMonitoringDelivery

type VehicleMonitoringDelivery struct {
	// Required by the SIRI spec
	ResponseTimestamp string

	ErrorCondition ErrorCondition
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳