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 pathemails.py
158 lines (141 loc) · 5.57 KB
/
emails.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
import FuelSDK
import singer
from tap_exacttarget.client import request
from tap_exacttarget.dao import DataAccessObject
from tap_exacttarget.schemas import ID_FIELD, CUSTOM_PROPERTY_LIST, \
CREATED_DATE_FIELD, CUSTOMER_KEY_FIELD, OBJECT_ID_FIELD, \
MODIFIED_DATE_FIELD, with_properties
from tap_exacttarget.state import incorporate, save_state, \
get_last_record_value_for_table
LOGGER = singer.get_logger()
class EmailDataAccessObject(DataAccessObject):
SCHEMA = with_properties({
'CategoryID': {
'type': ['null', 'integer'],
'description': ('Specifies the identifier of the folder '
'containing the email.'),
},
'CharacterSet': {
'type': ['null', 'string'],
'description': ('Indicates encoding used in an email '
'message.'),
},
'ClonedFromID': {
'type': ['null', 'integer'],
'description': ('ID of email message from which the specified '
'email message was created.'),
},
'ContentAreaIDs': {
'type': 'array',
'description': ('Contains information on content areas '
'included in an email message.'),
'items': {
'type': ['null', 'integer']
}
},
'ContentCheckStatus': {
'type': ['null', 'string'],
'description': ('Indicates whether content validation has '
'completed for this email message.'),
},
'CreatedDate': CREATED_DATE_FIELD,
'CustomerKey': CUSTOMER_KEY_FIELD,
'EmailType': {
'type': ['null', 'string'],
'description': ('Defines preferred email type.'),
},
'HasDynamicSubjectLine': {
'type': ['null', 'boolean'],
'description': ('Indicates whether email message contains '
'a dynamic subject line.'),
},
'HTMLBody': {
'type': ['null', 'string'],
'description': ('Contains HTML body of an email message.'),
},
'ID': ID_FIELD,
'IsActive': {
'type': ['null', 'boolean'],
'description': ('Specifies whether the object is active.')
},
'IsHTMLPaste': {
'type': ['null', 'boolean'],
'description': ('Indicates whether email message was created '
'via pasted HTML.')
},
'ModifiedDate': MODIFIED_DATE_FIELD,
'Name': {
'type': ['null', 'string'],
'description': 'Name of the object or property.',
},
'ObjectID': OBJECT_ID_FIELD,
'PartnerProperties': CUSTOM_PROPERTY_LIST,
'PreHeader': {
'type': ['null', 'string'],
'description': ('Contains text used in preheader of email '
'message on mobile devices.')
},
'Status': {
'type': ['null', 'string'],
'description': ('Defines status of object. Status of an '
'address.'),
},
'Subject': {
'type': ['null', 'string'],
'description': ('Contains subject area information for a '
'message.'),
},
'SyncTextWithHTML': {
'type': ['null', 'boolean'],
'description': ('Makes the text version of an email contain '
'the same content as the HTML version.'),
},
'TextBody': {
'type': ['null', 'string'],
'description': ('Contains raw text body of a message.'),
},
'__AdditionalEmailAttribute1': {'type': ['null', 'string']},
'__AdditionalEmailAttribute2': {'type': ['null', 'string']},
'__AdditionalEmailAttribute3': {'type': ['null', 'string']},
'__AdditionalEmailAttribute4': {'type': ['null', 'string']},
'__AdditionalEmailAttribute5': {'type': ['null', 'string']},
})
TABLE = 'email'
KEY_PROPERTIES = ['ID']
def parse_object(self, obj):
to_return = obj.copy()
content_area_ids = []
for content_area in to_return.get('ContentAreas', []):
content_area_ids.append(content_area.get('ID'))
to_return['EmailID'] = to_return.get('Email', {}).get('ID')
to_return['ContentAreaIDs'] = content_area_ids
return super(EmailDataAccessObject, self).parse_object(to_return)
def sync_data(self):
table = self.__class__.TABLE
selector = FuelSDK.ET_Email
search_filter = None
retrieve_all_since = get_last_record_value_for_table(
self.state,
table,
self.config.get('start_date'),
self.config.get('offset_start_date', None),
self.is_full_table_mode()
)
if retrieve_all_since is not None:
search_filter = {
'Property': 'ModifiedDate',
'SimpleOperator': 'greaterThan',
'Value': retrieve_all_since
}
stream = request('Email',
selector,
self.auth_stub,
search_filter)
for email in stream:
email = self.filter_keys_and_parse(email)
self.state = incorporate(self.state,
table,
'ModifiedDate',
email.get('ModifiedDate'))
singer.write_records(table, [email])
save_state(self.state)