-
Notifications
You must be signed in to change notification settings - Fork 0
/
sessions.go
49 lines (45 loc) · 1.11 KB
/
sessions.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
package hwapi
import (
"encoding/json"
"fmt"
)
// DeleteSessions Delete all sessions associated with a user
func (api *HWApi) DeleteSessions(accountHash string, uid int) (bool, error) {
_, e := api.Request(
&Request{
Method: DELETE,
URL: fmt.Sprintf("/api/v1/accounts/%s/users/%d/sessions", accountHash, uid),
},
)
if e != nil {
return false, e
}
return true, nil
}
// GetSessions Fetch all sessions associated with a user
func (api *HWApi) GetSessions(accountHash string, uid int) (*AccessTokenList, error) {
r, e := api.Request(
&Request{
Method: GET,
URL: fmt.Sprintf("/api/v1/accounts/%s/users/%d/sessions", accountHash, uid),
},
)
if e != nil {
return nil, e
}
al := &AccessTokenList{}
return al, json.Unmarshal(r.body, al)
}
// DeleteSession Delete a session associated with a user
func (api *HWApi) DeleteSession(accountHash string, uid int, tokenID string) (bool, error) {
_, e := api.Request(
&Request{
Method: DELETE,
URL: fmt.Sprintf("/api/v1/accounts/%s/users/%d/sessions/%s", accountHash, uid, tokenID),
},
)
if e != nil {
return false, e
}
return true, nil
}