-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_api-calls.py
More file actions
executable file
·119 lines (101 loc) · 2.5 KB
/
_api-calls.py
File metadata and controls
executable file
·119 lines (101 loc) · 2.5 KB
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
#!/usr/bin/env python3
'''
Purpose: API call demo for request & response
'''
from utils import *
data = {
'Requests': [
{
'Status': 'Denied',
'Account': 1111,
'Alias': 'AAAA',
'SKU': 'A SKU',
'BU': 'A BU',
'Owners': [
{
'FullName': 'John Due',
'SSO': 123,
'Title': 'John\'s title',
'Mail': 'john.due@domain.com'
}
]
},
{
'Status': 'Granted',
'Account': 2222,
'Alias': 'BBBB',
'SKU': 'B SKU',
'BU': 'B BU',
'Owners': [
{
'FullName': 'Jean Due',
'SSO': 456,
'Title': 'Jean\'s title',
'Mail': 'jean.due@domain.com'
}
]
},
{
'Status': 'Requested',
'Account': 3333,
'Alias': 'CCCC',
'SKU': 'C SKU',
'BU': 'C BU',
'Owners': [
{
'FullName': 'Jean Due',
'SSO': 456,
'Title': 'Jean\'s title',
'Mail': 'jean.due@domain.com'
}
]
}
],
'Request': {
'SSO': 222,
'FullName': 'John Smith',
'Datetime': iso8601Time()
}
}
ppwide('Lambda response Demo')
printll('Lambda request / data / raw')
ppjson(data)
wline()
printll('Lambda response data / raw')
req = api_req(200, 'Denied', data)
ppjson(req)
printll('Lambda response data / api_res(res, full=True)')
res = api_res(req, full=True)
ppjson(res)
printll('Lambda response data / api_res(res, full=False)')
res = api_res(req, full=False)
ppjson(res)
printll('Lambda response data / json loads / format')
blue_green_dict_print(res['Request'], ' : ')
wline()
COLS = {
'#': 5,
'Status': 10,
'Data': 50
}
print(
justr('', COLS['#']),
justl('Status', COLS['Status']),
justl('Data', COLS['Data'])
)
wline()
for i, r in enumerate(res['Requests']):
stat = r['Status']
r.pop('Status')
r.pop('Owners')
if stat.lower() == 'granted':
color = 'Green'
if stat.lower() == 'denied':
color = 'Red'
if stat.lower() == 'requested':
color = 'Yellow'
print(
justr(f'{i+1}.', COLS['#']),
iColor(justl(stat, COLS['Status']), color),
justl(r, COLS['Data'])
)