Skip to content

Commit

Permalink
add get line status by mode (#13)
Browse files Browse the repository at this point in the history
* add initial line models and function

* add comments to models

* add comment to conv function

* correct casing of id fields
  • Loading branch information
jamesalexatkin authored Jul 15, 2024
1 parent e816663 commit de8f4d9
Show file tree
Hide file tree
Showing 3 changed files with 252 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/conv/conv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package conv

import "strings"

// StringSliceToString converts a string slice to a string.
func StringSliceToString(s []string) string {
return strings.Join(s, ",")
}
23 changes: 23 additions & 0 deletions line.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package tfl

import (
"context"
"fmt"

"github.com/jamesalexatkin/tfl-golang/internal/conv"
)

// GetLineStatusByMode gets the line status of all lines for the given modes.
//
// https://api.tfl.gov.uk/swagger/ui/index.html?url=/swagger/docs/v1#!/Line/Line_StatusByMode
func (c *Client) GetLineStatusByMode(ctx context.Context, modes []string) ([]Status, error) {
path := fmt.Sprintf("/Line/Mode/%s/Status", conv.StringSliceToString(modes))

statuses := []Status{}
err := c.get(ctx, path, &statuses)
if err != nil {
return nil, err
}

return statuses, err
}
221 changes: 221 additions & 0 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,55 @@ type AdditionalProperty struct {
Modified string `json:"modified"`
}

// AffectedRoute represents a route affected by a disruption.
type AffectedRoute struct {
ID string `json:"id"`
LineID string `json:"lineId"`
RouteCode string `json:"routeCode"`
Name string `json:"name"`
LineString string `json:"lineString"`
Direction string `json:"direction"`
OriginationName string `json:"originationName"`
DestinationName string `json:"destinationName"`
Via Via `json:"via"`
IsEntireRouteSection bool `json:"isEntireRouteSection"`
ValidTo time.Time `json:"validTo"`
ValidFrom time.Time `json:"validFrom"`
RouteSectionNaptanEntrySequence []RouteSectionNaptanEntrySequence `json:"routeSectionNaptanEntrySequence"`
}

// AffectedStop represents a stop affected by a disruption.
type AffectedStop struct {
NaptanID string `json:"naptanId"`
PlatformName string `json:"platformName"`
Indicator string `json:"indicator"`
StopLetter string `json:"stopLetter"`
Modes []string `json:"modes"`
IcsCode string `json:"icsCode"`
SmsCode string `json:"smsCode"`
StopType string `json:"stopType"`
StationNaptan string `json:"stationNaptan"`
AccessibilitySummary string `json:"accessibilitySummary"`
HubNaptanCode string `json:"hubNaptanCode"`
Lines []Line `json:"lines"`
LineGroup []LineGroup `json:"lineGroup"`
LineModeGroups []LineModeGroup `json:"lineModeGroups"`
FullName string `json:"fullName"`
NaptanMode string `json:"naptanMode"`
Status bool `json:"status"`
IndividualStopID string `json:"individualStopId"`
ID string `json:"id"`
URL string `json:"url"`
CommonName string `json:"commonName"`
Distance float64 `json:"distance"`
PlaceType string `json:"placeType"`
AdditionalProperties []Property `json:"additionalProperties"`
Children []StopPoint `json:"children"`
ChildrenUrls []string `json:"childrenUrls"`
Lat float64 `json:"lat"`
Lon float64 `json:"lon"`
}

// Bay represents an individual parking bay in a car park.
type Bay struct {
BayType string `json:"bayType"`
Expand Down Expand Up @@ -73,6 +122,73 @@ type Casualty struct {
AgeBand string `json:"ageBand"`
}

// Crowding represents how crowded a particular vehicle is.
type Crowding struct {
PassengerFlows []PassengerFlow `json:"passengerFlows"`
TrainLoadings []TrainLoading `json:"trainLoadings"`
}

// Disruption represents a particular disruption.
type Disruption struct {
Category string `json:"category"`
Type string `json:"type"`
CategoryDescription string `json:"categoryDescription"`
Description string `json:"description"`
Summary string `json:"summary"`
AdditionalInfo string `json:"additionalInfo"`
Created time.Time `json:"created"`
LastUpdate time.Time `json:"lastUpdate"`
AffectedRoutes []AffectedRoute `json:"affectedRoutes"`
AffectedStops []AffectedStop `json:"affectedStops"`
ClosureText string `json:"closureText"`
}

// Line represents a particular line on a mode of transport.
type Line struct {
ID string `json:"id"`
Name string `json:"name"`
URI string `json:"uri"`
FullName string `json:"fullName"`
Type string `json:"type"`
Crowding Crowding `json:"crowding"`
RouteType string `json:"routeType"`
Status string `json:"status"`
MotType string `json:"motType"`
Network string `json:"network"`
}

// LineGroup represents national metadata identifying the group of the line.
type LineGroup struct {
NaptanIDReference string `json:"naptanIdReference"`
StationAtcoCode string `json:"stationAtcoCode"`
LineIDentifier []string `json:"lineIdentifier"`
}

// LineModeGroup represents the mode group of a line.
type LineModeGroup struct {
ModeName string `json:"modeName"`
LineIdentifier []string `json:"lineIdentifier"`
}

// LineStatus represents the status of a particular line.
type LineStatus struct {
ID int `json:"id"`
LineID string `json:"lineId"`
StatusSeverity int `json:"statusSeverity"`
StatusSeverityDescription string `json:"statusSeverityDescription"`
Reason string `json:"reason"`
Created time.Time `json:"created"`
Modified time.Time `json:"modified"`
ValidityPeriods []ValidityPeriod `json:"validityPeriods"`
Disruption Disruption `json:"disruption"`
}

// PassengerFlow represents the flow of passengers at a particular time.
type PassengerFlow struct {
TimeSlice string `json:"timeSlice"`
Value int `json:"value"`
}

// Place represents a place managed by TfL. This includes things like bike points, coach bays and speed cameras.
type Place struct {
ID string `json:"id"`
Expand Down Expand Up @@ -121,7 +237,112 @@ type PredictionTiming struct {
Received string `json:"received"`
}

// Property represents an additional property for a station or stop point.
type Property struct {
Category string `json:"category"`
Key string `json:"key"`
SourceSystemKey string `json:"sourceSystemKey"`
Value string `json:"value"`
Modified time.Time `json:"modified"`
}

// RouteSection represents a particular section of a route.
type RouteSection struct {
RouteCode string `json:"routeCode"`
Name string `json:"name"`
Direction string `json:"direction"`
OriginationName string `json:"originationName"`
DestinationName string `json:"destinationName"`
Originator string `json:"originator"`
Destination string `json:"destination"`
ServiceType string `json:"serviceType"`
ValidTo time.Time `json:"validTo"`
ValidFrom time.Time `json:"validFrom"`
}

// RouteSectionNaptanEntrySequence represents the NaPTAN information for a route section.
type RouteSectionNaptanEntrySequence struct {
Ordinal int `json:"ordinal"`
StopPoint StopPoint `json:"stopPoint"`
}

// ServiceType represents a type of service for a mode of transport.
type ServiceType struct {
Name string `json:"name"`
URI string `json:"uri"`
}

// Status represents the status for a mode of transport.
type Status struct {
ID string `json:"id"`
Name string `json:"name"`
ModeName string `json:"modeName"`
Disruptions []Disruption `json:"disruptions"`
Created time.Time `json:"created"`
Modified time.Time `json:"modified"`
LineStatuses []LineStatus `json:"lineStatuses"`
RouteSections []RouteSection `json:"routeSections"`
ServiceTypes []ServiceType `json:"serviceTypes"`
Crowding Crowding `json:"crowding"`
}

// StopPoint represents a stopping point on a line.
type StopPoint struct {
NaptanID string `json:"naptanId"`
PlatformName string `json:"platformName"`
Indicator string `json:"indicator"`
StopLetter string `json:"stopLetter"`
Modes []string `json:"modes"`
IcsCode string `json:"icsCode"`
SmsCode string `json:"smsCode"`
StopType string `json:"stopType"`
StationNaptan string `json:"stationNaptan"`
AccessibilitySummary string `json:"accessibilitySummary"`
HubNaptanCode string `json:"hubNaptanCode"`
Lines []Line `json:"lines"`
LineGroup []LineGroup `json:"lineGroup"`
LineModeGroups []LineModeGroup `json:"lineModeGroups"`
FullName string `json:"fullName"`
NaptanMode string `json:"naptanMode"`
Status bool `json:"status"`
IndividualStopID string `json:"individualStopId"`
ID string `json:"id"`
URL string `json:"url"`
CommonName string `json:"commonName"`
Distance float64 `json:"distance"`
PlaceType string `json:"placeType"`
AdditionalProperties []Property `json:"additionalProperties"`
Children []StopPoint `json:"children"`
ChildrenUrls []string `json:"childrenUrls"`
Lat float64 `json:"lat"`
Lon float64 `json:"lon"`
}

// TrainLoading represents the loading of a train going in a particular direction.
type TrainLoading struct {
Line string `json:"line"`
LineDirection string `json:"lineDirection"`
PlatformDirection string `json:"platformDirection"`
Direction string `json:"direction"`
NaptanTo string `json:"naptanTo"`
TimeSlice string `json:"timeSlice"`
Value int `json:"value"`
}

// ValidityPeriod represents a period of time for which a status is valid.
type ValidityPeriod struct {
FromDate time.Time `json:"fromDate"`
ToDate time.Time `json:"toDate"`
IsNow bool `json:"isNow"`
}

// Vehicle represents a vehicle.
type Vehicle struct {
Type string `json:"type"`
}

// Via represents a stop point that a route can go via (e.g. Northern Line via Charing Cross).
type Via struct {
Ordinal int `json:"ordinal"`
StopPoint StopPoint `json:"stopPoint"`
}

0 comments on commit de8f4d9

Please sign in to comment.