-
Notifications
You must be signed in to change notification settings - Fork 15
/
education.go
97 lines (81 loc) · 3.34 KB
/
education.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
package golinkedin
import (
"encoding/json"
"net/url"
"strconv"
)
// EducationNode contains user educations info
type EducationNode struct {
// will set after calling ProfileNode.Educations()
ProfileID string `json:"profileId,omitempty"`
Elements []Education `json:"elements,omitempty"`
Paging Paging `json:"paging,omitempty"`
err error
ln *Linkedin
stopCursor bool
}
type Education struct {
EntityUrn string `json:"entityUrn,omitempty"`
Activities string `json:"activities,omitempty"`
School *School `json:"school,omitempty"`
TimePeriod *TimePeriod `json:"timePeriod,omitempty"`
Grade string `json:"grade,omitempty"`
Description string `json:"description,omitempty"`
DegreeName string `json:"degreeName,omitempty"`
SchoolName string `json:"schoolName,omitempty"`
FieldOfStudy string `json:"fieldOfStudy,omitempty"`
Recommendations []interface{} `json:"recommendations,omitempty"`
SchoolUrn string `json:"schoolUrn,omitempty"`
DateRange *DateRange `json:"dateRange,omitempty"`
ProfileTreasuryMediaEducation *ProfileTreasuryMediaEducation `json:"profileTreasuryMediaEducation,omitempty"`
MultiLocaleSchoolName *MultiLocale `json:"multiLocaleSchoolName,omitempty"`
MultiLocaleFieldOfStudy *MultiLocale `json:"multiLocaleFieldOfStudy,omitempty"`
RecipeType string `json:"$recipeType,omitempty"`
MultiLocaleDescription *MultiLocale `json:"multiLocaleDescription,omitempty"`
MultiLocaleActivities *MultiLocale `json:"multiLocaleActivities,omitempty"`
MultiLocaleDegreeName *MultiLocale `json:"multiLocaleDegreeName,omitempty"`
}
type Title struct {
TextDirection string `json:"textDirection,omitempty"`
Text string `json:"text,omitempty"`
}
type ProfileTreasuryMediaEducation struct {
Paging Paging `json:"paging,omitempty"`
RecipeType string `json:"$recipeType,omitempty"`
Elements []interface{} `json:"elements,omitempty"`
}
func (edu *EducationNode) SetLinkedin(ln *Linkedin) {
edu.ln = ln
}
func (edu *EducationNode) Next() bool {
if edu.stopCursor {
return false
}
start := strconv.Itoa(edu.Paging.Start)
count := strconv.Itoa(edu.Paging.Count)
raw, err := edu.ln.get("/identity/profiles/"+edu.ProfileID+"/educations", url.Values{
"start": {start},
"count": {count},
})
if err != nil {
edu.err = err
return false
}
eduNode := new(EducationNode)
if err := json.Unmarshal(raw, eduNode); err != nil {
edu.err = err
return false
}
edu.Elements = eduNode.Elements
edu.Paging.Start = eduNode.Paging.Start + eduNode.Paging.Count
if len(edu.Elements) == 0 {
return false
}
if len(edu.Elements) < edu.Paging.Count {
edu.stopCursor = true
}
return true
}
func (edu *EducationNode) Error() error {
return edu.err
}