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 pathfolders.py
99 lines (80 loc) · 3.15 KB
/
folders.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
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, MODIFIED_DATE_FIELD, \
DESCRIPTION_FIELD, OBJECT_ID_FIELD, with_properties
from tap_exacttarget.state import incorporate, save_state, \
get_last_record_value_for_table
LOGGER = singer.get_logger()
class FolderDataAccessObject(DataAccessObject):
SCHEMA = with_properties({
'AllowChildren': {
'type': ['null', 'boolean'],
'description': ('Specifies whether a data folder can have '
'child data folders.'),
},
'ContentType': {
'type': ['null', 'string'],
'description': ('Defines the type of content contained '
'within a folder.'),
},
'CreatedDate': CREATED_DATE_FIELD,
'CustomerKey': CUSTOMER_KEY_FIELD,
'Description': DESCRIPTION_FIELD,
'ID': ID_FIELD,
'ModifiedDate': MODIFIED_DATE_FIELD,
'Name': {
'type': ['null', 'string'],
'description': 'Name of the object or property.',
},
'ObjectID': OBJECT_ID_FIELD,
'ParentFolder': {
'type': ['null', 'integer'],
'description': ('Specifies the parent folder for a data '
'folder.'),
},
'PartnerProperties': CUSTOM_PROPERTY_LIST,
'Type': {
'type': ['null', 'string'],
'description': ('Indicates type of specific list. Valid '
'values include Public, Private, Salesforce, '
'GlobalUnsubscribe, and Master.')
}
})
TABLE = 'folder'
KEY_PROPERTIES = ['ID']
def parse_object(self, obj):
to_return = obj.copy()
to_return['ParentFolder'] = to_return.get('ParentFolder', {}).get('ID')
return super(FolderDataAccessObject, self).parse_object(to_return)
def sync_data(self):
table = self.__class__.TABLE
selector = FuelSDK.ET_Folder
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('Folder',
selector,
self.auth_stub,
search_filter)
for folder in stream:
folder = self.filter_keys_and_parse(folder)
self.state = incorporate(self.state,
table,
'ModifiedDate',
folder.get('ModifiedDate'))
singer.write_records(table, [folder])
save_state(self.state)