-
Notifications
You must be signed in to change notification settings - Fork 0
/
realtime_client.go
40 lines (30 loc) · 1.01 KB
/
realtime_client.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
// this is obviously a work in progress.
package awn
const (
// apiVersionRealtime is a string and describes the version of the real-time API.
apiVersionRealtime = "/api=1"
// baseUrlRealtime The base URL for the Ambient Weather real-time API as a string.
baseURLRealtime = "wss://rt2.ambientweather.net"
)
// GetRealtimeData is a public function that will connect to the Ambient Weather real-time
// weather API via Websockets and fetch live data.
func GetRealtimeData() (string, error) {
/*
https://ambientweather.docs.apiary.io/#reference/ambient-realtime-api
setup: https://rt2.ambientweather.net/?api=1&applicationKey=AppKey
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
c, _, err := websocket.Dial(ctx, "ws://localhost:8080", nil)
if err != nil {
// ...
}
defer c.CloseNow()
err = wsjson.Write(ctx, c, "hi")
if err != nil {
// ...
}
c.Close(websocket.StatusNormalClosure, "")
*/
url := baseURLRealtime + apiVersionRealtime
return url, nil
}