-
Notifications
You must be signed in to change notification settings - Fork 14
/
service.go
77 lines (63 loc) · 1.58 KB
/
service.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
package golinkedin
import (
"encoding/json"
"net/url"
"strconv"
)
type ServiceNode struct {
Metadata Metadata `json:"metadata,omitempty"`
Elements []Service `json:"elements,omitempty"`
Paging Paging `json:"paging,omitempty"`
Keywords string `json:"keywords,omitempty"`
err error
ln *Linkedin
stopCursor bool
}
type Service struct {
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 (svc *ServiceNode) SetLinkedin(ln *Linkedin) {
svc.ln = ln
}
func (svc *ServiceNode) Next() bool {
if svc.stopCursor {
return false
}
start := strconv.Itoa(svc.Paging.Start)
count := strconv.Itoa(svc.Paging.Count)
raw, err := svc.ln.get("/typeahead/hitsV2", url.Values{
"keywords": {svc.Keywords},
"origin": {OriginOther},
"q": {QType},
"type": {TypeSkill},
"useCase": {MarketplaceSkills},
"start": {start},
"count": {count},
})
if err != nil {
svc.err = err
return false
}
svcNode := new(ServiceNode)
if err := json.Unmarshal(raw, svcNode); err != nil {
svc.err = err
return false
}
svc.Elements = svcNode.Elements
svc.Paging.Start = svcNode.Paging.Start + svcNode.Paging.Count
if len(svc.Elements) == 0 {
return false
}
if len(svc.Elements) < svc.Paging.Count {
svc.stopCursor = true
}
return true
}
func (svc *ServiceNode) Error() error {
return svc.err
}