mta

package module
v3.0.0-...-b7279e0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: MIT Imports: 10 Imported by: 0

README

mta

main

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

Subway

Read and Accept agreement.

Grab the API key from https://api.mta.info/#/AccessKey.

Example:

import "github.com/errornil/mta/v3"

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

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

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

Request API key here.

Example:

import "github.com/errornil/mta/v3"

client, err := mta.NewFeedsClient(
    &http.Client{
        Timeout: 30 * time.Second,
    },
    "", // API Key for Subway feeds (optional)
    "bc574e8cb4bf964dd2a215e253b2c13d", // API Key for Bus feeds (this is a fake one)
    "github.com/errornil/mta:v3.0",
)

resp, err := client.GetFeedMessage(mta.FeedBusTripUpdates)

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 EntrancesURL = "http://web.mta.info/developers/data/nyct/subway/StationEntrances.csv"

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 Entrance

type Entrance struct {
	Division         string // Specifies which division the station belongs to; either BMT, IND or IRT. Example: "BMT"
	Line             string
	StationName      string // Name of the station as shown on subway handout map. Example: "14 St-Union Sq"
	StationLatitude  float64
	StationLongitude float64
	Routes           []string     // Routes that serves the station (or complex, if applicable) during weekday service
	EntranceType     EntranceType // Describes the physical entry way indicated by the coordinates and is usually one of the following: Door or Doorway, Stair, Escalator, Elevator, Ramp or Easement (which only specifies that the entrance is within other property and does not indicate if it is a stair, etc)
	Entry            bool         // Indicates whether this 'Entrance' has turnstiles that allow entry (as opposed to exit only - see below)
	ExitOnly         bool         // Indicates if this 'Entrance' is actually an exit only location and prohibits entry
	Vending          bool
	Staffing         Staffing // Indicates the current level of staffing that is available at this entrance; FULL indicates a booth agent is available 24/7, NONE means the area is not staffed, and PART indicates that an agent is on duty at certain times but not 24/7
	StaffHours       string
	ADA              bool    // If a station is ADA accessible value is TRUE; however note this does not indicate that the actual entrance is ADA accessible
	ADANotes         string  // Any special circumstances regarding ADA accessibility at this station (or complex, if applicable)
	FreeCrossover    bool    // If a passenger can switch route directions without exiting and paying another fare at this station (note this is station level information, not entrance level)
	NorthSouthStreet string  // Primary vertical street adjacent to station entrance for wayfinding purposes
	EastWestStreet   string  // Primary horizontal street adjacent to station entrance for wayfinding purposes
	Corner           string  // Directional corner from the intersection of the vertical and horizontal streets
	Latitude         float64 // Latitude degrees of the station entrance
	Longitude        float64 // Longitude degrees of the station entrance
}

func ParseCSVReader

func ParseCSVReader(r io.Reader) ([]Entrance, error)

func ParseEntrancesCSV

func ParseEntrancesCSV(path string) ([]Entrance, error)

type EntranceType

type EntranceType int
const (
	EntranceTypeUnknown EntranceType = iota
	EntranceTypeStair
	EntranceTypeEasement
	EntranceTypeDoor
	EntranceTypeElevator
	EntranceTypeEscalator
	EntranceTypeRamp
	EntranceTypeWalkway
)

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/"

	FeedBusTripUpdates      Feed = "tripUpdates"
	FeedBusVehiclePositions Feed = "vehiclePositions"
	FeedBusAlerts           Feed = "alerts"

	FeedURLBus = "http://gtfsrt.prod.obanyc.com/"
)

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, feedsApiKey, busApiKey, 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 HTTPClient

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

type Staffing

type Staffing int
const (
	StaffingUnknown Staffing = iota
	StaffingFull
	StaffingNone
	StaffingPart
	StaffingSpecialEvent
)

Directories

Path Synopsis
examples
bus
mnr
proto
mnr

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL