-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlocations.go
90 lines (76 loc) · 1.72 KB
/
locations.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
package api
import "context"
type Location struct {
Type string
ID string
Name string
Location struct {
Type string
ID string
Latitude float64
Longitude float64
}
Products map[string]bool
StationDHID string
}
type locationsQuery struct {
c *Client
query string
fuzzy bool
results int
stops bool
addresses bool
poi bool
linesOfStops bool
language string
}
func (c *Client) Locations(query string) *locationsQuery {
return &locationsQuery{
c: c,
query: query,
fuzzy: true,
results: 10,
stops: true,
addresses: true,
poi: true,
linesOfStops: false,
language: "en",
}
}
func (q *locationsQuery) Do(ctx context.Context) ([]Location, error) {
const u = "/locations?query=%s&fuzzy=%t&results=%d&stops=%t&addresses=%t&poi=%t&linesOfStops=%t&language=%s&pretty=false"
var locs []Location
err := q.c.getJSON(ctx, &locs, u, q.query, q.fuzzy, q.results, q.stops, q.addresses, q.poi, q.linesOfStops, q.language)
if err != nil {
return nil, err
}
return locs, nil
}
func (q *locationsQuery) Fuzzy(f bool) *locationsQuery {
q.fuzzy = f
return q
}
func (q *locationsQuery) Results(r int) *locationsQuery {
q.results = r
return q
}
func (q *locationsQuery) Stops(s bool) *locationsQuery {
q.stops = s
return q
}
func (q *locationsQuery) Addresses(a bool) *locationsQuery {
q.addresses = a
return q
}
func (q *locationsQuery) POI(p bool) *locationsQuery {
q.poi = p
return q
}
func (q *locationsQuery) LinesOfStops(l bool) *locationsQuery {
q.linesOfStops = l
return q
}
func (q *locationsQuery) Language(l string) *locationsQuery {
q.language = l
return q
}