-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstopsnearby.go
93 lines (79 loc) · 1.79 KB
/
stopsnearby.go
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package api
import (
"context"
"strconv"
)
type StopNearby struct {
Type string
ID string
Name string
Location struct {
Type string
ID string
Latitude float64
Longitude float64
}
Products map[string]bool
Distance int
}
type stopsNearbyQuery struct {
c *Client
latitude float64
longitude float64
results int
distance int
stops bool
poi bool
linesOfStops bool
language string
}
func (c *Client) StopsNearby(latitude, longitude float64) *stopsNearbyQuery {
return &stopsNearbyQuery{
c: c,
latitude: latitude,
longitude: longitude,
results: 8,
distance: -1,
stops: true,
poi: false,
linesOfStops: false,
language: "en",
}
}
func (q *stopsNearbyQuery) Do(ctx context.Context) ([]StopNearby, error) {
const u = "/stops/nearby?latitude=%f&longitude=%f&results=%d&distance=%s&stops=%t&poi=%t&linesOfStops=%t&language=%s&pretty=false"
distance := ""
if q.distance > 0 {
distance = strconv.Itoa(q.distance)
}
var stops []StopNearby
err := q.c.getJSON(ctx, &stops, u, q.latitude, q.longitude, q.results, distance, q.stops, q.poi, q.linesOfStops, q.language)
if err != nil {
return nil, err
}
return stops, nil
}
func (q *stopsNearbyQuery) Results(r int) *stopsNearbyQuery {
q.results = r
return q
}
func (q *stopsNearbyQuery) Distance(d int) *stopsNearbyQuery {
q.distance = d
return q
}
func (q *stopsNearbyQuery) Stops(s bool) *stopsNearbyQuery {
q.stops = s
return q
}
func (q *stopsNearbyQuery) POI(p bool) *stopsNearbyQuery {
q.poi = p
return q
}
func (q *stopsNearbyQuery) LinesOfStops(l bool) *stopsNearbyQuery {
q.linesOfStops = l
return q
}
func (q *stopsNearbyQuery) Language(l string) *stopsNearbyQuery {
q.language = l
return q
}