-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
83 lines (69 loc) · 2.28 KB
/
user.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
package wifire
import (
"encoding/json"
"net/http"
)
type getUserDataResponse struct {
UserID string `json:"userId"`
GivenName string `json:"givenName"`
FamiltyName string `json:"familyName"`
FullName string `json:"fullName"`
Email string `json:"email"`
Username string `json:"username"`
Cognito string `json:"cognito"`
CustomerID string `json:"customerId"`
UrbanAirshipID string `json:"urbanAirshipId"`
Teams []team `json:"teams"`
Things []thing `json:"things"`
}
type team struct {
ID string `json:"teamID"`
Name string `json:"teamName"`
}
type thing struct {
Name string `json:"thingName"`
FriendlyName string `json:"friendlyName"`
DeviceTypeID string `json:"deviceTypeId"`
UserID string `json:"userId"`
Status string `json:"status"`
ProductID string `json:"productId"`
GrillModel grillModel `json:"grillModel"`
}
type grillModel struct {
ModuelNumber string `json:"modelNumber"`
Group string `json:"group"`
IOTCapable bool `json:"iotCapable"`
Make string `json:"make"`
IsTraeger bool `json:"isTraegerBrand"`
Region string `json:"regionIso"`
DeviceTypeID string `json:"deviceTypeId"`
Image image `json:"image"`
OwnersManualURL string `json:"ownersManualUrl"`
Name string `json:"name"`
Description string `json:"description"`
ReferenceProductID string `json:"referenceProductId"`
}
type image struct {
DefaultHost string `json:"defaultHost"`
Endpoint string `json:"endpoint"`
Name string `json:"name"`
}
// UserData fetches the /prod/users/self information from the WiFire API.
func (w WiFire) UserData() (*getUserDataResponse, error) { //nolint:revive // response is read only user doesn't need to create a new struct
client := http.Client{}
req, err := http.NewRequest("GET", w.config.baseURL+"/prod/users/self", http.NoBody)
if err != nil {
return nil, err
}
req.Header.Set("authorization", w.token)
r, err := client.Do(req)
if err != nil {
return nil, err
}
defer r.Body.Close()
var data getUserDataResponse
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}