diff options
author | Julien Dessaux | 2021-09-08 15:23:50 +0200 |
---|---|---|
committer | Julien Dessaux | 2021-09-08 16:12:01 +0200 |
commit | 3c5e31b25a53268b413bc1e511b7486a2a1c80b9 (patch) | |
tree | f6fe9a82eab8abf7a01f84bce954edc7462f87a2 /pkg/navitia_api_client/train_stops.go | |
parent | Removed useless user model code (diff) | |
download | trains-3c5e31b25a53268b413bc1e511b7486a2a1c80b9.tar.gz trains-3c5e31b25a53268b413bc1e511b7486a2a1c80b9.tar.bz2 trains-3c5e31b25a53268b413bc1e511b7486a2a1c80b9.zip |
Renamed TrainStop to simply Stop
Diffstat (limited to 'pkg/navitia_api_client/train_stops.go')
-rw-r--r-- | pkg/navitia_api_client/train_stops.go | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/pkg/navitia_api_client/train_stops.go b/pkg/navitia_api_client/train_stops.go deleted file mode 100644 index a31ccf7..0000000 --- a/pkg/navitia_api_client/train_stops.go +++ /dev/null @@ -1,70 +0,0 @@ -package navitia_api_client - -import ( - "encoding/json" - "fmt" - "net/http" - - "git.adyxax.org/adyxax/trains/pkg/model" -) - -type TrainStopsResponse struct { - Pagination struct { - StartPage int `json:"start_page"` - ItemsOnPage int `json:"items_on_page"` - ItemsPerPage int `json:"items_per_page"` - TotalResult int `json:"total_result"` - } `json:"pagination"` - StopAreas []struct { - Name string `json:"name"` - ID string `json:"id"` - Codes []interface{} `json:"codes"` - Links []interface{} `json:"links"` - Coord interface{} `json:"coord"` - Label string `json:"label"` - Timezone interface{} `json:"timezone"` - AdministrativeRegion interface{} `json:"administrative_regions"` - } `json:"stop_areas"` - Links []interface{} `json:"links"` - Disruptions []interface{} `json:"disruptions"` - FeedPublishers []interface{} `json:"feed_publishers"` - Context interface{} `json:"context"` -} - -func (c *NavitiaClient) GetTrainStops() (trainStops []model.TrainStop, err error) { - return getTrainStopsPage(c, 0) -} - -func getTrainStopsPage(c *NavitiaClient, i int) (trainStops []model.TrainStop, err error) { - request := fmt.Sprintf("%s/coverage/sncf/stop_areas?count=1000&start_page=%d", c.baseURL, i) - req, err := http.NewRequest("GET", request, nil) - if err != nil { - return nil, newHttpClientError("http.NewRequest error", err) - } - resp, err := c.httpClient.Do(req) - if err != nil { - return nil, newHttpClientError("httpClient.Do error", err) - } - defer resp.Body.Close() - if resp.StatusCode == http.StatusOK { - var data TrainStopsResponse - if err = json.NewDecoder(resp.Body).Decode(&data); err != nil { - return nil, newJsonDecodeError("GetTrainStops ", err) - } - for i := 0; i < len(data.StopAreas); i++ { - if data.StopAreas[i].Label != "" { - trainStops = append(trainStops, model.TrainStop{data.StopAreas[i].ID, data.StopAreas[i].Label}) - } - } - if data.Pagination.ItemsOnPage+data.Pagination.ItemsPerPage*data.Pagination.StartPage < data.Pagination.TotalResult { - tss, err := getTrainStopsPage(c, i+1) - if err != nil { - return nil, err - } - trainStops = append(trainStops, tss...) - } - } else { - err = newApiError(resp.StatusCode, "GetTrainStops") - } - return -} |