-
Notifications
You must be signed in to change notification settings - Fork 15
/
group.go
128 lines (109 loc) · 4.7 KB
/
group.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package golinkedin
import (
"encoding/json"
"net/url"
"strconv"
"strings"
)
type GroupNode struct {
Keywords string `json:"keywords,omitempty"`
Metadata Metadata `json:"metadata,omitempty"`
Elements []Group `json:"elements,omitempty"`
Paging Paging `json:"paging,omitempty"`
err error
ln *Linkedin
stopCursor bool
}
type Group struct {
// Elements contains groups from search group result
Elements []Group `json:"elements,omitempty"`
ExtendedElements []interface{} `json:"extendedElements,omitempty"`
Image *Image `json:"image,omitempty"`
TargetUrn string `json:"targetUrn,omitempty"`
TrackingUrn string `json:"trackingUrn,omitempty"`
Title *Text `json:"title,omitempty"`
Type string `json:"type,omitempty"`
Headline *Text `json:"headline,omitempty"`
Subline *Text `json:"subline,omitempty"`
TrackingID string `json:"trackingId,omitempty"`
GroupName string `json:"groupName,omitempty"`
EntityUrn string `json:"entityUrn,omitempty"`
MemberCount int `json:"memberCount,omitempty"`
Logo *Image `json:"logo,omitempty"`
HeroImage *Image `json:"heroImage,omitempty"`
RecipeType string `json:"$recipeType,omitempty"`
URL string `json:"url,omitempty"`
DashEntityUrn string `json:"dashEntityUrn"`
DisplayNotificationSubscriptionLevelOptions bool `json:"displayNotificationSubscriptionLevelOptions"`
GroupPostNotificationsEdgeSettingUrn string `json:"groupPostNotificationsEdgeSettingUrn"`
PostApprovalEnabled bool `json:"postApprovalEnabled"`
Description *Text `json:"description"`
ShowPostApprovalOption bool `json:"showPostApprovalOption"`
Rules string `json:"rules"`
Owners []Attribute `json:"owners"`
LogoUrn string `json:"logoUrn"`
InvitationLevel string `json:"invitationLevel"`
MemberConnectionsCount int `json:"memberConnectionsCount"`
CreatedAt int `json:"createdAt"`
Name *Text `json:"name"`
GlobalNewPostNotificationSettingOn bool `json:"globalNewPostNotificationSettingOn"`
RecommendByAdminAvailable bool `json:"recommendByAdminAvailable"`
GroupUrn string `json:"groupUrn"`
Managers []Attribute `json:"managers"`
}
func (ln *Linkedin) GroupByID(id int) (*Group, error) {
raw, err := ln.get("/groups/groups/urn:li:group:"+strconv.Itoa(id), nil)
if err != nil {
return nil, err
}
group := new(Group)
if err := json.Unmarshal(raw, group); err != nil {
return nil, err
}
return group, nil
}
func (gr *Group) GroupID() int {
split := strings.Split(gr.EntityUrn, ":")
id, _ := strconv.Atoi(split[len(split)-1])
return id
}
func (gr *GroupNode) SetLinkedin(ln *Linkedin) {
gr.ln = ln
}
func (gr *GroupNode) Next() bool {
if gr.stopCursor {
return false
}
start := strconv.Itoa(gr.Paging.Start)
count := strconv.Itoa(gr.Paging.Count)
raw, err := gr.ln.get("/search/blended", url.Values{
"keywords": {gr.Keywords},
"origin": {OriginSwitchSearchVertical},
"q": {QAll},
"filters": {composeFilter(DefaultSearchGroupFilter)},
"queryContext": {composeFilter(DefaultSearchGroupQueryContext)},
"start": {start},
"count": {count},
})
if err != nil {
gr.err = err
return false
}
grNode := new(GroupNode)
if err := json.Unmarshal(raw, grNode); err != nil {
gr.err = err
return false
}
gr.Elements = grNode.Elements
gr.Paging.Start = grNode.Paging.Start + grNode.Paging.Count
if len(gr.Elements) == 0 {
return false
}
if len(gr.Elements[0].Elements) < gr.Paging.Count {
gr.stopCursor = true
}
return true
}
func (gr *GroupNode) Error() error {
return gr.err
}