bart

package module
v0.0.0-...-d861467 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2015 License: ISC Imports: 5 Imported by: 0

README

A golang wrapper for the BART API (work in progress)

To install the package

go get github.com/chaitanyav/bart

For Docs

godoc -http=:8000

http://localhost:8000/pkg/github.com/chaitanyav/bart/

Sample code to get BART Stations along with Station info and Station Access information

package main

import (
"github.com/chaitanyav/bart"
"fmt"
"log"
)

func main() {
  stationsInfo, err := bart.GetStations()
    if err != nil {
      log.Fatalf("Error getting stations info: %s\n", err)
    }

  for _, station := range stationsInfo.Stations {
    fmt.Printf("Name: %q, Abbr: %q, Latitude: %g, Longitude: %g, Address: %q, City: %q, County: %q, State: %q, Zip: %d\n\n", station.Name, station.Abbr, station.Latitude, station.Longitude, station.Address, station.City, station.County, station.State, station.Zip)
  }

  stationAccessInfo, err := bart.GetStationAccessInfo("19th")
    if err != nil {
      log.Fatalf("Error getting station access info: %s\n", err)
    }

  fmt.Printf("Entering: %s\nExiting: %s\nParking: %s\nFillTime: %s\nCarShare: %s\nLockers: %s\nDestinations: %s\nTransitInfo: %s\n", stationAccessInfo.Entering, stationAccessInfo.Exiting, stationAccessInfo.Parking, stationAccessInfo.FillTime, stationAccessInfo.CarShare, stationAccessInfo.Lockers, stationAccessInfo.Destinations, stationAccessInfo.TransitInfo)
  stationInfo, err := bart.GetStationInfo("24th")
    if err != nil {
      log.Fatalf("Error getting station access info: %s\n",
          err)
    }
  fmt.Printf("NorthRoutes: %s\nSouthRoutes: %s\nNorthPlatforms: %s\nSouthPlatforms: %s\nPlatformInfo: %s\nIntro: %s\nCrossStreet: %s\nFood: %s\nShopping: %s\nAttractions: %s\nLink: %s\n", stationInfo.NorthRoutes, stationInfo.SouthRoutes, stationInfo.NorthPlatforms, stationInfo.SouthPlatforms, stationInfo.PlatformInfo, stationInfo.Intro, stationInfo.CrossStreet, stationInfo.Food, stationInfo.Shopping, stationInfo.Attractions, stationInfo.Link)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDataFromUri

func GetDataFromUri(uri string) ([]byte, error)

Types

type BSA

type BSA struct {
	Uri         string `xml:"uri"`
	Type        string `xml:"type"`
	Date        string `xml:"date"`
	Time        string `xml:"time"`
	Posted      string `xml:"bsa>posted"`
	Description string `xml:"bsa>description"`
	Expires     string `xml:"bsa>expires"`
	Message
}

func GetBSA

func GetBSA() (*BSA, error)

type Count

type Count struct {
	Uri       string `xml:"uri"`
	Date      string `xml:"date"`
	Time      string `xml:"time"`
	NumTrains int    `xml:"traincount"`
	Message
}

func GetActiveTrainCount

func GetActiveTrainCount() (*Count, error)

type Elevator

type Elevator struct {
	Uri         string `xml:"uri"`
	Date        string `xml:"date"`
	Time        string `xml:"time"`
	Posted      string `xml:"bsa>posted"`
	Description string `xml:"bsa>description"`
	Message
}

func GetElevatorStatus

func GetElevatorStatus() (*Elevator, error)

type Message

type Message struct {
	ErrorText    string `xml:"message>error>text"`
	ErrorDetails string `xml:"message>error>details"`
}

type Root

type Root struct {
	Uri      string    `xml:"uri"`
	Stations []Station `xml:"stations>station"`
	Message
}

func GetStations

func GetStations() (*Root, error)

func (*Root) String

func (root *Root) String() string

type Route

type Route struct {
	Name        string   `xml:"name"`
	Abbr        string   `xml:"abbr"`
	RouteID     string   `xml:"routeID"`
	Number      int      `xml:"number"`
	Origin      string   `xml:"origin"`
	Color       string   `xml:"color"`
	Direction   string   `xml:"direction"`
	Holidays    int      `xml:"holidays"`
	NumStations int      `xml:"num_stns"`
	Stns        []string `xml:"config>station"`
}

func GetRouteInfo

func GetRouteInfo(routeNumber int) (*Route, error)

func GetRoutes

func GetRoutes() ([]Route, error)

type RouteInfoRoot

type RouteInfoRoot struct {
	Uri       string `xml:"uri"`
	RouteInfo Route  `xml:"routes>route"`
	Message
}

type RoutesRoot

type RoutesRoot struct {
	Uri    string  `xml:"uri"`
	Routes []Route `xml:"routes>route"`
	Message
}

type Station

type Station struct {
	Name      string  `xml:"name"`
	Abbr      string  `xml:"abbr"`
	Latitude  float64 `xml:"gtfs_latitude"`
	Longitude float64 `xml:"gtfs_longitude"`
	Address   string  `xml:"address"`
	City      string  `xml:"city"`
	County    string  `xml:"county"`
	State     string  `xml:"state"`
	Zip       int     `xml:"zipcode"`
	StationInfo
	StationAccess
}

type StationAccess

type StationAccess struct {
	Entering     string `xml:"entering"`
	Exiting      string `xml:"exiting"`
	Parking      string `xml:"parking"`
	FillTime     string `xml:"fill_time"`
	CarShare     string `xml:"car_share"`
	Lockers      string `xml:"lockers"`
	Destinations string `xml:"destinations"`
	TransitInfo  string `xml:"transit_info"`
}

func GetStationAccessInfo

func GetStationAccessInfo(stationCode string) (*StationAccess, error)

type StationInfo

type StationInfo struct {
	NorthRoutes    []string `xml:"north_routes>route"`
	SouthRoutes    []string `xml:"south_routes>route"`
	NorthPlatforms []string `xml:"north_platforms>platform"`
	SouthPlatforms []string `xml:"south_platforms>platform"`
	PlatformInfo   string   `xml:"platform_info"`
	Intro          string   `xml:"intro"`
	CrossStreet    string   `xml:"cross_street"`
	Food           string   `xml:"food"`
	Shopping       string   `xml:"shopping"`
	Attractions    string   `xml:"attraction"`
	Link           string   `xml:"link"`
}

func GetStationInfo

func GetStationInfo(stationCode string) (*StationInfo, error)

Jump to

Keyboard shortcuts

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