def _get_fields(self, extensions): to_return = extensions.copy() result = request('DataExtensionField', FuelSDK.ET_DataExtension_Column, self.auth_stub) for field in result: extension_id = field.DataExtension.CustomerKey field = sudsobj_to_dict(field) field_name = field['Name'] if field.get('IsPrimaryKey'): to_return = _merge_in(to_return, [extension_id, 'key_properties'], field_name) field_schema = { 'type': [ 'null', _convert_extension_datatype(str(field.get('FieldType'))) ], 'description': str(field.get('Description')), } to_return = set_in( to_return, [extension_id, 'schema', 'properties', field_name], field_schema) return to_return
def _get_all_subscribers_list(self): """ Find the 'All Subscribers' list via the SOAP API, and return it. """ result = request('List', FuelSDK.ET_List, self.auth_stub, { 'Property': 'ListName', 'SimpleOperator': 'equals', 'Value': 'All Subscribers', }) lists = list(result) if len(lists) != 1: msg = ('Found {} all subscriber lists, expected one!' .format(len(lists))) raise RuntimeError(msg) return sudsobj_to_dict(lists[0])
def filter_keys_and_parse(self, obj): to_return = self.parse_object(sudsobj_to_dict(obj)) obj_schema = self.catalog['schema']['properties'] for k, v in to_return.items(): field_schema = obj_schema.get(k, {}) # sometimes data extension fields have type integer or # number, but come back as strings from the API. we need # to explicitly cast them. if v is None: pass elif 'integer' in field_schema.get('type'): to_return[k] = int(v) elif 'number' in field_schema.get('type'): to_return[k] = float(v) return to_return
def _get_fields(self, extensions): to_return = extensions.copy() result = request( 'DataExtensionField', FuelSDK.ET_DataExtension_Column, self.auth_stub) for field in result: extension_id = field.DataExtension.CustomerKey field = sudsobj_to_dict(field) field_name = field['Name'] if field.get('IsPrimaryKey'): to_return = _merge_in( to_return, [extension_id, 'key_properties'], field_name) field_schema = { 'type': [ 'null', _convert_extension_datatype(str(field.get('FieldType'))) ], 'description': str(field.get('Description')), } to_return = set_in( to_return, [extension_id, 'schema', 'properties', field_name], field_schema) # These fields are defaulted into the schema, do not add to metadata again. if field_name not in {'_CustomObjectKey', 'CategoryID'}: to_return[extension_id]['metadata'].append({ 'breadcrumb': ('properties', field_name), 'metadata': {'inclusion': 'available'} }) return to_return
def filter_keys_and_parse(self, obj): to_return = self.parse_object(sudsobj_to_dict(obj)) obj_schema = self.catalog['schema']['properties'] for k, v in to_return.items(): field_schema = obj_schema.get(k, {}) # sometimes data extension fields have type integer or # number, but come back as strings from the API. we need # to explicitly cast them. if v is None: pass elif 'integer' in field_schema.get('type'): to_return[k] = int(v) elif 'number' in field_schema.get('type'): to_return[k] = float(v) elif ('boolean' in field_schema.get('type') and isinstance(to_return[k], str)): # Extension bools can come through as a number of values, see: # https://help.salesforce.com/articleView?id=mc_es_data_extension_data_types.htm&type=5 # In practice, looks like they come through as either "True" # or "False", but for completeness I have included the other # possible values. if str(to_return[k]).lower() in [1, "1", "y", "yes", "true"]: to_return[k] = True elif str(to_return[k]).lower() in [0, "0", "n", "no", "false"]: to_return[k] = False else: LOGGER.warn('Could not infer boolean value from {}'.format( to_return[k])) to_return[k] = None return to_return
def filter_keys_and_parse(self, obj): to_return = sudsobj_to_dict(obj) return self.parse_object(to_return)