Skip to content

bamnet/njtapi

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.
  • List of all the train stations in the system.

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.

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.