-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathaggregated_feed.go
72 lines (64 loc) · 2.71 KB
/
aggregated_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
package stream
import (
"context"
"encoding/json"
)
// AggregatedFeed is a Stream aggregated feed, which contains activities grouped
// based on the grouping function defined on the dashboard.
type AggregatedFeed struct {
feed
}
// GetActivities requests and retrieves the activities and groups for the
// aggregated feed.
func (f *AggregatedFeed) GetActivities(ctx context.Context, opts ...GetActivitiesOption) (*AggregatedFeedResponse, error) {
body, err := f.client.getActivities(ctx, f, opts...)
if err != nil {
return nil, err
}
var resp AggregatedFeedResponse
if err := json.Unmarshal(body, &resp); err != nil {
return nil, err
}
return &resp, nil
}
// GetActivitiesWithRanking returns the activities and groups for the given AggregatedFeed,
// using the provided ranking method.
func (f *AggregatedFeed) GetActivitiesWithRanking(ctx context.Context, ranking string, opts ...GetActivitiesOption) (*AggregatedFeedResponse, error) {
return f.GetActivities(ctx, append(opts, WithActivitiesRanking(ranking))...)
}
// GetNextPageActivities returns the activities for the given AggregatedFeed at the "next" page
// of a previous *AggregatedFeedResponse response, if any.
func (f *AggregatedFeed) GetNextPageActivities(ctx context.Context, resp *AggregatedFeedResponse) (*AggregatedFeedResponse, error) {
opts, err := resp.parseNext()
if err != nil {
return nil, err
}
return f.GetActivities(ctx, opts...)
}
// GetEnrichedActivities requests and retrieves the enriched activities and groups for the
// aggregated feed.
func (f *AggregatedFeed) GetEnrichedActivities(ctx context.Context, opts ...GetActivitiesOption) (*EnrichedAggregatedFeedResponse, error) {
body, err := f.client.getEnrichedActivities(ctx, f, opts...)
if err != nil {
return nil, err
}
var resp EnrichedAggregatedFeedResponse
if err := json.Unmarshal(body, &resp); err != nil {
return nil, err
}
return &resp, nil
}
// GetNextPageEnrichedActivities returns the enriched activities for the given AggregatedFeed at the "next" page
// of a previous *EnrichedAggregatedFeedResponse response, if any.
func (f *AggregatedFeed) GetNextPageEnrichedActivities(ctx context.Context, resp *EnrichedAggregatedFeedResponse) (*EnrichedAggregatedFeedResponse, error) {
opts, err := resp.parseNext()
if err != nil {
return nil, err
}
return f.GetEnrichedActivities(ctx, opts...)
}
// GetEnrichedActivitiesWithRanking returns the enriched activities and groups for the given AggregatedFeed,
// using the provided ranking method.
func (f *AggregatedFeed) GetEnrichedActivitiesWithRanking(ctx context.Context, ranking string, opts ...GetActivitiesOption) (*EnrichedAggregatedFeedResponse, error) {
return f.GetEnrichedActivities(ctx, append(opts, WithActivitiesRanking(ranking))...)
}