-
Notifications
You must be signed in to change notification settings - Fork 15
/
industry.go
81 lines (67 loc) · 1.88 KB
/
industry.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
package golinkedin
import (
"encoding/json"
"net/url"
"strconv"
)
type IndustryNode struct {
Metadata Metadata `json:"metadata,omitempty"`
Elements []Industry `json:"elements,omitempty"`
Paging Paging `json:"paging,omitempty"`
Keywords string `json:"keywords,omitempty"`
err error
ln *Linkedin
stopCursor bool
}
type Industry struct {
LocalizedName string `json:"localizedName,omitempty"`
Name string `json:"name,omitempty"`
RecipeType string `json:"$recipeType,omitempty"`
EntityUrn string `json:"entityUrn,omitempty"`
CompanyNameRequired bool `json:"companyNameRequired,omitempty"`
TargetUrn string `json:"targetUrn,omitempty"`
ObjectUrn string `json:"objectUrn,omitempty"`
Text Text `json:"text,omitempty"`
DashTargetUrn string `json:"dashTargetUrn,omitempty"`
Type string `json:"type,omitempty"`
TrackingID string `json:"trackingId,omitempty"`
}
func (ind *IndustryNode) SetLinkedin(ln *Linkedin) {
ind.ln = ln
}
func (ind *IndustryNode) Next() bool {
if ind.stopCursor {
return false
}
start := strconv.Itoa(ind.Paging.Start)
count := strconv.Itoa(ind.Paging.Count)
raw, err := ind.ln.get("/typeahead/hitsV2", url.Values{
"keywords": {ind.Keywords},
"origin": {OriginOther},
"q": {QType},
"type": {TypeIndustry},
"start": {start},
"count": {count},
})
if err != nil {
ind.err = err
return false
}
indNode := new(IndustryNode)
if err := json.Unmarshal(raw, indNode); err != nil {
ind.err = err
return false
}
ind.Elements = indNode.Elements
ind.Paging.Start = indNode.Paging.Start + indNode.Paging.Count
if len(ind.Elements) == 0 {
return false
}
if len(ind.Elements) < ind.Paging.Count {
ind.stopCursor = true
}
return true
}
func (ind *IndustryNode) Error() error {
return ind.err
}