forked from GetStream/stream-go2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flat_feed.go
73 lines (64 loc) · 2.58 KB
/
flat_feed.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
package stream
import "encoding/json"
// FlatFeed is a Stream flat feed.
type FlatFeed struct {
feed
}
// GetActivities returns the activities for the given FlatFeed, filtering
// results with the provided GetActivitiesOption parameters.
func (f *FlatFeed) GetActivities(opts ...GetActivitiesOption) (*FlatFeedResponse, error) {
body, err := f.client.getActivities(f, opts...)
if err != nil {
return nil, err
}
var resp FlatFeedResponse
if err := json.Unmarshal(body, &resp); err != nil {
return nil, err
}
return &resp, nil
}
// GetNextPageActivities returns the activities for the given FlatFeed at the "next" page
// of a previous *FlatFeedResponse response, if any.
func (f *FlatFeed) GetNextPageActivities(resp *FlatFeedResponse) (*FlatFeedResponse, error) {
opts, err := resp.parseNext()
if err != nil {
return nil, err
}
return f.GetActivities(opts...)
}
// GetActivitiesWithRanking returns the activities (filtered) for the given FlatFeed,
// using the provided ranking method.
func (f *FlatFeed) GetActivitiesWithRanking(ranking string, opts ...GetActivitiesOption) (*FlatFeedResponse, error) {
return f.GetActivities(append(opts, withActivitiesRanking(ranking))...)
}
// GetFollowers returns the feeds following the given FlatFeed.
func (f *FlatFeed) GetFollowers(opts ...FollowersOption) (*FollowersResponse, error) {
return f.client.getFollowers(f, opts...)
}
// GetEnrichedActivities returns the enriched activities for the given FlatFeed, filtering
// results with the provided GetActivitiesOption parameters.
func (f *FlatFeed) GetEnrichedActivities(opts ...GetActivitiesOption) (*EnrichedFlatFeedResponse, error) {
body, err := f.client.getEnrichedActivities(f, opts...)
if err != nil {
return nil, err
}
var resp EnrichedFlatFeedResponse
if err := json.Unmarshal(body, &resp); err != nil {
return nil, err
}
return &resp, nil
}
// GetNextPageEnrichedActivities returns the enriched activities for the given FlatFeed at the "next" page
// of a previous *EnrichedFlatFeedResponse response, if any.
func (f *FlatFeed) GetNextPageEnrichedActivities(resp *EnrichedFlatFeedResponse) (*EnrichedFlatFeedResponse, error) {
opts, err := resp.parseNext()
if err != nil {
return nil, err
}
return f.GetEnrichedActivities(opts...)
}
// GetEnrichedActivitiesWithRanking returns the enriched activities (filtered) for the given FlatFeed,
// using the provided ranking method.
func (f *FlatFeed) GetEnrichedActivitiesWithRanking(ranking string, opts ...GetActivitiesOption) (*EnrichedFlatFeedResponse, error) {
return f.GetEnrichedActivities(append(opts, withActivitiesRanking(ranking))...)
}