-
Notifications
You must be signed in to change notification settings - Fork 13
/
relationships.go
74 lines (62 loc) · 1.84 KB
/
relationships.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
package mixin
import (
"context"
)
const (
RelationshipActionAdd = "ADD"
RelationshipActionRemove = "Remove"
RelationshipActionUpdate = "UPDATE"
RelationshipActionBlock = "BLOCK"
RelationshipActionUnblock = "UNBLOCK"
)
type RelationshipRequest struct {
UserID string `json:"user_id,omitempty"`
FullName string `json:"full_name,omitempty"`
Action string `json:"action,omitempty"`
}
func (c *Client) UpdateRelationship(ctx context.Context, req RelationshipRequest) (*User, error) {
var resp User
if err := c.Post(ctx, "/relationships", req, &resp); err != nil {
return nil, err
}
return &resp, nil
}
func (c *Client) AddFriend(ctx context.Context, userID, remark string) (*User, error) {
return c.UpdateRelationship(ctx, RelationshipRequest{
UserID: userID,
FullName: remark,
Action: RelationshipActionAdd,
})
}
func (c *Client) RemoveFriend(ctx context.Context, userID string) (*User, error) {
return c.UpdateRelationship(ctx, RelationshipRequest{
UserID: userID,
Action: RelationshipActionRemove,
})
}
func (c *Client) RemarkFriend(ctx context.Context, userID, remark string) (*User, error) {
return c.UpdateRelationship(ctx, RelationshipRequest{
UserID: userID,
FullName: remark,
Action: RelationshipActionUpdate,
})
}
func (c *Client) BlockUser(ctx context.Context, userID string) (*User, error) {
return c.UpdateRelationship(ctx, RelationshipRequest{
UserID: userID,
Action: RelationshipActionBlock,
})
}
func (c *Client) UnblockUser(ctx context.Context, userID string) (*User, error) {
return c.UpdateRelationship(ctx, RelationshipRequest{
UserID: userID,
Action: RelationshipActionUnblock,
})
}
func (c *Client) ListBlockingUsers(ctx context.Context) ([]*User, error) {
var users []*User
if err := c.Get(ctx, "/blocking_users", nil, &users); err != nil {
return nil, err
}
return users, nil
}