Documentation ¶
Index ¶
- Variables
- type Client
- type Journey
- type JourneyOptions
- type Location
- type LocationSearchOptions
- type LocationService
- type RealtimeResponse
- type RealtimeResponseData
- type RealtimeSearchOptions
- type RealtimeService
- type ReconstructionOptions
- type Transport
- type TravelPlannerService
- func (s *TravelPlannerService) Journey(ctx context.Context, opt *JourneyOptions) (*Journey, error)
- func (s *TravelPlannerService) Reconstruction(ctx context.Context, opt *ReconstructionOptions) (*Trip, error)
- func (s *TravelPlannerService) Trip(ctx context.Context, opt *TripOptions) ([]*Trip, error)
- type Trip
- type TripOptions
- type TripResponseData
- type TypeaheadResponseData
Constants ¶
This section is empty.
Variables ¶
var ( ErrTrailingSlash = errors.New("BaseURL must have a trailing slash") ErrNoKey = errors.New("API key can't be empty") ErrNoSiteID = errors.New("SiteID can't be empty") )
var (
ErrNoSearchString = errors.New("Search string is empty")
)
var (
ErrNoTripFound = errors.New("No trip found")
)
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // Base URL for API requests. Defaults to the SL API base url. BaseURL *url.URL // User agent used when communicating with the SL API. UserAgent string // Services used for talking to different parts of the SL API. Location *LocationService Realtime *RealtimeService TravelPlanner *TravelPlannerService // contains filtered or unexported fields }
A Client manages communication with the SL API.
func NewClient ¶
NewClient returns a new SL API client. If a nil httpClient is provided, http.DefaultClient will be used.
type Journey ¶
type Journey struct { ErrorCode string `json:"errorCode"` ErrorText string `json:"errorText"` Message string `json:"Message"` Directions struct { Direction []struct { RouteIdxFrom int `json:"routeIdxFrom"` RouteIdxTo int `json:"routeIdxTo"` Value string `json:"value"` } `json:"Direction"` } `json:"Directions"` JourneyStatus string `json:"JourneyStatus"` Names struct { Name []struct { Product struct { Admin string `json:"admin"` CatCode string `json:"catCode"` CatIn string `json:"catIn"` CatOut string `json:"catOut"` CatOutL string `json:"catOutL"` CatOutS string `json:"catOutS"` Line string `json:"line"` Name string `json:"name"` Num string `json:"num"` Operator string `json:"operator"` OperatorCode string `json:"operatorCode"` } `json:"Product"` Category string `json:"category"` Name string `json:"name"` Number string `json:"number"` RouteIdxFrom int `json:"routeIdxFrom"` RouteIdxTo int `json:"routeIdxTo"` } `json:"Name"` } `json:"Names"` ServiceDays []struct { SDaysB string `json:"sDaysB"` SDaysI string `json:"sDaysI"` SDaysR string `json:"sDaysR"` } `json:"ServiceDays"` Stops struct { Stop []struct { DepDate string `json:"depDate"` DepPrognosisType string `json:"depPrognosisType"` DepTime string `json:"depTime"` DepTrack string `json:"depTrack"` ExtID string `json:"extId"` HasMainMast bool `json:"hasMainMast"` ID string `json:"id"` Lat float64 `json:"lat"` Lon float64 `json:"lon"` MainMastExtID string `json:"mainMastExtId"` MainMastID string `json:"mainMastId"` Name string `json:"name"` RouteIdx int `json:"routeIdx"` } `json:"Stop"` } `json:"Stops"` LastPassRouteIdx int `json:"lastPassRouteIdx"` LastPassStopRef int `json:"lastPassStopRef"` Ref string `json:"ref"` }
Journey represents a journey.
type JourneyOptions ¶
type JourneyOptions struct { // Trip date. Example: 2014-08-23. Default is today. Date string `url:"date,omitempty"` // The reference from Trip, see above. ID string `url:"id,omitempty"` // API Key. Key string `url:"key,omitempty"` // Indicates whether detailed routes should be calculated for the results. 0 or 1. Default is 0. Poly int `url:"poly,omitempty"` }
JourneyOptions specifies optional parameters to the TravelPlannerService.Journey.
type Location ¶
type Location struct { Name string `json:"Name"` SiteID string `json:"SiteId"` Type string `json:"Type"` X string `json:"X"` Y string `json:"Y"` }
Location represents a location from the SL API.
type LocationSearchOptions ¶
type LocationSearchOptions struct { // Exclude buses if true. Default is false that are reversed to true. Bus bool `url:"bus,omitempty"` // API Key. Key string `url:"key,omitempty"` // Max results. Default is 10. Max 50. MaxResults bool `url:"maxResults,omitempty"` // SearchString. SearchString string `url:"searchstring,omitempty"` // Include only stations. Default is false. StationsOnly bool `url:"stationsonly,omitempty"` }
LocationSearchOptions specifies optional parameters to the LocationSearch.Search.
type LocationService ¶
type LocationService service
LocationService handles communication with the location related methods of the SL API.
SL API docs: https://www.trafiklab.se/api/sl-platsuppslag/dokumentation
func (*LocationService) Search ¶
func (s *LocationService) Search(ctx context.Context, opt *LocationSearchOptions) ([]*Location, error)
Search does a location lookup and response with the location list or a error.
type RealtimeResponse ¶
type RealtimeResponse struct { Buses []*Transport `json:"Buses"` DataAge int `json:"DataAge"` LatestUpdate string `json:"LatestUpdate"` Metros []*Transport `json:"Metros"` Ships []*Transport `json:"Ships"` StopPointDeviations []struct { Deviation struct { Consequence interface{} `json:"Consequence"` ImportanceLevel int `json:"ImportanceLevel"` Text string `json:"Text"` } `json:"Deviation"` StopInfo struct { GroupOfLine string `json:"GroupOfLine"` StopAreaName string `json:"StopAreaName"` StopAreaNumber int `json:"StopAreaNumber"` TransportMode string `json:"TransportMode"` } `json:"StopInfo"` } `json:"StopPointDeviations"` Trains []*Transport `json:"Trains"` Trams []*Transport `json:"Trams"` }
RealtimeResponse represents the realtime response from SL.
type RealtimeResponseData ¶
type RealtimeResponseData struct { ExecutionTime int `json:"ExecutionTime"` Message string `json:"Message"` ResponseData *RealtimeResponse `json:"ResponseData"` StatusCode int `json:"StatusCode"` }
RealtimeResponseData represents the realtime response data SL API.
type RealtimeSearchOptions ¶
type RealtimeSearchOptions struct { // Exclude buses if true. Default is false that are reversed to true. Bus bool `url:"bus,omitempty"` // Exclude metros if true. Default is false that are reversed to true. Metro bool `url:"metro,omitempty"` // API Key. Key string `url:"key,omitempty"` // Station ID. SiteID string `url:"siteId,omitempty"` // Exclude ships if true. Default is false that are reversed to true. Ship bool `url:"ship,omitempty"` // Exclude train if true. Default is false that are reversed to true. Train bool `url:"train,omitempty"` // Exclude trams if true. Default is false that are reversed to true. Tram bool `url:"tram,omitempty"` // Time window to search departures within. Max 60 minutes. TimeWindow int `url:"timeWindow,omitempty"` }
RealtimeSearchOptions specifies optional parameters to the RealtimeService.Search.
type RealtimeService ¶
type RealtimeService service
RealtimeService handles communication with the realtime related methods of the SL API.
SL API docs: https://www.trafiklab.se/node/15754/documentation
func (*RealtimeService) Search ¶
func (s *RealtimeService) Search(ctx context.Context, opt *RealtimeSearchOptions) (*RealtimeResponse, error)
Search does a realtime search and response with the realtime list or a error.
type ReconstructionOptions ¶
type ReconstructionOptions struct { // Trip date. Example: 2014-08-23. Default is today. Date string `url:"date,omitempty"` // The value I CtxRecon as I get the response from travel. Ctx string `url:"ctx,omitempty"` // API Key. Key string `url:"key,omitempty"` // Indicates whether detailed routes should be calculated for the results. 0 or 1. Default is 0. Poly int `url:"poly,omitempty"` }
ReconstructionOptions specifies optional parameters to the TravelPlannerService.Reconstruction.
type Transport ¶
type Transport struct { Destination string `json:"Destination"` Deviations []struct { Consequence string `json:"Consequence"` ImportanceLevel int `json:"ImportanceLevel"` Text string `json:"Text"` } `json:"Deviations"` DisplayTime string `json:"DisplayTime"` ExpectedDateTime string `json:"ExpectedDateTime"` GroupOfLine string `json:"GroupOfLine"` JourneyDirection int `json:"JourneyDirection"` JourneyNumber int `json:"JourneyNumber"` LineNumber string `json:"LineNumber"` StopAreaName string `json:"StopAreaName"` StopAreaNumber int `json:"StopAreaNumber"` StopPointDesignation string `json:"StopPointDesignation"` StopPointNumber int `json:"StopPointNumber"` TimeTabledDateTime string `json:"TimeTabledDateTime"` TransportMode string `json:"TransportMode"` }
Transport represents a transport type (bus, metro, ship, tram, train) struct.
type TravelPlannerService ¶
type TravelPlannerService service
TravelPlannerService handles communication with the travel planner related methods of the SL API.
SL API docs: https://www.trafiklab.se/node/16717/documentation
func (*TravelPlannerService) Journey ¶
func (s *TravelPlannerService) Journey(ctx context.Context, opt *JourneyOptions) (*Journey, error)
Journey does a journey request to SL API and response with the journey list or a error.
func (*TravelPlannerService) Reconstruction ¶
func (s *TravelPlannerService) Reconstruction(ctx context.Context, opt *ReconstructionOptions) (*Trip, error)
Reconstruction does a reconstruction request to SL API and response with a trip or a error.
func (*TravelPlannerService) Trip ¶
func (s *TravelPlannerService) Trip(ctx context.Context, opt *TripOptions) ([]*Trip, error)
Trip does a trip request to SL API and response with the trip list or a error.
type Trip ¶
type Trip struct { LegList struct { Leg []struct { Destination struct { Date string `json:"date"` ExtID string `json:"extId"` HasMainMast bool `json:"hasMainMast"` ID string `json:"id"` Lat float64 `json:"lat"` Lon float64 `json:"lon"` MainMastExtID string `json:"mainMastExtId"` MainMastID string `json:"mainMastId"` Name string `json:"name"` PrognosisType string `json:"prognosisType"` Time string `json:"time"` Track string `json:"track"` Type string `json:"type"` } `json:"Destination"` JourneyDetailRef struct { Ref string `json:"ref"` } `json:"JourneyDetailRef"` JourneyStatus string `json:"JourneyStatus"` Origin struct { Date string `json:"date"` ExtID string `json:"extId"` HasMainMast bool `json:"hasMainMast"` ID string `json:"id"` Lat float64 `json:"lat"` Lon float64 `json:"lon"` MainMastExtID string `json:"mainMastExtId"` MainMastID string `json:"mainMastId"` Name string `json:"name"` PrognosisType string `json:"prognosisType"` Time string `json:"time"` Track string `json:"track"` Type string `json:"type"` } `json:"Origin"` Product struct { Admin string `json:"admin"` CatCode string `json:"catCode"` CatIn string `json:"catIn"` CatOut string `json:"catOut"` CatOutL string `json:"catOutL"` CatOutS string `json:"catOutS"` Line string `json:"line"` Name string `json:"name"` Num string `json:"num"` Operator string `json:"operator"` OperatorCode string `json:"operatorCode"` } `json:"Product"` Category string `json:"category"` Direction string `json:"direction"` Idx string `json:"idx"` Name string `json:"name"` Number string `json:"number"` Reachable bool `json:"reachable"` Type string `json:"type"` } `json:"Leg"` } `json:"LegList"` ServiceDays []struct { PlanningPeriodBegin string `json:"planningPeriodBegin"` PlanningPeriodEnd string `json:"planningPeriodEnd"` SDaysB string `json:"sDaysB"` SDaysI string `json:"sDaysI"` SDaysR string `json:"sDaysR"` } `json:"ServiceDays"` TariffResult struct { FareSetItem []struct { Desc string `json:"desc"` FareItem []struct { Cur string `json:"cur"` Desc string `json:"desc"` Name string `json:"name"` Price int `json:"price"` } `json:"fareItem"` Name string `json:"name"` } `json:"fareSetItem"` } `json:"TariffResult"` Checksum string `json:"checksum"` CtxRecon string `json:"ctxRecon"` Duration string `json:"duration"` Idx int `json:"idx"` TripID string `json:"tripId"` }
Trip represents a trip.
type TripOptions ¶
type TripOptions struct { // Number of minutes added to estimated turnaround time. AddChangeTime int `url:"addChangeTime,omitempty"` // Separated by; in the following format: avoidId | avoidStatus // - avoidId, internal or external id for stop / station to avoid, // - avoidStatus, one of NPAVO (do not pass), NCAVO (do not change). Optionally. Avoid string `url:"avoid,omitempty"` // Internal or external ID for stop / station to avoid change. AvoidID string `url:"avoidID,omitempty"` // Percentage of original estimated time to handle a change. // Ex, 200 doubles the time the system will use for the traveler to catch up with a change. // Default 100. ChangeTimePercent int `url:"changeTimePercent,omitempty"` // Parameter that specifies the starting point for searching later or earlier trips. Context string `url:"context,omitempty"` // Trip date. Example: 2014-08-23. Default is today. Date string `url:"date,omitempty"` // Destination station id. Example: 300109600, 9600. DestID string `url:"destId,omitempty"` // Can either be a website id or an alias, website or acronym. Examples: 300109001, 9001, TCE. DestExtID string `url:"destExtId,omitempty"` // The destination coordinate in latitude. DestCoordLat string `url:"destCoordLat,omitempty"` // The destination coordinate in longitude. DestCoordLong string `url:"destCoordLong,omitempty"` // Indicates whether a trip can start with a walking distance. For distance sharing, min and max number of meters can be specified as 1, [min distance], [max distance]. // Default is 1. DestWalk string `url:"destWalk,omitempty"` // API Key. Key string `url:"key,omitempty"` // Response language. Default 'sv', can be 'en' or 'de'. Lang string `url:"lang,omitempty"` // Line or lines separated by commas to be used to filter results, exclamation points are used for exclusion of lines. // Example: lines=55,122 Lines string `url:"lines,omitempty"` // Max change (0-11). MaxChange int `url:"maxChange,omitempty"` // Max change time in minutes. MaxChangeTime int `url:"maxChangeTime,omitempty"` // Min change time in minutes. MinChangeTime int `url:"minChangeTime,omitempty"` // Min number of trips by the specified start time, default 4. // NumF and NumB together can not exceed 6. NumB string `url:"numB,omitempty"` // Min number of trips before the specified start time, default 1. // NumF and NumB together can not exceed 6. NumF string `url:"numF,omitempty"` // Limit the number of returned trips. Note that this is an approximate number. Default = 5 NumTrips int `url:"numTrips,omitempty"` // The station to start at. Example: 300109600, 9600. OriginID string `url:"originId,omitempty"` // Can either be a website id or an alias, website or acronym. Examples: 300109001, 9001, TCE. OriginExtID string `url:"originExtId,omitempty"` // The start coordinate in latitude. OriginCoordLat string `url:"originCoordLat,omitempty"` // The start coordinate in longitude. OriginCoordLong string `url:"originCoordLong,omitempty"` // Indicates whether a trip can start with a walking distance. For distance sharing, min and max number of meters can be specified as 1, [min distance], [max distance]. // Default is 1. OriginWalk string `url:"originWalk,omitempty"` // Indicates whether stops / stations passed on the trip should be retrieved. Default 0. Passlist int `url:"passlist,omitempty"` // Indicates whether detailed routes should be calculated for the results. 0 or 1. Default is 0. Poly int `url:"poly,omitempty"` // Combination value of desired traffic mode if not all will be used when traveling. Products int `url:"products,omitempty"` // By default, you are searching for the time you want the trip to resign. // By setting searchForArrival = 1, you will instead travel based on the time you want to reach. // Default = 0. SearchForArrival int `url:"searchForArrival,omitempty"` // Time. Example hour = 19:06. Default now. Time string `url:"time,omitempty"` // The station to pass through the station. Example: 300109600, 9600. ViaID string `url:"viaId,omitempty"` // Number of minutes to be spent on the via station indicated by ViaID. ViaWaitTime int `url:"viaWaitTime,omitempty"` }
TripOptions specifies optional parameters to the TravelPlannerService.Trip.
type TripResponseData ¶
type TripResponseData struct { ErrorCode string `json:"errorCode"` ErrorText string `json:"errorText"` Message string `json:"Message"` Trip []*Trip `json:"Trip"` ScrB string `json:"scrB"` ScrF string `json:"scrF"` }
TripResponseData represents the travel planner trip response data SL API.