-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtado.go
37 lines (31 loc) · 854 Bytes
/
tado.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
package gotado
import "context"
type Tado struct {
client *client
}
// New creates a new tado client.
func New(clientID, clientSecret string) *Tado {
return &Tado{
client: newClient(clientID, clientSecret),
}
}
func (t *Tado) authenticate(ctx context.Context, username, password string) error {
if client, err := t.client.WithCredentials(ctx, username, password); err != nil {
return err
} else {
t.client = client
return nil
}
}
// Me authenticates with the given credentials and returns information about the
// authenticated user.
func (t *Tado) Me(ctx context.Context, username, password string) (*User, error) {
if err := t.authenticate(ctx, username, password); err != nil {
return nil, err
}
me := &User{client: t.client}
if err := t.client.get(ctx, apiURL("me"), me); err != nil {
return nil, err
}
return me, nil
}