Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions example/vessels/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,20 @@ func main() {
fmt.Println(vesselLocations[1].VesselName)
fmt.Printf("%f°N, %f°W\n", vesselLocations[1].Latitude, vesselLocations[1].Longitude)
}

// get the route schedule
schedules, err := ferriesClient.GetRouteSchedules()
if err != nil {
panic(err)
}

for _, schedule := range schedules {
fmt.Printf("Schedule ID: %d, Route ID: %d, Description: %s\n", schedule.ScheduleID, schedule.RouteID, schedule.Description)
allSailings, err := ferriesClient.GetSchedulesTodayByRouteID(schedule.RouteID, false)
if err != nil {
panic(err)
}
fmt.Printf("last sailing: %s\n", allSailings.TerminalCombos[0].Times[len(allSailings.TerminalCombos[0].Times)-1].DepartingTime)
}

}
117 changes: 0 additions & 117 deletions ferries/ferries.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
package ferries

import (
"encoding/json"
"fmt"
"net/http"

"alpineworks.io/wsdot"
)

const (
getVesselBasicsAsJsonURL = "https://www.wsdot.wa.gov/Ferries/API/Vessels/rest/vesselbasics"
getVesselLocationsAsJsonURL = "https://www.wsdot.wa.gov/Ferries/API/Vessels/rest/vessellocations"
)

type FerriesClient struct {
wsdot *wsdot.WSDOTClient
}
Expand All @@ -26,111 +17,3 @@ func NewFerriesClient(wsdotClient *wsdot.WSDOTClient) (*FerriesClient, error) {
wsdot: wsdotClient,
}, nil
}

type VesselBasic struct {
VesselID int `json:"VesselID"`
VesselSubjectID int `json:"VesselSubjectID"`
VesselName string `json:"VesselName"`
VesselAbbrev string `json:"VesselAbbrev"`
Class struct {
ClassID int `json:"ClassID"`
ClassSubjectID int `json:"ClassSubjectID"`
ClassName string `json:"ClassName"`
SortSeq int `json:"SortSeq"`
DrawingImg string `json:"DrawingImg"`
SilhouetteImg string `json:"SilhouetteImg"`
PublicDisplayName string `json:"PublicDisplayName"`
} `json:"Class"`
Status int `json:"Status"`
OwnedByWSF bool `json:"OwnedByWSF"`
}

func (f *FerriesClient) GetVesselBasics() ([]VesselBasic, error) {
req, err := http.NewRequest(http.MethodGet, getVesselBasicsAsJsonURL, nil)
if err != nil {
return nil, fmt.Errorf("error creating request: %v", err)
}

q := req.URL.Query()
q.Add(wsdot.ParamFerriesAccessCodeKey, f.wsdot.ApiKey)
req.URL.RawQuery = q.Encode()
req.Header.Set("Content-Type", "application/json")

resp, err := f.wsdot.Client.Do(req)
if err != nil {
return nil, fmt.Errorf("error making request: %v", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}

var vessels []VesselBasic
if err := json.NewDecoder(resp.Body).Decode(&vessels); err != nil {
return nil, fmt.Errorf("error decoding response: %v", err)
}

return vessels, nil
}

type VesselLocation struct {
VesselID int `json:"VesselID"`
VesselName string `json:"VesselName"`
Mmsi int `json:"Mmsi"`
DepartingTerminalID int `json:"DepartingTerminalID"`
DepartingTerminalName string `json:"DepartingTerminalName"`
DepartingTerminalAbbrev string `json:"DepartingTerminalAbbrev"`
ArrivingTerminalID int `json:"ArrivingTerminalID"`
ArrivingTerminalName string `json:"ArrivingTerminalName"`
ArrivingTerminalAbbrev string `json:"ArrivingTerminalAbbrev"`
Latitude float64 `json:"Latitude"`
Longitude float64 `json:"Longitude"`
Speed float64 `json:"Speed"`
Heading int `json:"Heading"`
InService bool `json:"InService"`
AtDock bool `json:"AtDock"`
LeftDock string `json:"LeftDock"`
Eta string `json:"Eta"`
EtaBasis string `json:"EtaBasis"`
ScheduledDeparture string `json:"ScheduledDeparture"`
OpRouteAbbrev []string `json:"OpRouteAbbrev"`
VesselPositionNum int `json:"VesselPositionNum"`
SortSeq int `json:"SortSeq"`
ManagedBy int `json:"ManagedBy"`
TimeStamp string `json:"TimeStamp"`
VesselWatchShutID int `json:"VesselWatchShutID"`
VesselWatchShutMsg string `json:"VesselWatchShutMsg"`
VesselWatchShutFlag string `json:"VesselWatchShutFlag"`
VesselWatchStatus string `json:"VesselWatchStatus"`
VesselWatchMsg string `json:"VesselWatchMsg"`
}

func (f *FerriesClient) GetVesselLocations() ([]VesselLocation, error) {
req, err := http.NewRequest(http.MethodGet, getVesselLocationsAsJsonURL, nil)
if err != nil {
return nil, fmt.Errorf("error creating request: %v", err)
}

q := req.URL.Query()
q.Add(wsdot.ParamFerriesAccessCodeKey, f.wsdot.ApiKey)
req.URL.RawQuery = q.Encode()
req.Header.Set("Content-Type", "application/json")

resp, err := f.wsdot.Client.Do(req)
if err != nil {
return nil, fmt.Errorf("error making request: %v", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}

var vessels []VesselLocation
if err := json.NewDecoder(resp.Body).Decode(&vessels); err != nil {
return nil, fmt.Errorf("error decoding response: %v", err)
}

return vessels, nil
}
122 changes: 122 additions & 0 deletions ferries/locations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package ferries

import (
"encoding/json"
"fmt"
"net/http"

"alpineworks.io/wsdot"
)

const (
getVesselBasicsAsJsonURL = "https://www.wsdot.wa.gov/Ferries/API/Vessels/rest/vesselbasics"
getVesselLocationsAsJsonURL = "https://www.wsdot.wa.gov/Ferries/API/Vessels/rest/vessellocations"
)

type VesselBasic struct {
VesselID int `json:"VesselID"`
VesselSubjectID int `json:"VesselSubjectID"`
VesselName string `json:"VesselName"`
VesselAbbrev string `json:"VesselAbbrev"`
Class struct {
ClassID int `json:"ClassID"`
ClassSubjectID int `json:"ClassSubjectID"`
ClassName string `json:"ClassName"`
SortSeq int `json:"SortSeq"`
DrawingImg string `json:"DrawingImg"`
SilhouetteImg string `json:"SilhouetteImg"`
PublicDisplayName string `json:"PublicDisplayName"`
} `json:"Class"`
Status int `json:"Status"`
OwnedByWSF bool `json:"OwnedByWSF"`
}

func (f *FerriesClient) GetVesselBasics() ([]VesselBasic, error) {
req, err := http.NewRequest(http.MethodGet, getVesselBasicsAsJsonURL, nil)
if err != nil {
return nil, fmt.Errorf("error creating request: %v", err)
}

q := req.URL.Query()
q.Add(wsdot.ParamFerriesAccessCodeKey, f.wsdot.ApiKey)
req.URL.RawQuery = q.Encode()
req.Header.Set("Content-Type", "application/json")

resp, err := f.wsdot.Client.Do(req)
if err != nil {
return nil, fmt.Errorf("error making request: %v", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}

var vessels []VesselBasic
if err := json.NewDecoder(resp.Body).Decode(&vessels); err != nil {
return nil, fmt.Errorf("error decoding response: %v", err)
}

return vessels, nil
}

type VesselLocation struct {
VesselID int `json:"VesselID"`
VesselName string `json:"VesselName"`
Mmsi int `json:"Mmsi"`
DepartingTerminalID int `json:"DepartingTerminalID"`
DepartingTerminalName string `json:"DepartingTerminalName"`
DepartingTerminalAbbrev string `json:"DepartingTerminalAbbrev"`
ArrivingTerminalID int `json:"ArrivingTerminalID"`
ArrivingTerminalName string `json:"ArrivingTerminalName"`
ArrivingTerminalAbbrev string `json:"ArrivingTerminalAbbrev"`
Latitude float64 `json:"Latitude"`
Longitude float64 `json:"Longitude"`
Speed float64 `json:"Speed"`
Heading int `json:"Heading"`
InService bool `json:"InService"`
AtDock bool `json:"AtDock"`
LeftDock string `json:"LeftDock"`
Eta string `json:"Eta"`
EtaBasis string `json:"EtaBasis"`
ScheduledDeparture string `json:"ScheduledDeparture"`
OpRouteAbbrev []string `json:"OpRouteAbbrev"`
VesselPositionNum int `json:"VesselPositionNum"`
SortSeq int `json:"SortSeq"`
ManagedBy int `json:"ManagedBy"`
TimeStamp string `json:"TimeStamp"`
VesselWatchShutID int `json:"VesselWatchShutID"`
VesselWatchShutMsg string `json:"VesselWatchShutMsg"`
VesselWatchShutFlag string `json:"VesselWatchShutFlag"`
VesselWatchStatus string `json:"VesselWatchStatus"`
VesselWatchMsg string `json:"VesselWatchMsg"`
}

func (f *FerriesClient) GetVesselLocations() ([]VesselLocation, error) {
req, err := http.NewRequest(http.MethodGet, getVesselLocationsAsJsonURL, nil)
if err != nil {
return nil, fmt.Errorf("error creating request: %v", err)
}

q := req.URL.Query()
q.Add(wsdot.ParamFerriesAccessCodeKey, f.wsdot.ApiKey)
req.URL.RawQuery = q.Encode()
req.Header.Set("Content-Type", "application/json")

resp, err := f.wsdot.Client.Do(req)
if err != nil {
return nil, fmt.Errorf("error making request: %v", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}

var vessels []VesselLocation
if err := json.NewDecoder(resp.Body).Decode(&vessels); err != nil {
return nil, fmt.Errorf("error decoding response: %v", err)
}

return vessels, nil
}
Loading