MambuPy.rest1to2.mambustruct

Functions

import_class(path, _object)

process_filters(filters, kwargs)

set_custom_field(mambuentity[, customfield])

Classes

MambuStruct(*args, **kwargs)

class MambuPy.rest1to2.mambustruct.MambuStruct(*args, **kwargs)[source]

Bases: MambuStruct

DEFAULTS = {}
__contains__(item)[source]

Dict-like and List-like behaviour

__getattribute__(name)[source]

Object-like get attribute

When accessing an attribute, tries to find it in the attrs dictionary, so now MambuStruct may act not only as a dict-like structure, but as a full object-like too (this is the getter side).

__getitem__(key)[source]

Dict-like key query

__init__(*args, **kwargs)[source]

Initializes a new Mambu object.

Parameters:
  • urlfunc (str) – is the only required parameter. The urlfunc returns a string of the URL to make a request to Mambu. You may read about the valid urlfuncs supported by MambuPy at mambuutil.py

  • entid (str) – is the usual ID of a Mambu entity you like to GET from Mambu. The ID of a loan account, a client, a group, etc. Or the transactions or repayments of certain loan account. It’s an optional parameter because the iterable Mambu objects don’t need an specific ID, just some other filtering parameters supported on the urlfunc function.

If you send a None urlfunc, the object will be configured, but won’t connect to Mambu, never. Useful for iterables that configure their elements but can’t or won’t need Mambu to send further information. See mamburepayment.MambuRepayments for an example of this.

Should you need to add support for more functionality, add them at mambuutuil.

Many other arguments may be sent here to further configure the Mambu object or the response by Mambu REST API:

  • debug flag (currently not implemented, just stored on the object)

  • connect flag, to optionally omit the connection to Mambu (see the init() (with no underscores) method pydoc)

  • data parameter for POST requests (see connect() method pydoc)

  • date_format parameter (see util_date_format() method pydoc)

Also, parameters to be sent to Mambu on the request, such as:

  • limit parameter (for pagination, see connect() method pydoc). If 0 (default) tells connect to auto-paginate. All else is used as given for manual pagination (all along with the offset argument too)

  • offset parameter (for pagination, see connect() method pydoc)

  • fullDetails, accountState and other filtering parameters (see mambuutil pydocs)

  • user, password, url to connect to Mambu, to bypass mambuconfig configurations (see mambuutil pydoc)

__init_props(*args, **kwargs)
__len__()[source]

Length of the attrs attribute.

If dict-like (not iterable), it’s the number of keys holded on the attrs dictionary. If list-like (iterable), it’s the number of elements of the attrs list.

__module__ = 'MambuPy.rest1to2.mambustruct'
__repr__()[source]

Mambu object repr tells the class name and the usual ‘id’ for it.

If an iterable, it instead gives its length.

__setattr__(name, value)[source]

Object-like set attribute

When setting an attribute, tries to set it in the attrs dictionary, so now MambuStruct acts not only as a dict-like structure, but as a full object-like too (this is the setter side).

__setitem__(key, value)[source]

Dict-like set

__str__()[source]

Mambu object str gives a string representation of the attrs attribute.

attrs = {}
connect(*args, **kwargs)[source]

Connect to Mambu, make the request to the REST API.

If there’s no urlfunc to use, nothing is done here.

When done, initializes the attrs attribute of the Mambu object by calling the init method. Please refer to that code and pydoc for further information.

Uses urllib module to connect. Since all Mambu REST API responses are json, uses json module to translate the response to a valid python object (dictionary or list).

When Mambu returns a response with returnCode and returnStatus fields, it means something went wrong with the request, and a MambuError is thrown detailing the error given by Mambu itself.

If you need to make a POST request, send a data argument to the new Mambu object.

Provides to prevent errors due to using special chars on the request URL. See mambuutil.iri_to_uri() method pydoc for further info.

Provides to prevent errors due to using special chars on the parameters of a POST request. See mambuutil.encoded_dict() method pydoc for further info.

For every request done, the request counter Singleton is increased.

Includes retry logic, to provide for a max number of connection failures with Mambu. If maximum retries are reached, MambuCommError is thrown.

Includes pagination code. Mambu supports a max of 500 elements per response. Such an ugly detail is wrapped here so further pagination logic is not needed above here. You need a million elements? you got them by making several 500 elements requests later joined together in a sigle list. Just send a limit=0 (default) and that’s it.

Todo

improve raised exception messages. Sometimes MambuCommErrors are thrown due to reasons not always clear when catched down the road, but that perhaps may be noticed in here and aren’t fully reported to the user. Specially serious on retries-MambuCommError situations (the except Exception that increases the retries counter is not saving the exception message, just retrying).

Todo

what about using decorators for the retry and for the window logic? (https://www.oreilly.com/ideas/5-reasons-you-need-to-learn-to-write-python-decorators # Reusing impossible-to-reuse code)

create(data, *args, **kwargs)[source]

Creates an entity in Mambu

This method must be implemented in child classes

Parameters:

data (dictionary) – dictionary with data to send, this dictionary is specific for each Mambu entity

entid_fld = 'entid'
haskey(key)[source]
init(attrs={}, *args, **kwargs)[source]

Default initialization from a dictionary responded by Mambu

in to the elements of the Mambu object.

It assings the response to attrs attribute and converts each of its elements from a string to an adequate python object: number, datetime, etc.

Basically it stores the response on the attrs attribute, then runs some customizable preprocess method, then runs convert_dict_to_attrs method to convert the string elements to an adequate python object, then a customizable postprocess method.

It also executes each method on the ‘methods’ attribute given on instantiation time, and sets new customizable ‘properties’ to the object.

Why not on __init__? two reasons:

  • __init__ optionally connects to Mambu, if you don’t connect to Mambu, the Mambu object will be configured but it won’t have any Mambu info on it. Only when connected, the Mambu object will be initialized, here.

    Useful to POST several times the same Mambu object. You make a POST request over and over again by calling it’s connect() method every time you wish. This init method will configure the response in to the attrs attribute each time.

    You may also wish to update the info on a previously initialized Mambu object and refresh it with what Mambu now has. Instead of building a new object, you just connect() again and it will be refreshed.

  • Iterable Mambu objects (lists) do not initialize here, the iterable Mambu object __init__ goes through each of its elements and then initializes with this code one by one. Please look at some Mambu iterable object code and pydoc for more details.

keys()[source]

Dict-like behaviour

postprocess(*args, **kwargs)[source]
preprocess(*args, **kwargs)[source]
setBranch(*args, **kwargs)[source]
setCentre(*args, **kwargs)[source]
update(data, *args, **kwargs)[source]

Downloads an update made to an entity in Mambu.

This method must be implemented in child classes.

Parameters:

data (dictionary) – data to send

update_patch(data, *args, **kwargs)[source]

Updates an entity in Mambu

This method must be implemented in child classes

Parameters:

data (dictionary) – dictionary with data to send, this dictionary is specific for each Mambu entity

update_post(data, *args, **kwargs)[source]

Updates an entity in Mambu

This method must be implemented in child classes

Parameters:

data (dictionary) – dictionary with data to send, this dictionary is specific for each Mambu entity

upload_document(data, *args, **kwargs)[source]

Uploads a document in Mambu

This method must be implemented in child classes https://support.mambu.com/docs/attachments-api#post-attachments

Parameters:

data (dictionary) – dictionary with data to send

Example: data = {

“document”:{

“documentHolderKey” : self.encodedKey, “documentHolderType” : “LOAN_ACCOUNT”, # CLIENT, GROUP, USER, BRANCH… “name” : “loan_resume”, “type” : “pdf”,

}, “documentContent” : “[‘encodedBase64_file’]”,

}

MambuPy.rest1to2.mambustruct.import_class(path, _object)[source]
MambuPy.rest1to2.mambustruct.process_filters(filters, kwargs)[source]
MambuPy.rest1to2.mambustruct.set_custom_field(mambuentity, customfield='', *args, **kwargs)[source]