-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathflat_feed.go
83 lines (73 loc) · 3.14 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
74
75
76
77
78
79
80
81
82
83
package stream
import (
"context"
"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(ctx context.Context, opts ...GetActivitiesOption) (*FlatFeedResponse, error) {
body, err := f.client.getActivities(ctx, 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(ctx context.Context, resp *FlatFeedResponse) (*FlatFeedResponse, error) {
opts, err := resp.parseNext()
if err != nil {
return nil, err
}
return f.GetActivities(ctx, opts...)
}
// GetActivitiesWithRanking returns the activities (filtered) for the given FlatFeed,
// using the provided ranking method.
func (f *FlatFeed) GetActivitiesWithRanking(ctx context.Context, ranking string, opts ...GetActivitiesOption) (*FlatFeedResponse, error) {
return f.GetActivities(ctx, append(opts, WithActivitiesRanking(ranking))...)
}
// GetFollowers returns the feeds following the given FlatFeed.
func (f *FlatFeed) GetFollowers(ctx context.Context, opts ...FollowersOption) (*FollowersResponse, error) {
return f.client.getFollowers(ctx, f, opts...)
}
// GetEnrichedActivities returns the enriched activities for the given FlatFeed, filtering
// results with the provided GetActivitiesOption parameters.
func (f *FlatFeed) GetEnrichedActivities(ctx context.Context, opts ...GetActivitiesOption) (*EnrichedFlatFeedResponse, error) {
body, err := f.client.getEnrichedActivities(ctx, 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(ctx context.Context, resp *EnrichedFlatFeedResponse) (*EnrichedFlatFeedResponse, error) {
opts, err := resp.parseNext()
if err != nil {
return nil, err
}
return f.GetEnrichedActivities(ctx, opts...)
}
// GetEnrichedActivitiesWithRanking returns the enriched activities (filtered) for the given FlatFeed,
// using the provided ranking method.
func (f *FlatFeed) GetEnrichedActivitiesWithRanking(ctx context.Context, ranking string, opts ...GetActivitiesOption) (*EnrichedFlatFeedResponse, error) {
return f.GetEnrichedActivities(ctx, append(opts, WithActivitiesRanking(ranking))...)
}
// FollowStats returns the follower/following counts of the feed.
// If options are given, counts are filtered for the given slugs.
// Counts will be capped at 10K, if higher counts are needed and contact to support.
func (f *FlatFeed) FollowStats(ctx context.Context, opts ...FollowStatOption) (*FollowStatResponse, error) {
return f.client.followStats(ctx, f, opts...)
}