-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcard_builder_templates.py
356 lines (275 loc) · 13.1 KB
/
card_builder_templates.py
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
""" To run this example:
uvicorn card_builder_templates:app --reload --port 8080
"""
import random
from gapps import CardService
from gapps.cardservice import models
from gapps.cardservice.utilities import decode_email, decode_user
from fastapi import FastAPI
from fastapi.responses import JSONResponse
app = FastAPI(title="Cards Generator")
@app.get("/")
async def root():
return {"message": "Welcome to Card Generator example!"}
@app.post("/homepage", response_class=JSONResponse)
async def homepage(gevent: models.GEvent):
user_info = decode_user(gevent.authorizationEventObject.userIdToken)
print(f"USER INFO: {user_info}")
email = decode_email(gevent.authorizationEventObject.userIdToken)
print(f"USER email: {email}")
cards = [build_users_list_card, build_multi_section_card, build_user_card,
build_email_card, build_form_controls_card]
# Select a random card to display
page = random.choice(cards)()
return page
def build_users_list_card():
cardSection1DecoratedText1Icon1 = CardService.newIconImage() \
.setIconUrl('https://koolinus.files.wordpress.com/2019/03/avataaars-e28093-koolinus-1-12mar2019.png') # noqa: E501
cardSection1DecoratedText1 = CardService.newDecoratedText() \
.setText('John Doe') \
.setBottomLabel('Software engineer') \
.setStartIcon(cardSection1DecoratedText1Icon1)
cardSection1Divider1 = CardService.newDivider()
cardSection1DecoratedText2Icon1 = CardService.newIconImage() \
.setIconUrl('https://happyfacesparty.com/wp-content/uploads/2019/06/avataaars-Brittany.png') # noqa: E501
cardSection1DecoratedText2 = CardService.newDecoratedText() \
.setText('Jane Doe') \
.setBottomLabel('Product manager') \
.setStartIcon(cardSection1DecoratedText2Icon1)
cardSection1Divider2 = CardService.newDivider()
cardSection1DecoratedText3Icon1 = CardService.newIconImage() \
.setIconUrl('https://i2.wp.com/tunisaid.org/wp-content/uploads/2019/03/avataaars-2.png?ssl=1') # noqa: E501
cardSection1DecoratedText3 = CardService.newDecoratedText() \
.setText('Jamie Doe') \
.setBottomLabel('Vice president') \
.setStartIcon(cardSection1DecoratedText3Icon1)
cardSection1 = CardService.newCardSection() \
.setHeader('List of users') \
.addWidget(cardSection1DecoratedText1) \
.addWidget(cardSection1Divider1) \
.addWidget(cardSection1DecoratedText2) \
.addWidget(cardSection1Divider2) \
.addWidget(cardSection1DecoratedText3) \
card = CardService.newCardBuilder() \
.addSection(cardSection1) \
.build()
return card
def build_multi_section_card():
cardSection1DecoratedText1 = CardService.newDecoratedText() \
.setText('Item 1') \
.setBottomLabel('Info for Item 1 list 1')
cardSection1DecoratedText2 = CardService.newDecoratedText() \
.setText('Item 2') \
.setBottomLabel('Info for Item 2 list 1') \
cardSection1 = CardService.newCardSection() \
.setHeader('Items list 1') \
.addWidget(cardSection1DecoratedText1) \
.addWidget(cardSection1DecoratedText2) \
cardSection2DecoratedText1 = CardService.newDecoratedText() \
.setText('Item 1') \
.setBottomLabel('Info for Item 1 list 2') \
cardSection2DecoratedText2 = CardService.newDecoratedText() \
.setText('Item 2') \
.setBottomLabel('Info for Item 2 list 2') \
cardSection2 = CardService.newCardSection() \
.setHeader('Items list 2') \
.addWidget(cardSection2DecoratedText1) \
.addWidget(cardSection2DecoratedText2) \
card = CardService.newCardBuilder() \
.addSection(cardSection1) \
.addSection(cardSection2) \
.build()
return card
def build_user_card():
cardSection1DecoratedText1Icon1 = CardService.newIconImage() \
.setIconUrl(
'https://fonts.gstatic.com/s/i/googlematerialicons/email/v6/grey600-24dp/1x/gm_email_grey600_24dp.png' # noqa: E501
)
cardSection1DecoratedText1 = CardService.newDecoratedText() \
.setText('[email protected]') \
.setBottomLabel('Vice president') \
.setStartIcon(cardSection1DecoratedText1Icon1)
cardSection1DecoratedText2Icon1 = CardService.newIconImage() \
.setIconUrl(
'https://fonts.gstatic.com/s/i/googlematerialicons/chat/v6/grey600-24dp/1x/gm_chat_grey600_24dp.png' # noqa: E501
)
cardSection1DecoratedText2 = CardService.newDecoratedText() \
.setText('Online') \
.setBottomLabel('Vice president') \
.setStartIcon(cardSection1DecoratedText2Icon1)
cardSection1DecoratedText3Icon1 = CardService.newIconImage() \
.setIconUrl(
'https://fonts.gstatic.com/s/i/googlematerialicons/call/v6/grey600-24dp/1x/gm_call_grey600_24dp.png' # noqa: E501
)
cardSection1DecoratedText3 = CardService.newDecoratedText() \
.setText('+1 9897671432') \
.setBottomLabel('Vice president') \
.setStartIcon(cardSection1DecoratedText3Icon1)
cardSection1DecoratedText4 = CardService.newDecoratedText() \
.setText('Recent emails')
cardSection1DecoratedText5 = CardService.newDecoratedText() \
.setTopLabel('19:23') \
.setText(
'Greece planning/vacation recommendations — We stayed in Santorini for the first day' # noqa: E501
) \
.setWrapText(True)
cardSection1DecoratedText6 = CardService.newDecoratedText() \
.setTopLabel('Nov 8') \
.setText(
'Chocolate Factory Tour — Congratulations on finding the golden ticket! The tour begins.' # noqa: E501
) \
.setWrapText(True)
cardSection1ButtonList1Button1Action1 = CardService.newAction() \
.setFunctionName('TODO') \
.setParameters({})
cardSection1ButtonList1Button1 = CardService.newTextButton() \
.setText('Fetch more emails') \
.setTextButtonStyle(CardService.TextButtonStyle.TEXT) \
.setOnClickAction(cardSection1ButtonList1Button1Action1)
cardSection1ButtonList1Button2Action1 = CardService.newAction() \
.setFunctionName('TODO') \
.setParameters({})
cardSection1ButtonList1Button2 = CardService.newTextButton() \
.setText('EDIT') \
.setTextButtonStyle(CardService.TextButtonStyle.TEXT) \
.setOnClickAction(cardSection1ButtonList1Button2Action1)
cardSection1ButtonList1Button3Action1 = CardService.newAction() \
.setFunctionName('TODO') \
.setParameters({})
cardSection1ButtonList1Button3 = CardService.newTextButton() \
.setText('MORE..') \
.setTextButtonStyle(CardService.TextButtonStyle.TEXT) \
.setOnClickAction(cardSection1ButtonList1Button3Action1)
cardSection1ButtonList1 = CardService.newButtonSet() \
.addButton(cardSection1ButtonList1Button1) \
.addButton(cardSection1ButtonList1Button2) \
.addButton(cardSection1ButtonList1Button3)
cardSection1 = CardService.newCardSection() \
.setHeader('Contact details') \
.addWidget(cardSection1DecoratedText1) \
.addWidget(cardSection1DecoratedText2) \
.addWidget(cardSection1DecoratedText3) \
.addWidget(cardSection1DecoratedText4) \
.addWidget(cardSection1DecoratedText5) \
.addWidget(cardSection1DecoratedText6) \
.addWidget(cardSection1ButtonList1)
card = CardService.newCardBuilder() \
.addSection(cardSection1) \
.build()
return card
def build_email_card():
cardSection1DecoratedText1Button1Action1 = CardService.newAction() \
.setFunctionName('TODO') \
.setParameters({})
cardSection1DecoratedText1Button1 = CardService.newTextButton() \
.setText('REPLY') \
.setTextButtonStyle(CardService.TextButtonStyle.TEXT) \
.setOnClickAction(cardSection1DecoratedText1Button1Action1) \
cardSection1DecoratedText1 = CardService.newDecoratedText() \
.setText('[email protected]') \
.setBottomLabel('sender') \
.setButton(cardSection1DecoratedText1Button1)
cardSection1DecoratedText2 = CardService.newDecoratedText() \
.setTopLabel('Nov 8') \
.setText(
'Chocolate Factory Tour — Congratulations on finding the golden ticket! The tour begins.' # noqa: E501
) \
.setWrapText(True)
cardSection1DecoratedText3 = CardService.newDecoratedText() \
.setText('Location details')
cardSection1DecoratedText4Icon1 = CardService.newIconImage() \
.setIconUrl(
'https://fonts.gstatic.com/s/i/googlematerialicons/location_on/v6/grey600-36dp/1x/gm_location_on_grey600_36dp.png' # noqa: E501
)
cardSection1DecoratedText4 = CardService.newDecoratedText() \
.setText('274 Beacon Dr, Bradenton, FL 34203') \
.setStartIcon(cardSection1DecoratedText4Icon1) \
.setWrapText(True)
cardSection1Image1 = CardService.newImage() \
.setImageUrl('https://huurbs.com/images/google-map.jpg') \
.setAltText('Placeholder image') \
cardSection1 = CardService.newCardSection() \
.setHeader('Contact details') \
.addWidget(cardSection1DecoratedText1) \
.addWidget(cardSection1DecoratedText2) \
.addWidget(cardSection1DecoratedText3) \
.addWidget(cardSection1DecoratedText4) \
.addWidget(cardSection1Image1)
card = CardService.newCardBuilder() \
.addSection(cardSection1) \
.build()
return card
def build_form_controls_card():
cardSection1TextInput1 = CardService.newTextInput() \
.setFieldName('name') \
.setTitle('Name') \
.setMultiline(False)
cardSection1TextInput2 = CardService.newTextInput() \
.setFieldName('email') \
.setTitle('Email') \
.setMultiline(False)
cardSection1TextInput3 = CardService.newTextInput() \
.setFieldName('address') \
.setTitle('Address') \
.setMultiline(True)
cardSection1DatePTimePicker1 = CardService.newDateTimePicker() \
.setFieldName('dateTime') \
.setTitle('Pick a date and time')
cardSection1DecoratedText1Switch1 = CardService.newSwitch() \
.setControlType(CardService.SwitchControlType.CHECK_BOX) \
.setFieldName('saveFavorite')
cardSection1DecoratedText1 = CardService.newDecoratedText() \
.setText('Add to favorites') \
.setSwitchControl(cardSection1DecoratedText1Switch1)
cardSection1DecoratedText2Switch1 = CardService.newSwitch() \
.setControlType(CardService.SwitchControlType.CHECK_BOX) \
.setFieldName('mergeContact')
cardSection1DecoratedText2 = CardService.newDecoratedText() \
.setText('Merge with existing contacts') \
.setSwitchControl(cardSection1DecoratedText2Switch1)
cardSection1SelectionInput1 = CardService.newSelectionInput() \
.setFieldName('contactType') \
.setTitle('Contact type') \
.setType(CardService.SelectionInputType.RADIO_BUTTON) \
.addItem('Work', 'Work', False) \
.addItem('Personal', 'Personal', False)
cardSection1ButtonList1Button1Action1 = CardService.newAction() \
.setFunctionName('TODO') \
.setParameters({})
cardSection1ButtonList1Button1 = CardService.newTextButton() \
.setText('Submit') \
.setBackgroundColor('#66b73a') \
.setTextButtonStyle(CardService.TextButtonStyle.FILLED) \
.setOnClickAction(cardSection1ButtonList1Button1Action1)
cardSection1ButtonList1Button2Action1 = CardService.newAction() \
.setFunctionName('TODO') \
.setParameters({})
cardSection1ButtonList1Button2 = CardService.newTextButton() \
.setText('EDIT') \
.setTextButtonStyle(CardService.TextButtonStyle.TEXT) \
.setOnClickAction(cardSection1ButtonList1Button2Action1)
cardSection1ButtonList1Button3Action1 = CardService.newAction() \
.setFunctionName('TODO') \
.setParameters({})
cardSection1ButtonList1Button3 = CardService.newTextButton() \
.setText('MORE..') \
.setTextButtonStyle(CardService.TextButtonStyle.TEXT) \
.setOnClickAction(cardSection1ButtonList1Button3Action1)
cardSection1ButtonList1 = CardService.newButtonSet() \
.addButton(cardSection1ButtonList1Button1) \
.addButton(cardSection1ButtonList1Button2) \
.addButton(cardSection1ButtonList1Button3)
cardSection1 = CardService.newCardSection() \
.setHeader('Add new contact') \
.addWidget(cardSection1TextInput1) \
.addWidget(cardSection1TextInput2) \
.addWidget(cardSection1TextInput3) \
.addWidget(cardSection1DatePTimePicker1) \
.addWidget(cardSection1DecoratedText1) \
.addWidget(cardSection1DecoratedText2) \
.addWidget(cardSection1SelectionInput1) \
.addWidget(cardSection1ButtonList1) \
card = CardService.newCardBuilder() \
.addSection(cardSection1) \
.build()
return card