This repository was archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathobjects.py
406 lines (328 loc) · 13.1 KB
/
objects.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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
from FuelSDK.rest import ET_CUDSupport,ET_CUDSupportRest,ET_GetSupport,ET_Get,ET_Patch,ET_Post,ET_Delete,ET_Configure,ET_Describe
########
##
## wrap an Exact Target Content Area
##
########
class ET_ContentArea(ET_CUDSupport):
def __init__(self):
super(ET_ContentArea, self).__init__()
self.obj_type = 'ContentArea'
########
##
## wrap an Exact Target DataFolder
##
########
class ET_Folder(ET_CUDSupport):
def __init__(self):
super(ET_Folder, self).__init__()
self.obj_type = 'DataFolder'
########
##
## wrap an Exact Target PropertyDefinition
##
########
class ET_ProfileAttribute():
def __init__(self):
self.obj_type = 'PropertyDefinition'
self.update = False
self.delete = False
def post(self):
obj = ET_Configure(self.auth_stub, self.obj_type, self.props, self.update, self.delete)
if obj is not None:
self.last_request_id = obj.request_id
return obj
def get(self):
return ET_Describe(self.auth_stub, 'Subscriber')
########
##
## wrap an Exact Target Bounce Event
##
########
class ET_BounceEvent(ET_GetSupport):
def __init__(self):
self.obj_type = 'BounceEvent'
########
##
## wrap an Exact Target Campaign and associated Assets
##
########
class ET_Campaign(ET_CUDSupportRest):
def __init__(self):
super(ET_Campaign, self).__init__()
self.path = '/hub/v1/campaigns/{id}'
self.urlProps = ["id"]
self.urlPropsRequired = []
##the patch rest service is not implemented for campaigns yet. use post instead and remove this when patch is implemented on the back end
def patch(self):
self.path = '/hub/v1/campaigns' #don't put the id on the url when patching via post
obj = super(ET_Campaign, self).post()
self.path = '/hub/v1/campaigns/{id}' #but set it back to the url with id for other operations to continue working
return obj
class ET_Campaign_Asset(ET_CUDSupportRest):
def __init__(self):
super(ET_Campaign_Asset, self).__init__()
self.path = '/hub/v1/campaigns/{id}/assets/{assetId}'
self.urlProps = ["id", "assetId"]
self.urlPropsRequired = ["id"]
########
##
## wrap an Exact Target Click Event
##
########
class ET_ClickEvent(ET_GetSupport):
def __init__(self):
super(ET_ClickEvent, self).__init__()
self.obj_type = 'ClickEvent'
########
##
## wrap an Exact Target List and List Subscriber
##
########
class ET_Group(ET_CUDSupport):
def __init__(self):
super(ET_Group, self).__init__()
self.obj_type = 'Group'
class ET_Send(ET_CUDSupport):
def __init__(self):
super(ET_Send, self).__init__()
self.obj_type = 'Send'
class ET_ListSend(ET_CUDSupport):
def __init__(self):
super(ET_ListSend, self).__init__()
self.obj_type = 'ListSend'
class ET_List(ET_CUDSupport):
def __init__(self):
super(ET_List, self).__init__()
self.obj_type = 'List'
class ET_List_Subscriber(ET_GetSupport):
def __init__(self):
super(ET_List_Subscriber, self).__init__()
self.obj_type = 'ListSubscriber'
class ET_SubscriberList(ET_GetSupport):
def __init__(self):
super(ET_SubscriberList, self).__init__()
self.obj_type = 'SubscriberList'
class ET_SentEvent(ET_GetSupport):
def __init__(self):
super(ET_SentEvent, self).__init__()
self.obj_type = 'SentEvent'
class ET_OpenEvent(ET_GetSupport):
def __init__(self):
super(ET_OpenEvent, self).__init__()
self.obj_type = 'OpenEvent'
class ET_UnsubEvent(ET_GetSupport):
def __init__(self):
super(ET_UnsubEvent, self).__init__()
self.obj_type = 'UnsubEvent'
class ET_Email(ET_CUDSupport):
def __init__(self):
super(ET_Email, self).__init__()
self.obj_type = 'Email'
class ET_TriggeredSend(ET_CUDSupport):
subscribers = None
attributes = None
def __init__(self):
super(ET_TriggeredSend, self).__init__()
self.obj_type = 'TriggeredSendDefinition'
def send(self):
tscall = {"TriggeredSendDefinition":self.props, "Subscribers" : self.subscribers, "Attributes": self.attributes }
self.obj = ET_Post(self.auth_stub, "TriggeredSend", tscall)
return self.obj
class ET_Subscriber(ET_CUDSupport):
def __init__(self):
super(ET_Subscriber, self).__init__()
self.obj_type = 'Subscriber'
class ET_DataExtension(ET_CUDSupport):
columns = None
def __init__(self):
super(ET_DataExtension, self).__init__()
self.obj_type = 'DataExtension'
def post(self):
originalProps = self.props
if type(self.props) is list:
multiDE = []
for currentDE in self.props:
currentDE['Fields'] = {}
currentDE['Fields']['Field'] = []
for key in currentDE['columns']:
currentDE['Fields']['Field'].append(key)
del currentDE['columns']
multiDE.append(currentDE.copy())
self.props = multiDE
else:
self.props['Fields'] = {}
self.props['Fields']['Field'] = []
for key in self.columns:
self.props['Fields']['Field'].append(key)
obj = super(ET_DataExtension, self).post()
self.props = originalProps
return obj
def patch(self):
self.props['Fields'] = {}
self.props['Fields']['Field'] = []
for key in self.columns:
self.props['Fields']['Field'].append(key)
obj = super(ET_DataExtension, self).patch()
del self.props["Fields"]
return obj
class ET_DataExtension_Column(ET_GetSupport):
def __init__(self):
super(ET_DataExtension_Column, self).__init__()
self.obj = 'DataExtensionField'
def get(self):
'''
if props and props.is_a? Array then
@props = props
end
'''
if self.props is not None and type(self.props) is dict:
self.props = self.props.keys()
'''
if filter and filter.is_a? Hash then
@filter = filter
end
'''
'''
fixCustomerKey = False
if filter and filter.is_a? Hash then
@filter = filter
if @filter.has_key?("Property") && @filter["Property"] == "CustomerKey" then
@filter["Property"] = "DataExtension.CustomerKey"
fixCustomerKey = true
end
end
'''
obj = ET_Get(self.auth_stub, self.obj, self.props, self.search_filter)
self.last_request_id = obj.request_id
'''
if fixCustomerKey then
@filter["Property"] = "CustomerKey"
end
'''
return obj
class ET_DataExtension_Row(ET_CUDSupport):
Name = None
CustomerKey = None
def __init__(self):
super(ET_DataExtension_Row, self).__init__()
self.obj_type = "DataExtensionObject"
def get(self):
self.getName()
'''
if props and props.is_a? Array then
@props = props
end
'''
if self.props is not None and type(self.props) is dict:
self.props = self.props.keys()
'''
if filter and filter.is_a? Hash then
@filter = filter
end
'''
obj = ET_Get(self.auth_stub, "DataExtensionObject[{0}]".format(self.Name), self.props, self.search_filter)
self.last_request_id = obj.request_id
return obj
def post(self):
self.getCustomerKey()
originalProps = self.props
if type(self.props) is list:
currentPropList = []
for rec in self.props:
currentFields = []
currentProp = {}
for key, value in rec.items():
currentFields.append({"Name" : key, "Value" : value})
currentProp['CustomerKey'] = self.CustomerKey
currentProp['Properties'] = {}
currentProp['Properties']['Property'] = currentFields
currentPropList.append(currentProp)
currentProp = currentPropList
else:
currentFields = []
currentProp = {}
for key, value in self.props.items():
currentFields.append({"Name" : key, "Value" : value})
currentProp['CustomerKey'] = self.CustomerKey
currentProp['Properties'] = {}
currentProp['Properties']['Property'] = currentFields
obj = ET_Post(self.auth_stub, self.obj_type, currentProp)
self.props = originalProps
return obj
def patch(self):
self.getCustomerKey()
if type(self.props) is list:
currentPropList = []
for rec in self.props:
currentFields = []
currentProp = {}
for key, value in rec.items():
currentFields.append({"Name" : key, "Value" : value})
currentProp['CustomerKey'] = self.CustomerKey
currentProp['Properties'] = {}
currentProp['Properties']['Property'] = currentFields
currentPropList.append(currentProp)
currentProp = currentPropList
else:
currentFields = []
currentProp = {}
for key, value in self.props.items():
currentFields.append({"Name" : key, "Value" : value})
currentProp['CustomerKey'] = self.CustomerKey
currentProp['Properties'] = {}
currentProp['Properties']['Property'] = currentFields
obj = ET_Patch(self.auth_stub, self.obj_type, currentProp)
return obj
def delete(self):
self.getCustomerKey()
if type(self.props) is list:
currentPropList = []
for rec in self.props:
currentFields = []
currentProp = {}
for key, value in rec.items():
currentFields.append({"Name" : key, "Value" : value})
currentProp['CustomerKey'] = self.CustomerKey
currentProp['Keys'] = {}
currentProp['Keys']['Key'] = currentFields
currentPropList.append(currentProp)
currentProp = currentPropList
else:
currentFields = []
currentProp = {}
for key, value in self.props.items():
currentFields.append({"Name" : key, "Value" : value})
currentProp['CustomerKey'] = self.CustomerKey
currentProp['Keys'] = {}
currentProp['Keys']['Key'] = currentFields
obj = ET_Delete(self.auth_stub, self.obj_type, currentProp)
return obj
def getCustomerKey(self):
if self.CustomerKey is None:
if self.Name is None:
raise Exception('Unable to process DataExtension::Row request due to CustomerKey and Name not being defined on ET_DatExtension::row')
else:
de = ET_DataExtension()
de.auth_stub = self.auth_stub
de.props = ["Name","CustomerKey"]
de.search_filter = {'Property' : 'Name','SimpleOperator' : 'equals','Value' : self.Name}
getResponse = de.get()
if getResponse.status and len(getResponse.results) == 1 and 'CustomerKey' in getResponse.results[0]:
self.CustomerKey = getResponse.results[0]['CustomerKey']
else:
raise Exception('Unable to process DataExtension::Row request due to unable to find DataExtension based on Name')
def getName(self):
if self.Name is None:
if self.CustomerKey is None:
raise Exception('Unable to process DataExtension::Row request due to CustomerKey and Name not being defined on ET_DatExtension::row')
else:
de = ET_DataExtension()
de.auth_stub = self.auth_stub
de.props = ["Name","CustomerKey"]
de.search_filter = {'Property' : 'CustomerKey','SimpleOperator' : 'equals','Value' : self.CustomerKey}
getResponse = de.get()
if getResponse.status and len(getResponse.results) == 1 and 'Name' in getResponse.results[0]:
self.Name = getResponse.results[0]['Name']
else:
raise Exception('Unable to process DataExtension::Row request due to unable to find DataExtension based on CustomerKey')