-
Notifications
You must be signed in to change notification settings - Fork 14
/
feed_general.go
77 lines (61 loc) · 2.24 KB
/
feed_general.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
package getstream
// GeneralFeed is a container for Feeds returned from request
// The specific Type will be unknown so no Actions are associated with a GeneralFeed
type GeneralFeed struct {
Client *Client
FeedSlug string
UserID string
token string
}
// Signature is used to sign Requests : "FeedSlugUserID Token"
func (f *GeneralFeed) Signature() string {
if f.Token() == "" {
return f.FeedIDWithoutColon()
}
return f.FeedIDWithoutColon() + " " + f.Token()
}
// FeedID is the combo if the FeedSlug and UserID : "FeedSlug:UserID"
func (f *GeneralFeed) FeedID() FeedID {
return FeedID(f.FeedSlug + ":" + f.UserID)
}
func (f *GeneralFeed) FeedIDWithoutColon() string {
return f.FeedSlug + f.UserID
}
// SignFeed sets the token on a Feed
func (f *GeneralFeed) SignFeed(signer *Signer) {
if f.Client.Signer != nil {
f.token = signer.GenerateToken(f.FeedIDWithoutColon())
}
}
// Token returns the token of a Feed
func (f *GeneralFeed) Token() string {
return f.token
}
// GenerateToken returns a new Token for a Feed without setting it to the Feed
func (f *GeneralFeed) GenerateToken(signer *Signer) string {
if f.Client.Signer != nil {
return signer.GenerateToken(f.FeedSlug + f.UserID)
}
return ""
}
// Unfollow is used to Unfollow a target Feed
func (f *GeneralFeed) Unfollow(client *Client, target *FlatFeed) error {
f.Client = client
f.SignFeed(f.Client.Signer)
endpoint := "feed/" + f.FeedSlug + "/" + f.UserID + "/" + "following" + "/" + target.FeedID().Value() + "/"
return f.Client.del(f, endpoint, nil, nil)
}
// UnfollowAggregated is used to Unfollow a target Aggregated Feed
func (f *GeneralFeed) UnfollowAggregated(client *Client, target *AggregatedFeed) error {
f.Client = client
f.SignFeed(f.Client.Signer)
endpoint := "feed/" + f.FeedSlug + "/" + f.UserID + "/" + "following" + "/" + target.FeedID().Value() + "/"
return f.Client.del(f, endpoint, nil, nil)
}
// UnfollowNotification is used to Unfollow a target Notification Feed
func (f *GeneralFeed) UnfollowNotification(client *Client, target *NotificationFeed) error {
f.Client = client
f.SignFeed(f.Client.Signer)
endpoint := "feed/" + f.FeedSlug + "/" + f.UserID + "/" + "following" + "/" + target.FeedID().Value() + "/"
return f.Client.del(f, endpoint, nil, nil)
}