-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraffic_speed_bands.go
More file actions
62 lines (55 loc) · 1.81 KB
/
Copy pathtraffic_speed_bands.go
File metadata and controls
62 lines (55 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package ltadatamall
import (
"errors"
"strconv"
)
type AllTrafficSpeedBandsResponse struct {
Metadata string `json:"odata.metadata"`
LastUpdatedTime string `json:"lastUpdatedTime"`
TrafficSpeedBands []TrafficSpeedBand `json:"value"`
}
type TrafficSpeedBand struct {
LinkID string `json:"LinkID"`
RoadName string `json:"RoadName"`
RoadCategory string `json:"RoadCategory"`
SpeedBand int `json:"SpeedBand"`
MinimumSpeed string `json:"MinimumSpeed"`
MaximumSpeed string `json:"MaximumSpeed"`
StartLon string `json:"StartLon"`
StartLat string `json:"StartLat"`
EndLon string `json:"EndLon"`
EndLat string `json:"EndLat"`
}
func GetTrafficSpeedBandsPaginated(apiClient *APIClient, skip int) (AllTrafficSpeedBandsResponse, error) {
var result AllTrafficSpeedBandsResponse
endpoint := "v4/TrafficSpeedBands?$skip=" + strconv.Itoa(skip)
if err := apiClient.getJSON(endpoint, &result); err != nil {
return AllTrafficSpeedBandsResponse{}, err
}
if len(result.TrafficSpeedBands) == 0 {
return AllTrafficSpeedBandsResponse{}, errors.New("no TrafficSpeedBands found")
}
return result, nil
}
func GetAllTrafficSpeedBands(apiClient *APIClient) (AllTrafficSpeedBandsResponse, error) {
var trafficSpeedBands []TrafficSpeedBand
// Keep fetching until all records are retrieved
errorCount := 0
pagination := 0
var res AllTrafficSpeedBandsResponse
for errorCount < 1 {
res, err := GetTrafficSpeedBandsPaginated(apiClient, pagination)
if err != nil {
errorCount++
break
}
pagination += 500
trafficSpeedBands = append(trafficSpeedBands, res.TrafficSpeedBands...)
}
result := AllTrafficSpeedBandsResponse{
TrafficSpeedBands: trafficSpeedBands,
Metadata: res.Metadata,
LastUpdatedTime: res.LastUpdatedTime,
}
return result, nil
}