-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup.go
120 lines (93 loc) · 3.03 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
package golinkedmin
import (
"strconv"
"strings"
"time"
"github.com/tamboto2000/golinkedin"
)
type Group struct {
ID int `json:"id,omitempty"`
URL string `json:"url,omitempty"`
Logo *Image `json:"picture,omitempty"`
BackgroundPicture *Image `json:"backgroundPicture,omitempty"`
GroupName string `json:"groupName,omitempty"`
MemberCount int `json:"memberCount,omitempty"`
Description string `json:"description,omitempty"`
Type string `json:"type,omitempty"`
PostApprovalEnabled bool `json:"postApprovalEnabled,omitempty"`
CreatedAt *Date `json:"created,omitempty"`
Rules string `json:"rules,omitempty"`
RelatedGroups []Group `json:"relatedGroups,omitempty"`
Owners []Profile `json:"owners,omitempty"`
Admins []Profile `json:"admins,omitempty"`
}
// compose Group from golinkedin.MiniGroup
func composeMiniGroup(gm *golinkedin.MiniGroup) *Group {
group := new(Group)
// extract id
split := strings.Split(gm.EntityUrn, ":")
id, _ := strconv.Atoi(split[len(split)-1])
group.ID = id
// extract logo
if gm.Logo.COMLinkedinCommonVectorImage != nil {
group.Logo = composeImage(gm.Logo.COMLinkedinCommonVectorImage)
}
// create group url
group.URL = "https://www.linkedin.com/groups/" + strconv.Itoa(group.ID)
// extract group name
group.GroupName = gm.GroupName
// extract description
group.Description = gm.GroupDescription
return group
}
// compose group from golinkedin.Group
func composeGroup(g *golinkedin.Group) *Group {
group := new(Group)
// extract id
split := strings.Split(g.EntityUrn, ":")
id, _ := strconv.Atoi(split[len(split)-1])
group.ID = id
// create group url
group.URL = "https://www.linkedin.com/groups/" + strconv.Itoa(group.ID)
// extract logo
if g.Logo.COMLinkedinCommonVectorImage != nil {
group.Logo = composeImage(g.Logo.COMLinkedinCommonVectorImage)
}
// extract background picture
if g.HeroImage != nil {
if g.HeroImage.COMLinkedinCommonVectorImage != nil {
group.BackgroundPicture = composeImage(g.HeroImage.COMLinkedinCommonVectorImage)
}
}
// extract group name
group.GroupName = g.Name.Text
// extract member count
group.MemberCount = g.MemberCount
// extract description
group.Description = g.Description.Text
// extract type
group.Type = g.Type
// extract post approval enabled
group.PostApprovalEnabled = g.PostApprovalEnabled
// extract created at
group.CreatedAt = unixMilliToDate(int64(g.CreatedAt))
// extract rules
group.Rules = g.Rules
// extract owners
for _, attr := range g.Owners {
group.Owners = append(group.Owners, *composeMiniProfile(attr.MiniProfile))
}
// extract admins
for _, attr := range g.Managers {
group.Admins = append(group.Admins, *composeMiniProfile(attr.MiniProfile))
}
return group
}
func unixMilliToDate(t int64) *Date {
date := time.Unix(t/1000, 0)
return &Date{
Year: date.Year(),
Month: int(date.Month()),
Day: date.Day(),
}
}