MambuPy.api.entities
Mambu Entities
Classes
|
A Mambu object that you may work with directly on Mambu web too. |
|
A Mambu object with attaching capabilities. |
|
A Mambu CustomField obtained via an Entity. |
|
A Mambu object with commenting capabilities. |
|
An entity which allows to be 'owned' by another. |
|
A Mambu object with searching capabilities. |
|
A Mambu object with writing capabilities. |
|
Loan Account Installment (aka Repayment) |
- class MambuPy.api.entities.MambuEntity(**kwargs)[source]
Bases:
MambuStruct
A Mambu object that you may work with directly on Mambu web too.
- classmethod __build_object(connector, resp, attrs, tzattrs, get_entities=False, detailsLevel='BASIC', debug=False)
Builds an instance of an Entity object
- Parameters:
cls (obj) – the object to build
connector (obj) – connector object to Mambu
resp (bytes) – the raw json that originates the object
attrs (dict) – the dict with the values to build the object
tzattrs (dict) – the dict with TZ data for datetimes in attrs
get_entities (bool) – should MambuPy automatically instantiate other MambuPy entities found inside the built entity?
detailsLevel (str) – “BASIC” or “FULL”
debug (bool) – print debugging info
- classmethod __get_several_args(args, get_entities=False, debug=False)
Processes MambuPy.api.entities.get_several arguments.
- Parameters:
cls (obj) – the object for which the args are built
args (dict) – optional arguments received by get_several method
- __module__ = 'MambuPy.api.entities'
- __search_field_in_cfsets(field)
Search for a field in custom field sets for the entity.
Retrieves all the customfieldsets for this entity and looks if the field lives there.
If field is found, returns the path going through the set.
- Parameters:
field (str) – the field to search in customfieldsets
- Returns:
(str) – the path for the field when found or None if not found.
- _connector = None
Default connector (REST)
- _extract_field_path(field, attrs_dict={}, original_keys=[], cf_class=None)[source]
Extracts the path for a given field.
If the field is a Custom Field, the path is given in a property in its attrs dict. (cf MambuPy.api.entities.MambuEntityCF)
If not, first it looks at the original keys in attrs to look if it lives in the root (/) of the entity.
If not, looks for the field in the custom field sets of the entity.
If not, the path does not exists, but it may be a valid path, default to / . Here we are hoping the path is correct, otherwise a PATCH may throw an error.
TODO: perhaps here, in the default case, a better approach would be to implement, and maintain, the schema for each entity as a VO, and validate if field belongs here. If not, default would be an empty string for not being a valid field.
- Parameters:
field (str) – a field for which to extract the path
attrs (dict) – an attrs structure holding the field
original_keys (list) – keys for entity original attrs
cf_class (obj) – the class used for custom field VOs. If the field is a CF in attrs, the path is a property of it. If not, it lives on the “root” of the attrs
- Returns:
(str) – the path to the field.
- _filter_keys = []
allowed filters for get_all filtering
- classmethod _get_several(get_func, connector, **kwargs)[source]
get several entities.
Using certain mambu connector function and its particular arguments.
arg limit has a hard limit imposed by Mambu, that only 1,000 registers can be retrieved, so a pagination must be done to retrieve more registries.
A pagination algorithm (using the offset and the 1,000 limitation) is applied here so that limit may be higher than 1,000 and _get_several will get a all the registers from Mambu in several requests.
- Parameters:
get_func (function) – mambu request function that returns several entities (json [])
connector (obj) – connector object to Mambu
kwargs (dict) –
keyword arguments to pass on to get_func as arguments
prefix (str): prefix for connections to Mambu
kwargs –
keyword arguments to pass on to get_func as params
detailsLevel (str): “BASIC” or “FULL”
offset (int): >= 0
- limit (int): >= 0 If limit=0 or None, the algorithm will retrieve
EVERYTHING according to the given filters, using several requests to that end.
kwargs –
keyword arguments for this method
- get_entities (bool): should MambuPy automatically instantiate
other MambuPy entities found inside the retrieved entities?
debug (bool): print debugging info
- Returns:
list of instances of an entity with data from Mambu, assembled from possibly several calls to get_func
- _prefix = ''
prefix constant for connections to Mambu
- _sortBy_fields = []
allowed fields for get_all sorting
- classmethod get(entid, detailsLevel='BASIC', get_entities=False, **kwargs)[source]
get, a single entity, identified by its entid.
- Parameters:
entid (str) – ID for the entity
detailsLevel (str BASIC/FULL) – ask for extra details or not
get_entities (bool) – should MambuPy automatically instantiate other MambuPy entities found inside the retrieved entity?
kwargs (dict) –
- keyword arguments for this method.
May include a user, pwd and url to connect to Mambu.
debug (bool): print debugging info
- Returns:
instance of an entity with data from Mambu
- classmethod get_all(filters=None, offset=None, limit=None, paginationDetails='OFF', detailsLevel='BASIC', sortBy=None, **kwargs)[source]
get_all, several entities, filtering allowed
- Parameters:
filters (dict) – key-value filters, dependes on each entity (keys must be one of the _filter_keys)
offset (int) – pagination, index to start searching
limit (int) – pagination, number of elements to retrieve
paginationDetails (str ON/OFF) – ask for details on pagination
detailsLevel (str BASIC/FULL) – ask for extra details or not
sortBy (str) –
field1:ASC,field2:DESC
, sorting criteria for results (fields must be one of the _sortBy_fields)kwargs (dict) – extra parameters that a specific entity may receive in its get_all method. May include a user, pwd and url to connect to Mambu.
- Returns:
list of instances of an entity with data from Mambu
- refresh(detailsLevel='')[source]
get again this single entity, identified by its entid.
Updates _attrs with responded data. Loses any change on _attrs that overlaps with anything from Mambu. Leaves alone any other properties that don’t come in the response.
- Parameters:
detailsLevel (str BASIC/FULL) – ask for extra details or not
- class MambuPy.api.entities.MambuEntityAttachable(cf_class=<class 'MambuPy.api.classes.GenericClass'>, **kwargs)[source]
Bases:
MambuStruct
,MambuAttachable
A Mambu object with attaching capabilities.
- __abstractmethods__ = frozenset({})
- __module__ = 'MambuPy.api.entities'
- _abc_impl = <_abc_data object>
- _attachments = {}
dict of attachments of an entity, key is the id
- _ownerType = ''
attachments owner type of this entity
- attach_document(filename, title='', notes='')[source]
uploads an attachment to this entity
_attachments dicitionary gets a new entry with the attached document.
- del_attachment(documentName=None, documentId=None)[source]
deletes an attachment by its documentName.
- Parameters:
- Raises:
MambuPyError – if the documentId and the documentName is not an attachment of the entity
- class MambuPy.api.entities.MambuEntityCF(value, path='', typecf='STANDARD', mcf=None)[source]
Bases:
MambuValueObject
A Mambu CustomField obtained via an Entity.
This is NOT a CustomField obtained through it’s own endpoint, those go in another separate class.
Here you just have a class to manage custom field values living inside some Mambu entity.
- __module__ = 'MambuPy.api.entities'
- class MambuPy.api.entities.MambuEntityCommentable(cf_class=<class 'MambuPy.api.classes.GenericClass'>, **kwargs)[source]
Bases:
MambuStruct
,MambuCommentable
A Mambu object with commenting capabilities.
- __abstractmethods__ = frozenset({})
- __module__ = 'MambuPy.api.entities'
- _abc_impl = <_abc_data object>
- _comments = []
list of comments of an entity
- comment(comment)[source]
Comments this entity
_comments list gets a new entry with comment.
- Parameters:
comment (str) – the text of the comment
- Returns:
Mambu’s response with metadata of the posted comment
- class MambuPy.api.entities.MambuEntityOwnable(cf_class=<class 'MambuPy.api.classes.GenericClass'>, **kwargs)[source]
Bases:
MambuStruct
,MambuOwnable
An entity which allows to be ‘owned’ by another.
An owned entity has an ‘accountHolderKey’ and ‘accountHolderType’ fields.
Because of that, you may call get_accountHolder on the owned entity to instantiate the MambuEntity who owns it.
- __abstractmethods__ = frozenset({})
- __module__ = 'MambuPy.api.entities'
- _abc_impl = <_abc_data object>
- class MambuPy.api.entities.MambuEntitySearchable(cf_class=<class 'MambuPy.api.classes.GenericClass'>, **kwargs)[source]
Bases:
MambuStruct
,MambuSearchable
A Mambu object with searching capabilities.
- __abstractmethods__ = frozenset({})
- __module__ = 'MambuPy.api.entities'
- _abc_impl = <_abc_data object>
- classmethod search(filterCriteria=None, sortingCriteria=None, offset=None, limit=None, paginationDetails='OFF', detailsLevel='BASIC', **kwargs)[source]
search, several entities, filtering criteria allowed
- Parameters:
filterCriteria (list of dicts) – fields according to each entity FilterCriteria schema
sortingCriteria (dict) – fields according to each entity SortingCriteria
offset (int) – pagination, index to start searching
limit (int) – pagination, number of elements to retrieve
paginationDetails (str ON/OFF) – ask for details on pagination
detailsLevel (str BASIC/FULL) – ask for extra details or not
- Returns:
list of instances of an entity with data from Mambu
- class MambuPy.api.entities.MambuEntityWritable(cf_class=<class 'MambuPy.api.classes.GenericClass'>, **kwargs)[source]
Bases:
MambuStruct
,MambuWritable
A Mambu object with writing capabilities.
- __abstractmethods__ = frozenset({})
- __module__ = 'MambuPy.api.entities'
- __patch_field_op(field, original_attrs)
Returns a valid ADD or REPLACE operation tuple for a field in attrs.
- __patch_op(operation, attrs, original_keys, field, cf_class)
Returns a patch operation tuple.
- Parameters:
- Returns:
(tuple) – according to the PATCH operation None: in case the field is not a valid attribute to patch
- _abc_impl = <_abc_data object>
- create()[source]
creates a mambu entity
Uses the current values of the _attrs to send to Mambu. Pre-requires that CustomFields are updated previously. Post-requires that CustomFields are extracted again.
- patch(fields=None, autodetect_remove=False)[source]
patches a mambu entity
Allows patching of parts of the entity up to Mambu.
fields is a list of the keys in the _attrs that will be sent to Mambu
autodetect automatically searches for deleted fields and patches a remove in Mambu.
Pre-requires that CustomFields are updated previously. Post-requires that CustomFields are extracted again.
- Parameters:
fields (list of str) – list of ids of fields to explicitly patch
autodetect_remove (bool) – False: if deleted fields, don’t remove them True: if delete field, remove them
Autodetect operation, for any field (every field if fields param is None):
ADD: in attrs, but not in resp
REPLACE: in attrs, and in resp
REMOVE: not in attrs, but in resp
MOVE: not yet implemented (how to autodetect? request needs ‘from’ element)
- Raises:
MambuPyError – if field not in attrrs, and not in resp