Documentation ¶
Overview ¶
Package njtapi provides an library to access NJTransit Train data.
A valid username and password is required to call the NJTransit API. To register, head on over to https://datasource.njtransit.com/.
This library makes opinionated decisions about how data should be sanitized and modeled. As a result, it does not provide a 1:1 mapping of all of features and fields included in the API spec.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client stores connection info needed talking to the NJTransit API.
func NewClient ¶
NewClient constructs a new client to talk to the NJTransit API.
baseURL: The root URL that the API is exposed on. username / password: Authentication credentials for calling the API.
func NewCustomClient ¶
NewCustomClient uses the supplied `http.Client` when talking to the API. This can be useful if you need to supply a custom timeout, proxy server, etc.
See `NewClient` for a description of the rest of the parameters.
func (*Client) StationData ¶
StationData returns details about upcoming trains stopping at a station.
Example ¶
// Update these values. 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) } for _, departures := range station.Departures { fmt.Printf("Train to %s at %s", departures.Destination, departures.ScheduledDepartureDate) }
Output:
func (*Client) StationList ¶
StationList returns a list of all the stations available.
type Station ¶
type Station struct { ID string // Station character code Name string // Station name Aliases []string // Additional names for this station Departures []StationTrain // Trains departing from this station }
A Station provides information about the next trains stopping at a station.
type StationStop ¶
type StationStop struct { Name string // Station stop name Time time.Time // Estimated arrival time at this stop Departed bool // Indicates if the train has departed the stop or not }
A StationStop is a stop this train will make, or has made, on it's route.
type StationTrain ¶
type StationTrain struct { Index int // Row index TrainID int // Train ID Line string // Train line LineAbbrv string // Train line abbreviation Destination string // Destination for the train ScheduledDepartureDate time.Time // Scheduled departure time from the station Track string // Track number/letter Status string // Current train status SecondsLate time.Duration // Train delay LatLng *LatLng // Train location LatLngTimestamp time.Time // Time the train location was measured InlineMsg string // In-line message for the train at this station Stops []StationStop // List of all stops for this train. }
A StationTrain models a train which is scheduled to depart from a station.
type Train ¶
type Train struct { ID int // Train number Line string // Train line Direction string // Eastbound or Westbound LastModified time.Time // ??? ScheduledDepartureTime time.Time // ??? SecondsLate time.Duration // Train delay NextStop string // ??? LatLng *LatLng // Last identified latlng }
A Train summarizes the latest information about a train.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package main demos functionality of the `njtapi` library.
|
Package main demos functionality of the `njtapi` library. |
Package departurevision parses an HTML table showing departure information.
|
Package departurevision parses an HTML table showing departure information. |
demo
Package main demos functionality of the `departurevision` library.
|
Package main demos functionality of the `departurevision` library. |