-
Notifications
You must be signed in to change notification settings - Fork 0
/
measurements.go
50 lines (44 loc) · 1.17 KB
/
measurements.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
package airly
import (
"fmt"
"net/url"
)
// Measurements holds measurements data.
type Measurements struct {
Current *AveragedValues `json:"current"`
}
type AveragedValues struct {
Values []*Value `json:"values"`
Indexes []*Index `json:"indexes"`
}
type Value struct {
Name string `json:"name"`
Value float64 `json:"value"`
}
type Index struct {
Name string `json:"name"`
Value float64 `json:"value"`
Level string `json:"level"`
Description string `json:"description"`
Advice string `json:"advice"`
Color string `json:"color"`
}
// NearestMeasurements returns measurements for an installation closest to a given location.
func (c *Client) NearestMeasurements(lat, lon float64, dist float32) (*Measurements, error) {
u, _ := url.Parse("v2/measurements/nearest")
u = c.BaseURL.ResolveReference(u)
q := u.Query()
q.Set("lat", fmt.Sprintf("%f", lat))
q.Set("lng", fmt.Sprintf("%f", lon))
q.Set("maxDistanceKM", fmt.Sprintf("%f", dist))
u.RawQuery = q.Encode()
req, err := c.NewRequest(u.String())
if err != nil {
return nil, err
}
v := &Measurements{}
if err := c.Do(req, v); err != nil {
return nil, err
}
return v, nil
}