This repository has been archived by the owner on Nov 19, 2024. It is now read-only.
forked from singer-io/tap-exacttarget
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsubscribers.py
157 lines (137 loc) · 5.15 KB
/
subscribers.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
import FuelSDK
import singer
from tap_exacttarget.client import request
from tap_exacttarget.dao import DataAccessObject
from tap_exacttarget.schemas import CUSTOM_PROPERTY_LIST, ID_FIELD, \
CREATED_DATE_FIELD, CUSTOMER_KEY_FIELD, OBJECT_ID_FIELD, \
SUBSCRIBER_KEY_FIELD, MODIFIED_DATE_FIELD, with_properties
LOGGER = singer.get_logger()
SCHEMA = with_properties({
'Addresses': {
'type': 'array',
'description': ('Indicates addresses belonging to a subscriber, '
'used to create, retrieve, update or delete an '
'email or SMS Address for a given subscriber.'),
'items': {
'type': 'object',
'properties': {
'Address': {'type': ['null', 'string']},
'AddressType': {'type': ['null', 'string']},
'AddressStatus': {'type': ['null', 'string']}
}
}
},
'Attributes': CUSTOM_PROPERTY_LIST,
'CreatedDate': CREATED_DATE_FIELD,
'CustomerKey': CUSTOMER_KEY_FIELD,
'EmailAddress': {
'type': ['null', 'string'],
'description': ('Contains the email address for a subscriber. '
'Indicates the data extension field contains '
'email address data.'),
},
'EmailTypePreference': {
'type': ['null', 'string'],
'description': 'The format in which email should be sent'
},
'ID': ID_FIELD,
'ListIDs': {
'type': 'array',
'description': 'Defines list IDs a subscriber resides on.',
'items': {
'type': ['null', 'string']
}
},
'Locale': {
'type': ['null', 'string'],
'description': ('Contains the locale information for an Account. '
'If no location is set, Locale defaults to en-US '
'(English in United States).'),
},
'ModifiedDate': MODIFIED_DATE_FIELD,
'ObjectID': OBJECT_ID_FIELD,
'PartnerKey': {
'type': ['null', 'string'],
'description': ('Unique identifier provided by partner for an '
'object, accessible only via API.'),
},
'PartnerProperties': CUSTOM_PROPERTY_LIST,
'PartnerType': {
'type': ['null', 'string'],
'description': 'Defines partner associated with a subscriber.'
},
'PrimaryEmailAddress': {
'type': ['null', 'string'],
'description': 'Indicates primary email address for a subscriber.'
},
'PrimarySMSAddress': {
'type': ['null', 'string'],
'description': ('Indicates primary SMS address for a subscriber. '
'Used to create and update SMS Address for a '
'given subscriber.'),
},
'PrimarySMSPublicationStatus': {
'type': ['null', 'string'],
'description': 'Indicates the subscriber\'s modality status.',
},
'Status': {
'type': ['null', 'string'],
'description': 'Defines status of object. Status of an address.',
},
'SubscriberKey': SUBSCRIBER_KEY_FIELD,
'SubscriberTypeDefinition': {
'type': ['null', 'string'],
'description': ('Specifies if a subscriber resides in an '
'integration, such as Salesforce or Microsoft '
'Dynamics CRM'),
},
'UnsubscribedDate': {
'type': ['null', 'string'],
'description': ('Represents date subscriber unsubscribed '
'from a list.'),
}
})
class SubscriberDataAccessObject(DataAccessObject):
SCHEMA = SCHEMA
TABLE = 'subscriber'
KEY_PROPERTIES = ['ID']
def parse_object(self, obj):
to_return = obj.copy()
if 'ListIDs' in to_return:
to_return['ListIDs'] = [_list.get('ObjectID')
for _list in to_return.get('Lists', [])]
if 'Lists' in to_return:
del to_return['Lists']
if to_return.get('Addresses') is None:
to_return['Addresses'] = []
if to_return.get('PartnerProperties') is None:
to_return['PartnerProperties'] = []
return super(SubscriberDataAccessObject, self).parse_object(obj)
def sync_data(self):
pass
def pull_subscribers_batch(self, subscriber_keys):
if not subscriber_keys:
return
table = self.__class__.TABLE
_filter = {}
if len(subscriber_keys) == 1:
_filter = {
'Property': 'SubscriberKey',
'SimpleOperator': 'equals',
'Value': subscriber_keys[0]
}
elif len(subscriber_keys) > 1:
_filter = {
'Property': 'SubscriberKey',
'SimpleOperator': 'IN',
'Value': subscriber_keys
}
else:
LOGGER.info('Got empty set of subscriber keys, moving on')
return
stream = request(
'Subscriber', FuelSDK.ET_Subscriber, self.auth_stub, _filter)
for subscriber in stream:
subscriber = self.filter_keys_and_parse(subscriber)
subscriber = self.remove_sensitive_data(subscriber)
singer.write_records(table, [subscriber])