This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
forked from entone/cm-py
-
Notifications
You must be signed in to change notification settings - Fork 1
/
campaign_monitor.py
58 lines (45 loc) · 2.13 KB
/
campaign_monitor.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
from Soap import *
from settings import *
class CampaignMonitor(SoapObject):
def __init__(self, **kwargs):
self.extra_keys['ApiKey'] = CAMPAIGN_MONITOR_KEY
SoapObject.__init__(self, CAMPAIGN_MONITOR_NAMESPACE, CAMPAIGN_MONITOR_URL, self.parse, True, **kwargs)
def parse(self, method, soap_resp):
doc = minidom.parseString(soap_resp)
if doc.hasChildNodes():
result_nodes = doc.getElementsByTagName(method+"Result")
if len(result_nodes) == 1:
node = result_nodes[0]
rtype = node._attrs.get('xsi:type')
if rtype: rtype = rtype.value
else: rtype='boop'
if not node.firstChild.hasChildNodes(): return node.firstChild.nodeValue
elif rtype.startswith('Array'):
arr = []
for node_list in node.childNodes:
node_info = {}
for i in node_list.childNodes:
node_info[i.nodeName] = i.firstChild.nodeValue
arr.append(node_info)
return arr
elif rtype.startswith('Client'):
node_info = {}
for i in node.childNodes:
node_info[i.nodeName] = {}
for ii in i.childNodes:
if ii.firstChild: node_info[i.nodeName][ii.nodeName] = ii.firstChild.nodeValue
else: node_info[i.nodeName][ii.nodeName] = ii.nodeValue
return node_info
else:
node_info = {}
for i in node.childNodes:
node_info[i.nodeName] = i.firstChild.nodeValue
return node_info
return None
class Client(CampaignMonitor): pass
class List(CampaignMonitor): pass
class Subscriber(CampaignMonitor): pass
class Subscribers(CampaignMonitor): pass
class Template(CampaignMonitor): pass
class Campaign(CampaignMonitor): pass
class User(CampaignMonitor): pass