-
Notifications
You must be signed in to change notification settings - Fork 15
/
honor.go
87 lines (71 loc) · 2.17 KB
/
honor.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
package golinkedin
import (
"encoding/json"
"net/url"
"strconv"
)
type HonorNode struct {
ProfileID string `json:"profileId,omitempty"`
Paging Paging `json:"paging,omitempty"`
RecipeType string `json:"$recipeType,omitempty"`
Elements []Honor `json:"elements,omitempty"`
err error
ln *Linkedin
stopCursor bool
}
type Honor struct {
MultiLocaleTitle *MultiLocale `json:"multiLocaleTitle,omitempty"`
Description string `json:"description,omitempty"`
OccupationUnion *OccupationUnion `json:"occupationUnion,omitempty"`
Title string `json:"title,omitempty"`
Issuer string `json:"issuer,omitempty"`
IssuedOn *IssuedOn `json:"issuedOn,omitempty"`
EntityUrn string `json:"entityUrn,omitempty"`
RecipeType string `json:"$recipeType,omitempty"`
MultiLocaleIssuer *MultiLocale `json:"multiLocaleIssuer,omitempty"`
MultiLocaleDescription *MultiLocale `json:"multiLocaleDescription,omitempty"`
Occupation string `json:"occupation,omitempty"`
IssueDate *Date `json:"issueDate,omitempty"`
}
type IssuedOn struct {
Month int `json:"month,omitempty"`
Year int `json:"year,omitempty"`
}
type OccupationUnion struct {
ProfilePosition string `json:"profilePosition,omitempty"`
}
func (hn *HonorNode) SetLinkedin(ln *Linkedin) {
hn.ln = ln
}
func (hn *HonorNode) Next() bool {
if hn.stopCursor {
return false
}
start := strconv.Itoa(hn.Paging.Start)
count := strconv.Itoa(hn.Paging.Count)
raw, err := hn.ln.get("/identity/profiles/"+hn.ProfileID+"/honors", url.Values{
"start": {start},
"count": {count},
})
if err != nil {
hn.err = err
return false
}
hnNode := new(HonorNode)
if err := json.Unmarshal(raw, hnNode); err != nil {
hn.err = err
return false
}
hn.Elements = hnNode.Elements
hn.Paging.Start = hnNode.Paging.Start + hnNode.Paging.Count
if len(hn.Elements) == 0 {
return false
}
if len(hn.Elements) < hn.Paging.Count {
hn.stopCursor = true
}
return true
}
func (hn *HonorNode) Error() error {
return hn.err
}