diff options
author | Julien Dessaux | 2021-03-18 20:12:43 +0100 |
---|---|---|
committer | Julien Dessaux | 2021-03-19 11:27:21 +0100 |
commit | bb78fe4cbac510b54d49f41efbdb35ffe7175299 (patch) | |
tree | 4c5ebba1ac3cae5b5e2b0755e2de1a0f3c00eb8d /api/departures.go | |
parent | Initial import (diff) | |
download | trains-bb78fe4cbac510b54d49f41efbdb35ffe7175299.tar.gz trains-bb78fe4cbac510b54d49f41efbdb35ffe7175299.tar.bz2 trains-bb78fe4cbac510b54d49f41efbdb35ffe7175299.zip |
Added api module with departures feature
Diffstat (limited to 'api/departures.go')
-rw-r--r-- | api/departures.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/api/departures.go b/api/departures.go new file mode 100644 index 0000000..b87e35b --- /dev/null +++ b/api/departures.go @@ -0,0 +1,59 @@ +package api + +import ( + "encoding/json" + "fmt" + "net/http" +) + +type DeparturesResponse struct { + Disruptions []interface{} `json:"disruptions"` + Notes []interface{} `json:"notes"` + Departures []struct { + DisplayInformations struct { + Direction string `json:"direction"` + Code string `json:"code"` + Network string `json:"network"` + Links []interface{} `json:"links"` + Color string `json:"color"` + Name string `json:"name"` + PhysicalMode string `json:"physical_mode"` + Headsign string `json:"headsign"` + Label string `json:"label"` + Equipments []interface{} `json:"equipments"` + TextColor string `json:"text_color"` + TripShortName string `json:"trip_short_name"` + CommercialMode string `json:"commercial_mode"` + Description string `json:"description"` + } `json:"display_informations"` + StopDateTime struct { + Links []interface{} `json:"links"` + ArrivalDateTime string `json:"arrival_date_time"` + AdditionalInformations []interface{} `json:"additional_informations"` + DepartureDateTime string `json:"departure_date_time"` + BaseArrivalDateTime string `json:"base_arrival_date_time"` + BaseDepartureDateTime string `json:"base_departure_date_time"` + DataFreshness string `json:"data_freshness"` + } `json:"stop_date_time"` + } `json:"departures"` + Context struct { + Timezone string `json:"timezone"` + CurrentDatetime string `json:"current_datetime"` + } `json:"context"` +} + +func (c *Client) GetDepartures() (departures *DeparturesResponse, err error) { + req, err := http.NewRequest("GET", fmt.Sprintf("%s/coverage/sncf/stop_areas/stop_area:SNCF:87723502/departures", c.baseURL), nil) + if err != nil { + return nil, err + } + resp, err := c.httpClient.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + if err = json.NewDecoder(resp.Body).Decode(&departures); err != nil { + return nil, err + } + return +} |