-
Notifications
You must be signed in to change notification settings - Fork 15
/
geo.go
89 lines (74 loc) · 2.34 KB
/
geo.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
package golinkedin
import (
"encoding/json"
"net/url"
"strconv"
)
type GeoNode struct {
Metadata Metadata `json:"metadata,omitempty"`
Elements []Geo `json:"elements,omitempty"`
Paging Paging `json:"paging,omitempty"`
Keywords string `json:"keywords,omitempty"`
err error
ln *Linkedin
stopCursor bool
}
type GeoLocation struct {
Geo Geo `json:"geo,omitempty"`
GeoUrn string `json:"geoUrn,omitempty"`
RecipeType string `json:"$recipeType,omitempty"`
}
type Geo struct {
CountryUrn string `json:"countryUrn,omitempty"`
Country *Country `json:"country,omitempty"`
DefaultLocalizedNameWithoutCountryName string `json:"defaultLocalizedNameWithoutCountryName,omitempty"`
EntityUrn string `json:"entityUrn,omitempty"`
RecipeType string `json:"$recipeType,omitempty"`
DefaultLocalizedName string `json:"defaultLocalizedName,omitempty"`
TargetUrn string `json:"targetUrn,omitempty"`
Text Text `json:"text,omitempty"`
DashTargetUrn string `json:"dashTargetUrn,omitempty"`
Type string `json:"type,omitempty"`
TrackingID string `json:"trackingId,omitempty"`
}
func (g *GeoNode) SetLinkedin(ln *Linkedin) {
g.ln = ln
}
func (g *GeoNode) Next() bool {
if g.stopCursor {
return false
}
start := strconv.Itoa(g.Paging.Start)
count := strconv.Itoa(g.Paging.Count)
raw, err := g.ln.get("/typeahead/hitsV2", url.Values{
"keywords": {g.Keywords},
"origin": {OriginOther},
"q": {QType},
"queryContext": {composeFilter(DefaultGeoSearchQueryContext)},
"type": {TypeGeo},
"useCase": {GeoAbbreviated},
"start": {start},
"count": {count},
})
if err != nil {
g.err = err
return false
}
geoNode := new(GeoNode)
if err := json.Unmarshal(raw, geoNode); err != nil {
g.err = err
return false
}
g.Elements = geoNode.Elements
g.Paging.Start = geoNode.Paging.Start + geoNode.Paging.Count
if len(g.Elements) == 0 {
return false
}
if len(g.Elements) < g.Paging.Count {
g.stopCursor = true
}
return true
}
func (g *GeoNode) Error() error {
return g.err
}