-
Notifications
You must be signed in to change notification settings - Fork 14
/
interest.go
79 lines (64 loc) · 2.01 KB
/
interest.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
package golinkedin
import (
"encoding/json"
"net/url"
"strconv"
)
type InterestNode struct {
ProfileID string `json:"profileId,omitempty"`
Type string `json:"type,omitempty"`
Elements []Interest `json:"elements,omitempty"`
Paging Paging `json:"paging,omitempty"`
err error
ln *Linkedin
stopCursor bool
}
type Interest struct {
Entity *Entity `json:"entity,omitempty"`
FollowingInfo *FollowingInfo `json:"followingInfo,omitempty"`
}
type Entity struct {
MiniCompany *MiniCompany `json:"com.linkedin.voyager.entities.shared.MiniCompany,omitempty"`
MiniGroup *MiniGroup `json:"com.linkedin.voyager.entities.shared.MiniGroup,omitempty"`
MiniSchool *MiniSchool `json:"com.linkedin.voyager.entities.shared.MiniSchool,omitempty"`
MiniProfile *MiniProfile `json:"com.linkedin.voyager.entities.shared.MiniProfile,omitempty"`
}
type FollowingInfo struct {
FollowingType string `json:"followingType,omitempty"`
EntityUrn string `json:"entityUrn,omitempty"`
FollowerCount int `json:"followerCount,omitempty"`
Following bool `json:"following,omitempty"`
TrackingUrn string `json:"trackingUrn,omitempty"`
}
func (inter *InterestNode) SetLinkedin(ln *Linkedin) {
inter.ln = ln
}
func (inter *InterestNode) Next() bool {
if inter.stopCursor {
return false
}
raw, err := inter.ln.get("/identity/profiles/"+inter.ProfileID+"/following", url.Values{
"entityType": {inter.Type},
"q": {"followedEntities"},
"start": {strconv.Itoa(inter.Paging.Start)},
"count": {strconv.Itoa(inter.Paging.Count)},
})
if err != nil {
inter.err = err
return false
}
interNode := new(InterestNode)
if err := json.Unmarshal(raw, interNode); err != nil {
inter.err = err
return false
}
inter.Elements = interNode.Elements
inter.Paging.Start = interNode.Paging.Start + interNode.Paging.Count
if len(inter.Elements) < inter.Paging.Count {
inter.stopCursor = true
}
return true
}
func (inter *InterestNode) Error() error {
return inter.err
}