aboutsummaryrefslogtreecommitdiff
path: root/navitia_api_client/departures.go
diff options
context:
space:
mode:
authorJulien Dessaux2021-04-05 17:52:31 +0200
committerJulien Dessaux2021-04-05 17:52:31 +0200
commit1ffc9c42054e208a01d3e70e6b6f3e1781e798f8 (patch)
tree721f202dcf46fb5e9c181013237e4da9d27f796a /navitia_api_client/departures.go
parentReworked error handling for better and simpler tests (diff)
downloadtrains-1ffc9c42054e208a01d3e70e6b6f3e1781e798f8.tar.gz
trains-1ffc9c42054e208a01d3e70e6b6f3e1781e798f8.tar.bz2
trains-1ffc9c42054e208a01d3e70e6b6f3e1781e798f8.zip
Moved code around to conform best practices
Diffstat (limited to 'navitia_api_client/departures.go')
-rw-r--r--navitia_api_client/departures.go73
1 files changed, 0 insertions, 73 deletions
diff --git a/navitia_api_client/departures.go b/navitia_api_client/departures.go
deleted file mode 100644
index 7738940..0000000
--- a/navitia_api_client/departures.go
+++ /dev/null
@@ -1,73 +0,0 @@
-package navitia_api_client
-
-import (
- "encoding/json"
- "fmt"
- "net/http"
- "time"
-)
-
-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) {
- request := fmt.Sprintf("%s/coverage/sncf/stop_areas/stop_area:SNCF:87723502/departures", c.baseURL)
- start := time.Now()
- c.mutex.Lock()
- defer c.mutex.Unlock()
- if cachedResult, ok := c.cache[request]; ok {
- if start.Sub(cachedResult.ts) < 60*1000*1000*1000 {
- return cachedResult.result.(*DeparturesResponse), nil
- }
- }
- req, err := http.NewRequest("GET", request, 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
- }
- c.cache[request] = cachedResult{
- ts: start,
- result: departures,
- }
- return
-}