Compare commits

..

No commits in common. "49a4ecc07f68182c32d59f0c41ede21085e0101d" and "8f4a7b1f6d2ea053e1a917b74244d8ee4afc7d85" have entirely different histories.

4 changed files with 47 additions and 11 deletions

View File

@ -16,7 +16,10 @@ c = mitel_ommclient2.OMMClient2("omm.local", "admin", "admin")
c.ping() c.ping()
# Create custom messages # Create custom messages
r = c.connection.request(mitel_ommclient2.messages.Ping(timeStamp=2342)) r = c.request(mitel_ommclient2.messages.Ping(timeStamp=2342))
# Craft your own request, if it is not implemented yet
r = c.request(mitel_ommclient2.messages.DictRequest("Ping", {"timeStamp": 2342}))
``` ```
Consult class documentation for more in depth examples and options. Consult class documentation for more in depth examples and options.

View File

@ -37,7 +37,6 @@ validate common API requests. See class documentation to get and overview and op
Making custom requests Making custom requests
---------------------- ----------------------
:class:`mitel_ommclient2.client.OMMClient2` holds its :class:`mitel_ommclient2.connection.Connection` :func:`mitel_ommclient2.client.OMMClient2.request` allowes you to send custom requests.
in the connection attribute. It just passes arguments and results to :func:`mitel_ommclient2.connection.Connection.request`.
Use :func:`mitel_ommclient2.connection.Connection.request` directly for making some custom requests.
See :doc:`/manual/connection` about using this. See :doc:`/manual/connection` about using this.

View File

@ -23,7 +23,7 @@ class OMMClient2:
Use request to send custom messages:: Use request to send custom messages::
>>> r = s.connection.request(mitel_ommclient2.messages.Ping()) >>> r = s.request(mitel_ommclient2.messages.Ping())
""" """
def __init__(self, host, username, password, port=None, ommsync=False): def __init__(self, host, username, password, port=None, ommsync=False):
@ -39,13 +39,28 @@ class OMMClient2:
kwargs["port"] = self._port kwargs["port"] = self._port
# Connect # Connect
self.connection = Connection(self._host, **kwargs) self._connection = Connection(self._host, **kwargs)
self.connection.connect() self._connection.connect()
# Login # Login
r = self.connection.request(messages.Open(self._username, self._password, UserDeviceSyncClient=self._ommsync)) r = self.request(messages.Open(self._username, self._password, UserDeviceSyncClient=self._ommsync))
r.raise_on_error() r.raise_on_error()
def request(self, request):
"""
Sends a request, waits for response and returns response
:param request: Request object
Usage::
>>> r = c.request(mitel_ommclient2.messages.Ping())
>>> r.name
'PingResp'
"""
return self._connection.request(request)
def get_account(self, id): def get_account(self, id):
""" """
Get account Get account
@ -53,7 +68,7 @@ class OMMClient2:
:param id: User id :param id: User id
""" """
r = self.connection.request(messages.GetAccount(id)) r = self.request(messages.GetAccount(id))
r.raise_on_error() r.raise_on_error()
if r.account is None: if r.account is None:
return None return None
@ -65,7 +80,7 @@ class OMMClient2:
:param id: Device id :param id: Device id
""" """
r = self.connection.request(messages.GetPPDev(ppn)) r = self.request(messages.GetPPDev(ppn))
r.raise_on_error() r.raise_on_error()
if r.pp is None: if r.pp is None:
return None return None
@ -78,7 +93,7 @@ class OMMClient2:
Returns `True` when response is received. Returns `True` when response is received.
""" """
r = self.connection.request(messages.Ping()) r = self.request(messages.Ping())
if r.errCode is None: if r.errCode is None:
return True return True
return False return False

View File

@ -32,6 +32,25 @@ class Request:
def seq(self, seq): def seq(self, seq):
self.attrs["seq"] = seq self.attrs["seq"] = seq
class DictRequest(Request):
"""
Create a message by dict attributes
:param name: Name of the message
:param attrs: Message attributes
:param childs: Message children
Usage::
>>> req = DictRequest("Ping", {"timeStamp": 2342})
"""
def __init__(self, name, attrs={}, childs={}):
self.name = name
self.attrs = attrs
self.childs = childs
class Response: class Response:
""" """
Response message class Response message class