-
Notifications
You must be signed in to change notification settings - Fork 15
/
recommendation.go
71 lines (58 loc) · 1.94 KB
/
recommendation.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
package golinkedin
import (
"encoding/json"
"net/url"
"strconv"
)
type RecommendationNode struct {
ProfileID string `json:"profileId,omitempty"`
Q string `json:"q,omitempty"`
Elements []Recommendation `json:"elements,omitempty"`
Paging Paging `json:"paging,omitempty"`
err error
ln *Linkedin
stopCursor bool
}
type Recommendation struct {
EntityUrn string `json:"entityUrn,omitempty"`
Created int `json:"created,omitempty"`
Recommendee *MiniProfile `json:"recommendee,omitempty"`
RecommendationText string `json:"recommendationText,omitempty"`
RecommendeeEntity string `json:"recommendeeEntity,omitempty"`
VisibilityOnRecommenderProfile string `json:"visibilityOnRecommenderProfile,omitempty"`
LastModified int `json:"lastModified,omitempty"`
Relationship string `json:"relationship,omitempty"`
Recommender *MiniProfile `json:"recommender,omitempty"`
Status string `json:"status,omitempty"`
}
func (rec *RecommendationNode) SetLinkedin(ln *Linkedin) {
rec.ln = ln
}
func (rec *RecommendationNode) Next() bool {
if rec.stopCursor {
return false
}
raw, err := rec.ln.get("/identity/profiles/"+rec.ProfileID+"/recommendations", url.Values{
"q": {rec.Q},
"start": {strconv.Itoa(rec.Paging.Start)},
"count": {strconv.Itoa(rec.Paging.Count)},
})
if err != nil {
rec.err = err
return false
}
recNode := new(RecommendationNode)
if err := json.Unmarshal(raw, recNode); err != nil {
rec.err = err
return false
}
rec.Elements = recNode.Elements
rec.Paging.Start = recNode.Paging.Start + recNode.Paging.Count
if len(rec.Elements) < rec.Paging.Count {
rec.stopCursor = true
}
return true
}
func (rec *RecommendationNode) Error() error {
return rec.err
}