-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtypes.go
807 lines (690 loc) · 22.6 KB
/
types.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
package stream
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
"strconv"
"strings"
"time"
"github.com/mitchellh/mapstructure"
)
// Duration wraps time.Duration, used because of JSON marshaling and
// unmarshaling.
type Duration struct {
time.Duration
}
// UnmarshalJSON for Duration is required because of the incoming duration string.
func (d *Duration) UnmarshalJSON(b []byte) error {
var tmp any
err := json.Unmarshal(b, &tmp)
if err != nil {
return err
}
switch v := tmp.(type) {
case string:
*d, err = durationFromString(v)
case float64:
*d, err = durationFromString(fmt.Sprintf("%fs", v))
default:
err = errors.New("invalid duration")
}
return err
}
// MarshalJSON marshals the Duration to a string like "30s".
func (d Duration) MarshalJSON() ([]byte, error) {
return json.Marshal(d.String())
}
func durationFromString(s string) (Duration, error) {
dd, err := time.ParseDuration(s)
return Duration{dd}, err
}
// Time wraps time.Time, used because of custom API time format in JSON marshaling
// and unmarshaling.
type Time struct {
time.Time
}
// UnmarshalJSON for Time is required because of the incoming time string format.
func (t *Time) UnmarshalJSON(b []byte) error {
var err error
*t, err = timeFromString(strings.ReplaceAll(string(b), `"`, ""))
return err
}
// MarshalJSON marshals Time (NOTE! in UTC) into a string formatted with the TimeLayout format.
func (t Time) MarshalJSON() ([]byte, error) {
return json.Marshal(t.UTC().Format(TimeLayout))
}
func timeFromString(s string) (Time, error) {
var err error
for _, layout := range timeLayouts {
var tt time.Time
tt, err = time.Parse(layout, s)
if err == nil {
return Time{tt}, nil
}
}
return Time{}, err
}
// Data is a representation of an enriched activities enriched object,
// such as the the user or the object
type Data struct {
ID string `json:"id"`
Extra map[string]any `json:"-"`
}
func (a *Data) decode(data map[string]any) error {
// We are not using decodeData here because we do not need the DecodeHook
// since it leads to a stack overflow
cfg := &mapstructure.DecoderConfig{
Result: a,
Metadata: &mapstructure.Metadata{},
TagName: "json",
}
dec, err := mapstructure.NewDecoder(cfg)
if err != nil {
return err
}
if err := dec.Decode(data); err != nil {
return err
}
if len(cfg.Metadata.Unused) > 0 {
a.Extra = make(map[string]any)
for _, k := range cfg.Metadata.Unused {
a.Extra[k] = data[k]
}
}
return nil
}
// MarshalJSON encodes data into json.
func (a Data) MarshalJSON() ([]byte, error) {
m := make(map[string]any, len(a.Extra))
for k, v := range a.Extra {
m[k] = v
}
result := map[string]any{
"id": a.ID,
"data": m,
}
return json.Marshal(result)
}
// Rate is the information to be filled if a rate limited response
type Rate struct {
// Reset is the time for limit to reset
Reset Time
// Limit is the existing limit for the resource
Limit int
// Remaining is the remaining possible calls
Remaining int
}
func NewRate(headers http.Header) *Rate {
var r Rate
limit, err := strconv.Atoi(headers.Get(HeaderRateLimit))
if err == nil {
r.Limit = limit
}
remaining, err := strconv.Atoi(headers.Get(HeaderRateRemaining))
if err == nil {
r.Remaining = remaining
}
reset, err := strconv.ParseInt(headers.Get(HeaderRateReset), 10, 64)
if err == nil && reset > 0 {
r.Reset = Time{Time: time.Unix(reset, 0)}
}
return &r
}
// Response is the part of StreamAPI responses common throughout the API.
type response struct {
Rate Rate `json:"ratelimit,omitempty"`
Duration Duration `json:"duration,omitempty"`
}
type BaseResponse struct {
response
}
// readResponse is the part of StreamAPI responses common for GetActivities API requests.
type readResponse struct {
response
Next string `json:"next,omitempty"`
}
var (
// ErrMissingNextPage is returned when trying to read the next page of a response
// which has an empty "next" field.
ErrMissingNextPage = errors.New("request missing next page")
// ErrInvalidNextPage is returned when trying to read the next page of a response
// which has an invalid "next" field.
ErrInvalidNextPage = errors.New("invalid format for Next field")
)
func (r readResponse) parseNext() ([]GetActivitiesOption, error) {
if r.Next == "" {
return nil, ErrMissingNextPage
}
urlParts := strings.Split(r.Next, "?")
if len(urlParts) != 2 {
return nil, ErrInvalidNextPage
}
values, err := url.ParseQuery(urlParts[1])
if err != nil {
return nil, ErrInvalidNextPage
}
var opts []GetActivitiesOption
limit, ok, err := parseIntValue(values, "limit")
if err != nil {
return nil, err
}
if ok {
opts = append(opts, WithActivitiesLimit(limit))
}
offset, ok, err := parseIntValue(values, "offset")
if err != nil {
return nil, err
}
if ok {
opts = append(opts, WithActivitiesOffset(offset))
}
if idLT := values.Get("id_lt"); idLT != "" {
opts = append(opts, WithActivitiesIDLT(idLT))
}
if ranking := values.Get("ranking"); ranking != "" {
opts = append(opts, WithActivitiesRanking(ranking))
}
if enrichOpt := values.Get("withOwnReactions"); parseBool(enrichOpt) {
opts = append(opts, WithEnrichOwnReactions())
}
if enrichOpt := values.Get("user_id"); enrichOpt != "" {
opts = append(opts, WithEnrichUserReactions(enrichOpt))
}
if enrichOpt := values.Get("withFirstReactions"); parseBool(enrichOpt) {
opts = append(opts, WithEnrichFirstReactions())
}
if enrichOpt := values.Get("withRecentReactions"); parseBool(enrichOpt) {
opts = append(opts, WithEnrichRecentReactions())
}
if enrichOpt := values.Get("withReactionCounts"); parseBool(enrichOpt) {
opts = append(opts, WithEnrichReactionCounts())
}
if enrichOpt := values.Get("withOwnChildren"); parseBool(enrichOpt) {
opts = append(opts, WithEnrichOwnChildren())
}
reactionsLimit, ok, err := parseIntValue(values, "recentReactionsLimit")
if err != nil {
return nil, err
} else if ok {
opts = append(opts, WithEnrichRecentReactionsLimit(reactionsLimit))
}
reactionsLimit, ok, err = parseIntValue(values, "reaction_limit")
if err != nil {
return nil, err
} else if ok {
opts = append(opts, WithEnrichReactionsLimit(reactionsLimit))
}
if enrichOpt := values.Get("reactionKindsFilter"); enrichOpt != "" {
kinds := strings.Split(enrichOpt, ",")
opts = append(opts, WithEnrichReactionKindsFilter(kinds...))
}
if enrichOpt := values.Get("withOwnChildrenKinds"); enrichOpt != "" {
kinds := strings.Split(enrichOpt, ",")
opts = append(opts, WithEnrichOwnChildrenKindsFilter(kinds...))
}
return opts, nil
}
// baseNotificationFeedResponse is the common part of responses obtained from reading normal or enriched notification feeds.
type baseNotificationFeedResponse struct {
readResponse
Unseen int `json:"unseen"`
Unread int `json:"unread"`
}
// baseNotificationFeedResult is the common part of responses obtained from reading normal or enriched notification feeds.
type baseNotificationFeedResult struct {
ID string `json:"id"`
ActivityCount int `json:"activity_count"`
ActorCount int `json:"actor_count"`
Group string `json:"group"`
IsRead bool `json:"is_read"`
IsSeen bool `json:"is_seen"`
Verb string `json:"verb"`
CreatedAt Time `json:"created_at"`
UpdatedAt Time `json:"updated_at"`
}
// FlatFeedResponse is the API response obtained when retrieving activities from
// a flat feed.
type FlatFeedResponse struct {
readResponse
Results []Activity `json:"results,omitempty"`
}
// AggregatedFeedResponse is the API response obtained when retrieving
// activities from an aggregated feed.
type AggregatedFeedResponse struct {
readResponse
Results []ActivityGroup `json:"results,omitempty"`
}
// NotificationFeedResponse is the API response obtained when retrieving activities
// from a notification feed.
type NotificationFeedResponse struct {
baseNotificationFeedResponse
Results []NotificationFeedResult `json:"results"`
}
// NotificationFeedResult is a notification-feed specific response, containing
// the list of activities in the group, plus the extra fields about the group read+seen status.
type NotificationFeedResult struct {
baseNotificationFeedResult
Activities []Activity `json:"activities"`
}
// AddActivityResponse is the API response obtained when adding a single activity
// to a feed.
type AddActivityResponse struct {
activityResponse
}
type activityResponse struct {
response
Activity
}
// UnmarshalJSON is the custom unmarshaler since activity custom unmarshaler
// can take extra values.
func (a *activityResponse) UnmarshalJSON(buf []byte) error {
var r response
if err := json.Unmarshal(buf, &r); err != nil {
return err
}
var ac Activity
if err := json.Unmarshal(buf, &ac); err != nil {
return err
}
delete(ac.Extra, "duration")
delete(ac.Extra, "ratelimit")
*a = activityResponse{response: r, Activity: ac}
return nil
}
// RemoveActivityResponse is the API response obtained when removing an activity
// from a feed.
type RemoveActivityResponse struct {
response
Removed string `json:"removed"`
}
// AddActivitiesResponse is the API response obtained when adding activities to
// a feed.
type AddActivitiesResponse struct {
response
Activities []Activity `json:"activities,omitempty"`
}
// Follower is the representation of a feed following another feed.
type Follower struct {
FeedID string `json:"feed_id,omitempty"`
TargetID string `json:"target_id,omitempty"`
}
// followResponse is the API response obtained when retrieving follow graph
type followResponse struct {
response
Results []Follower `json:"results,omitempty"`
}
// FollowersResponse is the API response obtained when retrieving followers from
// a feed.
type FollowersResponse struct {
followResponse
}
// FollowingResponse is the API response obtained when retrieving following
// feeds from a feed.
type FollowingResponse struct {
followResponse
}
// AddToManyRequest is the API request body for adding an activity to multiple
// feeds at once.
type AddToManyRequest struct {
Activity Activity `json:"activity,omitempty"`
FeedIDs []string `json:"feeds,omitempty"`
}
// FollowRelationship represents a follow relationship between a source
// ("follower") and a target ("following"), used for FollowMany requests.
type FollowRelationship struct {
Source string `json:"source,omitempty"`
Target string `json:"target,omitempty"`
ActivityCopyLimit *int `json:"activity_copy_limit,omitempty"`
}
// NewFollowRelationship is a helper for creating a FollowRelationship from the
// source ("follower") and target ("following") feeds.
func NewFollowRelationship(source, target Feed, opts ...FollowRelationshipOption) FollowRelationship {
r := FollowRelationship{
Source: source.ID(),
Target: target.ID(),
}
for _, opt := range opts {
opt(&r)
}
return r
}
// FollowRelationshipOption customizes a FollowRelationship.
type FollowRelationshipOption func(r *FollowRelationship)
// WithFollowRelationshipActivityCopyLimit sets the ActivityCopyLimit field for a given FollowRelationship.
func WithFollowRelationshipActivityCopyLimit(activityCopyLimit int) FollowRelationshipOption {
return func(r *FollowRelationship) {
r.ActivityCopyLimit = &activityCopyLimit
}
}
type updateToTargetsRequest struct {
ForeignID string `json:"foreign_id,omitempty"`
Time string `json:"time,omitempty"`
New []string `json:"new_targets,omitempty"`
Adds []string `json:"added_targets,omitempty"`
Removes []string `json:"removed_targets,omitempty"`
}
// UpdateToTargetsRequest is a helper type for batch updating TO targets.
type UpdateToTargetsRequest struct {
ForeignID string
Time Time
Opts []UpdateToTargetsOption
}
// UpdateToTargetsResponse is the response for updating to targets of an activity.
type UpdateToTargetsResponse struct {
response
Activity map[string]any `json:"activity"`
Added []string `json:"added"`
Removed []string `json:"removed"`
}
// UnfollowRelationship represents a single follow relationship to remove, used for
// UnfollowMany requests.
type UnfollowRelationship struct {
Source string `json:"source"`
Target string `json:"target"`
KeepHistory bool `json:"keep_history"`
}
// NewUnfollowRelationship is a helper for creating an UnfollowRelationship from the
// source ("follower") and target ("following") feeds.
func NewUnfollowRelationship(source, target Feed, opts ...UnfollowRelationshipOption) UnfollowRelationship {
r := UnfollowRelationship{
Source: source.ID(),
Target: target.ID(),
}
for _, opt := range opts {
opt(&r)
}
return r
}
// WithUnfollowRelationshipKeepHistory sets the KeepHistory field for a given UnfollowRelationship.
func WithUnfollowRelationshipKeepHistory() UnfollowRelationshipOption {
return func(r *UnfollowRelationship) {
r.KeepHistory = true
}
}
// UnfollowRelationshipOption customizes an UnfollowRelationship.
type UnfollowRelationshipOption func(r *UnfollowRelationship)
// CollectionObject is a collection's object.
type CollectionObject struct {
ID string `json:"id,omitempty"`
Data map[string]any `json:"data"`
}
type CollectionObjectResponse struct {
response
CollectionObject `json:",inline"`
}
// MarshalJSON marshals the CollectionObject to a flat JSON object.
func (o CollectionObject) MarshalJSON() ([]byte, error) {
m := map[string]any{
"id": o.ID,
}
for k, v := range o.Data {
m[k] = v
}
return json.Marshal(m)
}
type addCollectionRequest struct {
UserID *string `json:"user_id,omitempty"`
CollectionObject
}
func (r addCollectionRequest) MarshalJSON() ([]byte, error) {
m := map[string]any{
"id": r.ID,
"data": r.Data,
}
if r.UserID != nil {
m["user_id"] = r.UserID
}
return json.Marshal(m)
}
// GetCollectionResponseObject represents a single response coming from a Collection
// Get request after a CollectionsClient.Get call.
type GetCollectionResponseObject struct {
ForeignID string `json:"foreign_id"`
Data map[string]any `json:"data"`
}
type getCollectionResponse struct {
Data []GetCollectionResponseObject `json:"data"`
}
type getCollectionResponseWrap struct {
response
Response getCollectionResponse `json:"response"`
}
// GetCollectionResponse represents a single response coming from a Collection Select
// request after a CollectionsClient.Select call.
type GetCollectionResponse struct {
response
Objects []GetCollectionResponseObject
}
// User represents a user
type User struct {
ID string `json:"id"`
Data map[string]any `json:"data,omitempty"`
}
type UserResponse struct {
response
User `json:",inline"`
}
// Reaction is a reaction retrieved from the API.
type Reaction struct {
AddReactionRequestObject
User User `json:"user,omitempty"`
ChildrenReactions map[string][]*Reaction `json:"latest_children,omitempty"`
OwnChildren map[string][]*Reaction `json:"own_children,omitempty"`
ChildrenCounters map[string]any `json:"children_counts,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `json:"deleted_at,omitempty"`
Score float64 `json:"score,omitempty"`
Moderation map[string]any `json:"moderation,omitempty"`
}
type ReactionResponse struct {
response
Reaction `json:",inline"`
}
// AddReactionRequestObject is an object used only when calling the Add* reaction endpoints
type AddReactionRequestObject struct {
ID string `json:"id,omitempty"`
Kind string `json:"kind"`
ActivityID string `json:"activity_id"`
UserID string `json:"user_id"`
Data map[string]any `json:"data,omitempty"`
TargetFeeds []string `json:"target_feeds,omitempty"`
TargetFeedsExtraData map[string]any `json:"target_feeds_extra_data,omitempty"`
ParentID string `json:"parent,omitempty"`
}
// filterResponse is the part of StreamAPI responses common for FilterReactions API requests.
type filterResponse struct {
response
Next string `json:"next,omitempty"`
}
func (r filterResponse) parseNext() ([]FilterReactionsOption, error) {
if r.Next == "" {
return nil, ErrMissingNextPage
}
urlParts := strings.Split(r.Next, "?")
if len(urlParts) != 2 {
return nil, ErrInvalidNextPage
}
values, err := url.ParseQuery(urlParts[1])
if err != nil {
return nil, ErrInvalidNextPage
}
var opts []FilterReactionsOption
limit, ok, err := parseIntValue(values, "limit")
if err != nil {
return nil, err
}
if ok {
opts = append(opts, WithLimit(limit))
}
if idLT := values.Get("id_lt"); idLT != "" {
opts = append(opts, WithIDLT(idLT))
}
if idLT := values.Get("id_gt"); idLT != "" {
opts = append(opts, WithIDGT(idLT))
}
if withActData := values.Get("with_activity_data"); withActData != "" {
if val := strings.ToLower(withActData); val == "true" || val == "t" || val == "1" {
opts = append(opts, WithActivityData())
}
}
if withOwnChildren := values.Get("with_own_children"); withOwnChildren != "" {
if val := strings.ToLower(withOwnChildren); val == "true" || val == "t" || val == "1" {
opts = append(opts, WithOwnChildren())
}
}
if userID := values.Get("user_id"); userID != "" {
opts = append(opts, WithOwnUserID(userID))
}
if userID := values.Get("children_user_id"); userID != "" {
opts = append(opts, WithChildrenUserID(userID))
}
if childrenKinds := values.Get("with_own_children_kinds"); childrenKinds != "" {
opts = append(opts, FilterReactionsOption(WithEnrichOwnChildrenKindsFilter(strings.Split(childrenKinds, ",")...)))
}
return opts, nil
}
// FilterReactionResponse is the response received from the ReactionsClient.Filter call.
type FilterReactionResponse struct {
filterResponse
Results []Reaction `json:"results"`
Activity map[string]any `json:"activity"`
meta filterReactionsRequestMetadata
}
// filterReactionsRequestMetadata holds the initial request metadata used for pagination.
type filterReactionsRequestMetadata struct {
attr FilterReactionsAttribute
}
// PersonalizationResponse is a generic response from the personalization endpoints
// obtained after a PersonalizationClient.Get call.
// Common JSON fields are directly available as struct fields, while non-standard
// JSON fields can be retrieved using the Extra() method.
type PersonalizationResponse struct {
AppID int `json:"app_id"`
Duration Duration `json:"duration"`
Rate Rate `json:"ratelimit"`
Limit int `json:"limit"`
Offset int `json:"offset"`
Version string `json:"version"`
Next string `json:"next"`
Results []map[string]any `json:"results"`
extra map[string]any
}
// Extra returns the non-common response fields as a map[string]any.
func (r *PersonalizationResponse) Extra() map[string]any {
return r.extra
}
// UnmarshalJSON for PersonalizationResponse is required because of the incoming duration string, and
// for storing non-standard fields without losing their values, so they can be retrieved
// later on with the Extra() function.
func (r *PersonalizationResponse) UnmarshalJSON(data []byte) error {
var m map[string]any
err := json.Unmarshal(data, &m)
if err != nil {
return err
}
meta, err := decodeData(m, r)
if err != nil {
return err
}
r.extra = make(map[string]any)
for _, k := range meta.Unused {
r.extra[k] = m[k]
}
return nil
}
// EnrichedFlatFeedResponse is the API response obtained when retrieving enriched activities from
// a flat feed.
type EnrichedFlatFeedResponse struct {
readResponse
Results []EnrichedActivity `json:"results,omitempty"`
}
// EnrichedAggregatedFeedResponse is the API response obtained when retrieving
// enriched activities from an aggregated feed.
type EnrichedAggregatedFeedResponse struct {
readResponse
Results []EnrichedActivityGroup `json:"results,omitempty"`
}
// EnrichedNotificationFeedResponse is the API response obtained when retrieving enriched activities
// from a notification feed.
type EnrichedNotificationFeedResponse struct {
baseNotificationFeedResponse
Results []EnrichedNotificationFeedResult `json:"results"`
}
// GetActivitiesResponse contains a slice of Activity returned by GetActivitiesByID
// and GetActivitiesByForeignID requests.
type GetActivitiesResponse struct {
response
Results []Activity `json:"results"`
}
// GetEnrichedActivitiesResponse contains a slice of enriched Activity returned by GetEnrichedActivitiesByID
// and GetEnrichedActivitiesByForeignID requests.
type GetEnrichedActivitiesResponse struct {
response
Results []EnrichedActivity `json:"results"`
}
type GetReactionsByIDsResponse struct {
response
Results []Reaction `json:"reactions"`
}
// ForeignIDTimePair couples an activity's foreignID and timestamp.
type ForeignIDTimePair struct {
ForeignID string
Timestamp Time
}
// NewForeignIDTimePair creates a new ForeignIDTimePair with the given foreign ID and timestamp.
func NewForeignIDTimePair(foreignID string, timestamp Time) ForeignIDTimePair {
return ForeignIDTimePair{
ForeignID: foreignID,
Timestamp: timestamp,
}
}
// UpdateActivityRequest is the API request body for partially updating an activity.
type UpdateActivityRequest struct {
ID *string `json:"id,omitempty"`
ForeignID *string `json:"foreign_id,omitempty"`
Time *Time `json:"time,omitempty"`
Set map[string]any `json:"set,omitempty"`
Unset []string `json:"unset,omitempty"`
}
// NewUpdateActivityRequestByID creates a new UpdateActivityRequest to be used by PartialUpdateActivities
func NewUpdateActivityRequestByID(id string, set map[string]any, unset []string) UpdateActivityRequest {
return UpdateActivityRequest{
ID: &id,
Set: set,
Unset: unset,
}
}
// NewUpdateActivityRequestByForeignID creates a new UpdateActivityRequest to be used by PartialUpdateActivities
func NewUpdateActivityRequestByForeignID(foreignID string, timestamp Time, set map[string]any, unset []string) UpdateActivityRequest {
return UpdateActivityRequest{
ForeignID: &foreignID,
Time: ×tamp,
Set: set,
Unset: unset,
}
}
// UpdateActivityResponse is the response returned by the UpdateActivityByID and
// UpdateActivityByForeignID methods.
type UpdateActivityResponse struct {
activityResponse
}
type UpdateActivitiesResponse struct {
response
Activities []*Activity `json:"activities"`
}
type countResponse struct {
Feed string `json:"feed"`
Count int `json:"count"`
}
type countResponses struct {
Followers countResponse `json:"followers,omitempty"`
Following countResponse `json:"following,omitempty"`
}
// FollowStatResponse is the result of follow stats endpoint.
type FollowStatResponse struct {
response
countResponses `json:"results,inline"`
}