Skip to content
bamnetPublic

About

Go client for the NJTransit API

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

89 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NJTAPI

GoDoc Build Status codecov Go Report Card GitHub

NJTAPI is a Go library for accessing data about NJTransit Trains. It wraps the NJTransit HTTP API.

Features include:

  • Timetables and statuses of departures from each station.
  • Train status including location and stops.
  • Station service messages (banner advisories).
  • List of all the train stations in the system.
  • Service alerts from the RailData GTFS-realtime feed (Client.Alerts).

See the GoDoc for full details.

Installation

import "github.com/bamnet/njtapi"

API Access

Register with the NJTransit Developer Portal to get a username and password needed to call the API.

Service alerts come from NJTransit's RailData API, which has its own username and password, separate from the ones above. Pass them with the WithRailData option:

client := njtapi.NewClient(baseURL, username, password,
	njtapi.WithRailData(railDataUsername, railDataPassword))
alerts, err := client.Alerts(context.Background())

Without WithRailData, Alerts returns ErrRailDataNotConfigured. The client logs in to RailData on first use and caches a token for each RailData API.

Example Usage

func main() {
	username := "your username"
	password := "your password"

	client := NewClient("http://njttraindata_tst.njtransit.com:8090/njttraindata.asmx/", username, password)
	station, err := client.StationData(context.Background(), "NY")
	if err != nil {
		log.Fatalf("StationData() error: %v", err)
	}
	fmt.Println("Departures from New York Penn Station")
	for _, departures := range station.Departures {
		fmt.Printf("Train to %s at %s", departures.Destination, departures.ScheduledDepartureDate)
	}
}

Demo

Run demo.go for a working demo using a command like:

go run demo/demo.go --base_url="http://njttraindata_tst.njtransit.com:8090/njttraindata.asmx/" --username=<USERNAME> --password=<PASSWORD>

Note: Both of the samples above point to a testing api server, not the production one.

About

Go client for the NJTransit API

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages