-
Notifications
You must be signed in to change notification settings - Fork 15
/
activity.go
237 lines (204 loc) · 10 KB
/
activity.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
package golinkedin
import (
"encoding/json"
"net/url"
"strconv"
)
type ActivityNode struct {
Metadata *Metadata `json:"metadata,omitempty"`
Elements []Activity `json:"elements,omitempty"`
Paging Paging `json:"paging,omitempty"`
Type string `json:"type,omitempty"`
ProfileUrn string `json:"profileUrn,omitempty"`
err error
ln *Linkedin
stopCursor bool
}
type Activity struct {
Image *BackgroundImage `json:"image,omitempty"`
Featured bool `json:"featured,omitempty"`
PermaLink string `json:"permaLink,omitempty"`
LinkedinArticleUrn string `json:"linkedinArticleUrn,omitempty"`
ContentText *Text `json:"contentText,omitempty"`
Title string `json:"title,omitempty"`
NumLikes int `json:"numLikes,omitempty"`
PostedDate *Date `json:"postedDate,omitempty"`
SocialDetail *SocialDetail `json:"socialDetail,omitempty"`
TrackingData *TrackingData `json:"trackingData,omitempty"`
NumComments int `json:"numComments,omitempty"`
CreatedDate *Date `json:"createdDate,omitempty"`
PostedAt int `json:"postedAt,omitempty"`
EntityUrn string `json:"entityUrn,omitempty"`
AuthorComponent *AuthorComponent `json:"authorComponent,omitempty"`
Actor Actor `json:"actor,omitempty"`
UpdateMetadata Metadata `json:"updateMetadata,omitempty"`
Content Content `json:"content,omitempty"`
Commentary Commentary `json:"commentary,omitempty"`
}
type Commentary struct {
TemplateType string `json:"templateType,omitempty"`
Text Text `json:"text,omitempty"`
}
type Content struct {
COMLinkedinVoyagerFeedRenderArticleComponent COMLinkedinVoyagerFeedRenderArticleComponent `json:"com.linkedin.voyager.feed.render.ArticleComponent,omitempty"`
}
type COMLinkedinVoyagerFeedRenderArticleComponent struct {
TemplateType string `json:"templateType,omitempty"`
Urn string `json:"urn,omitempty"`
LargeImage *Image `json:"largeImage,omitempty"`
Subtitle *Text `json:"subtitle,omitempty"`
NavigationContext *NavigationContext `json:"navigationContext,omitempty"`
Type string `json:"type,omitempty"`
Title *Text `json:"title,omitempty"`
AuthorNavigationContext *NavigationContext `json:"authorNavigationContext,omitempty"`
Author *Text `json:"author,omitempty"`
Description *Text `json:"description,omitempty"`
FollowAction *COMLinkedinVoyagerFeedRenderArticleComponentFollowAction `json:"followAction,omitempty"`
SubtitleImage *Image `json:"subtitleImage,omitempty"`
SubscribeAction *SubscribeAction `json:"subscribeAction,omitempty"`
}
type SubscribeAction struct {
EntityUrn string `json:"entityUrn,omitempty"`
Subscribed bool `json:"subscribed,omitempty"`
SubscriberCount int `json:"subscriberCount,omitempty"`
}
type COMLinkedinVoyagerFeedRenderArticleComponentFollowAction struct {
FollowTrackingActionType string `json:"followTrackingActionType,omitempty"`
FollowingInfo *FollowingInfo `json:"followingInfo,omitempty"`
UnfollowTrackingActionType string `json:"unfollowTrackingActionType,omitempty"`
Type string `json:"type,omitempty"`
TrackingActionType string `json:"trackingActionType,omitempty"`
}
type NavigationContext struct {
TrackingActionType string `json:"trackingActionType,omitempty"`
AccessibilityText string `json:"accessibilityText,omitempty"`
ActionTarget string `json:"actionTarget,omitempty"`
}
type Actor struct {
Urn string `json:"urn,omitempty"`
Image *Image `json:"image,omitempty"`
SupplementaryActorInfo *SubDescription `json:"supplementaryActorInfo,omitempty"`
Name *Name `json:"name,omitempty"`
SubDescription *SubDescription `json:"subDescription,omitempty"`
NavigationContext *NavigationContext `json:"navigationContext,omitempty"`
Description *Text `json:"description,omitempty"`
ShowInfluencerBadge bool `json:"showInfluencerBadge,omitempty"`
FollowAction *ActorFollowAction `json:"followAction,omitempty"`
}
type ActorFollowAction struct {
FollowTrackingActionType string `json:"followTrackingActionType,omitempty"`
FollowingInfo *FollowingInfo `json:"followingInfo,omitempty"`
Type string `json:"type,omitempty"`
TrackingActionType string `json:"trackingActionType,omitempty"`
}
type Name struct {
TextDirection string `json:"textDirection,omitempty"`
Attributes []Attribute `json:"attributes,omitempty"`
Text string `json:"text,omitempty"`
}
type SubDescription struct {
TextDirection string `json:"textDirection,omitempty"`
Attributes []Attribute `json:"attributes,omitempty"`
Text string `json:"text,omitempty"`
AccessibilityText string `json:"accessibilityText,omitempty"`
}
type AuthorComponent struct {
Name *Text `json:"name,omitempty"`
Image *AuthorComponentImage `json:"image,omitempty"`
Description *Text `json:"description,omitempty"`
}
type AuthorComponentImage struct {
Attributes []Attribute `json:"attributes,omitempty"`
AccessibilityTextAttributes []interface{} `json:"accessibilityTextAttributes,omitempty"`
AccessibilityText string `json:"accessibilityText,omitempty"`
}
type TrackingData struct {
TrackingID string `json:"trackingId,omitempty"`
}
type SocialDetail struct {
ReactionElements []interface{} `json:"reactionElements,omitempty"`
Comments *Comments `json:"comments,omitempty"`
SocialPermissions *SocialPermissions `json:"socialPermissions,omitempty"`
Liked bool `json:"liked,omitempty"`
ShowShareButton bool `json:"showShareButton,omitempty"`
TotalShares int `json:"totalShares,omitempty"`
Urn string `json:"urn,omitempty"`
ThreadID string `json:"threadId,omitempty"`
AllowedCommentersScope string `json:"allowedCommentersScope,omitempty"`
TotalSocialActivityCounts *TotalSocialActivityCounts `json:"totalSocialActivityCounts,omitempty"`
EntityUrn string `json:"entityUrn,omitempty"`
CommentingDisabled bool `json:"commentingDisabled,omitempty"`
SocialUpdateType string `json:"socialUpdateType,omitempty"`
Likes *ActivityNode `json:"likes,omitempty"`
}
type Comments struct {
Metadata *Metadata `json:"metadata,omitempty"`
Paging Paging `json:"paging,omitempty"`
Elements []interface{} `json:"elements,omitempty"`
}
type SocialPermissions struct {
CanPostComments bool `json:"canPostComments,omitempty"`
EntityUrn string `json:"entityUrn,omitempty"`
CanShare bool `json:"canShare,omitempty"`
CanReact bool `json:"canReact,omitempty"`
}
type TotalSocialActivityCounts struct {
SocialDetailEntityUrn string `json:"socialDetailEntityUrn,omitempty"`
Urn string `json:"urn,omitempty"`
NumComments int `json:"numComments,omitempty"`
ReactionTypeCounts []ReactionTypeCount `json:"reactionTypeCounts,omitempty"`
EntityUrn string `json:"entityUrn,omitempty"`
NumShares int `json:"numShares,omitempty"`
NumLikes int `json:"numLikes,omitempty"`
Liked bool `json:"liked,omitempty"`
}
type ReactionTypeCount struct {
Count int `json:"count,omitempty"`
ReactionType string `json:"reactionType,omitempty"`
}
func (act *ActivityNode) SetLinkedin(ln *Linkedin) {
act.ln = ln
}
func (act *ActivityNode) Next() bool {
if act.stopCursor {
return false
}
var raw []byte
var err error
if act.Type == ActivityArticle {
raw, err = act.ln.get("/identity/profiles/williamhgates/posts", url.Values{
"start": {strconv.Itoa(act.Paging.Start)},
"count": {strconv.Itoa(act.Paging.Count)},
})
}
if act.Type == ActivityPost {
raw, err = act.ln.get("/identity/profileUpdatesV2", url.Values{
"includeLongTermHistory": {"true"},
"moduleKey": {"member-shares:phone"},
"numComments": {"0"},
"numLikes": {"0"},
"profileUrn": {act.ProfileUrn},
"q": {"memberShareFeed"},
"start": {strconv.Itoa(act.Paging.Start)},
"count": {strconv.Itoa(act.Paging.Count)},
})
}
if err != nil {
act.err = err
return false
}
actNode := new(ActivityNode)
if err := json.Unmarshal(raw, actNode); err != nil {
act.err = err
return false
}
act.Elements = actNode.Elements
act.Paging.Start = actNode.Paging.Start + actNode.Paging.Count
if len(act.Elements) < actNode.Paging.Count {
act.stopCursor = true
}
return true
}
func (act *ActivityNode) Error() error {
return act.err
}