This repository has been archived by the owner on Apr 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuilder.go
252 lines (223 loc) · 5.08 KB
/
builder.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
package hangouts
// NewMessage message with builder functions
func NewMessage() *Message {
return &Message{}
}
// WithText adds text to function
func (m *Message) WithText(t string) *Message {
m.Text = t
return m
}
// WithSender adds a User to Message
func (m *Message) WithSender(u User) *Message {
m.Sender = u
return m
}
// InThread defines the thread a message should be posted in
func (m *Message) InThread(name string) *Message {
m.Thread = &Thread{
Name: name,
}
return m
}
// WithCard adds a new card to Message
func (m *Message) WithCard(c *Card) *Message {
m.Cards = append(m.Cards, c)
return m
}
// NewCard for being used in Message
func NewCard() *Card {
return &Card{}
}
// WithHeader adds the defined header values to card
func (c *Card) WithHeader(title, subtitle, imageURL, imageStyle string) *Card {
c.Header = &Header{
Title: title,
Subtitle: subtitle,
ImageURL: imageURL,
ImageStyle: imageStyle,
}
return c
}
// WithSection adds a new Section to Card
func (c *Card) WithSection(s *Section) *Card {
c.Sections = append(c.Sections, s)
return c
}
// WithAction adds a new Action to Card
func (c *Card) WithAction(a *Action) *Card {
c.Actions = append(c.Actions, a)
return c
}
// NewSection for being used in Card
func NewSection(header string) *Section {
return &Section{
Header: header,
}
}
// WithWidget adds a new Widget to Section
func (s *Section) WithWidget(w *Widget) *Section {
s.Widgets = append(s.Widgets, w)
return s
}
// NewWidget which may **either** contain TextParagraph, KeyValue or Buttons
func NewWidget() *Widget {
return &Widget{}
}
// WithTextParagraph adds text to widget
func (w *Widget) WithTextParagraph(t string) *Widget {
w.TextParagraph = &TextParagraph{
Text: t,
}
return w
}
// WithKeyValue adds KeyValue object to widget
func (w *Widget) WithKeyValue(kv *KeyValue) *Widget {
w.KeyValue = kv
return w
}
// WithButton adds new Button to Widget
func (w *Widget) WithButton(b *Button) *Widget {
w.Buttons = append(w.Buttons, b)
return w
}
// WithImage adds new Image to Widget
func (w *Widget) WithImage(i *Image) *Widget {
w.Image = i
return w
}
// NewKeyValue for use in Widget
// TopLabel and Content are required
func NewKeyValue(topLabel, content string, multiline bool) *KeyValue {
return &KeyValue{
TopLabel: topLabel,
Content: content,
ContentMultiline: multiline,
}
}
// WithBottomLabel for KeyValue
func (kv *KeyValue) WithBottomLabel(l string) *KeyValue {
kv.BottomLabel = l
return kv
}
// WithOpenLink adds OnClick containing an OpenLink action to KeyValue
func (kv *KeyValue) WithOpenLink(url string) *KeyValue {
kv.OnClick = &OnClick{
Action: nil,
OpenLink: &OpenLink{
URL: url,
},
}
return kv
}
// WithAction adds OnClick containing a FormAction to KeyValue
func (kv *KeyValue) WithAction(name string, parameters ...*ActionParameter) *KeyValue {
kv.OnClick = &OnClick{
Action: &FormAction{
MethodName: name,
Parameters: parameters,
},
OpenLink: nil,
}
return kv
}
// NewActionParameter for use in KeyValue
func NewActionParameter(key, value string) *ActionParameter {
return &ActionParameter{
Key: key,
Value: value,
}
}
// WithButton adds new Button to KeyValue
func (kv *KeyValue) WithButton(b *Button) *KeyValue {
kv.Button = b
return kv
}
// NewTextLinkButton containing OpenLink
func NewTextLinkButton(text, url string) *Button {
return &Button{
TextButton: &TextButton{
Text: text,
OnClick: &OnClick{
Action: nil,
OpenLink: &OpenLink{
URL: url,
},
},
},
}
}
// NewTextActionButton containing FormAction
func NewTextActionButton(text, action string, parameters ...*ActionParameter) *Button {
return &Button{
TextButton: &TextButton{
Text: text,
OnClick: &OnClick{
Action: &FormAction{
MethodName: action,
Parameters: parameters,
},
OpenLink: nil,
},
},
}
}
// NewImageLinkButton containing OpenLink
func NewImageLinkButton(icon, iconURL, url string) *Button {
return &Button{
ImageButton: &ImageButton{
Icon: icon,
IconURL: iconURL,
OnClick: &OnClick{
Action: nil,
OpenLink: &OpenLink{
URL: url,
},
},
},
}
}
// NewImageActionButton containing FormAction
func NewImageActionButton(icon, iconURL, action string, parameters ...*ActionParameter) *Button {
return &Button{
ImageButton: &ImageButton{
Icon: icon,
IconURL: iconURL,
OnClick: &OnClick{
Action: &FormAction{
MethodName: action,
Parameters: parameters,
},
OpenLink: nil,
},
},
}
}
// NewImage with URL and AspectRatio
func NewImage(url string, ratio int) *Image {
return &Image{
ImageURL: url,
AspectRatio: ratio,
}
}
// WithOpenLink adds OnClick with OpenLink to Image
func (i *Image) WithOpenLink(url string) *Image {
i.OnClick = &OnClick{
Action: nil,
OpenLink: &OpenLink{
URL: url,
},
}
return i
}
// WithAction adds OnClick with FormAction to Image
func (i *Image) WithAction(name string, parameters ...*ActionParameter) *Image {
i.OnClick = &OnClick{
Action: &FormAction{
MethodName: name,
Parameters: parameters,
},
OpenLink: nil,
}
return i
}