Compare commits
2 Commits
8f4a7b1f6d
...
49a4ecc07f
Author | SHA1 | Date | |
---|---|---|---|
49a4ecc07f | |||
7076eb1543 |
@ -16,10 +16,7 @@ c = mitel_ommclient2.OMMClient2("omm.local", "admin", "admin")
|
||||
c.ping()
|
||||
|
||||
# Create custom messages
|
||||
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}))
|
||||
r = c.connection.request(mitel_ommclient2.messages.Ping(timeStamp=2342))
|
||||
```
|
||||
|
||||
Consult class documentation for more in depth examples and options.
|
||||
|
@ -37,6 +37,7 @@ validate common API requests. See class documentation to get and overview and op
|
||||
Making custom requests
|
||||
----------------------
|
||||
|
||||
:func:`mitel_ommclient2.client.OMMClient2.request` allowes you to send custom requests.
|
||||
It just passes arguments and results to :func:`mitel_ommclient2.connection.Connection.request`.
|
||||
:class:`mitel_ommclient2.client.OMMClient2` holds its :class:`mitel_ommclient2.connection.Connection`
|
||||
in the connection attribute.
|
||||
Use :func:`mitel_ommclient2.connection.Connection.request` directly for making some custom requests.
|
||||
See :doc:`/manual/connection` about using this.
|
||||
|
@ -23,7 +23,7 @@ class OMMClient2:
|
||||
|
||||
Use request to send custom messages::
|
||||
|
||||
>>> r = s.request(mitel_ommclient2.messages.Ping())
|
||||
>>> r = s.connection.request(mitel_ommclient2.messages.Ping())
|
||||
"""
|
||||
|
||||
def __init__(self, host, username, password, port=None, ommsync=False):
|
||||
@ -39,28 +39,13 @@ class OMMClient2:
|
||||
kwargs["port"] = self._port
|
||||
|
||||
# Connect
|
||||
self._connection = Connection(self._host, **kwargs)
|
||||
self._connection.connect()
|
||||
self.connection = Connection(self._host, **kwargs)
|
||||
self.connection.connect()
|
||||
|
||||
# Login
|
||||
r = self.request(messages.Open(self._username, self._password, UserDeviceSyncClient=self._ommsync))
|
||||
r = self.connection.request(messages.Open(self._username, self._password, UserDeviceSyncClient=self._ommsync))
|
||||
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):
|
||||
"""
|
||||
Get account
|
||||
@ -68,7 +53,7 @@ class OMMClient2:
|
||||
:param id: User id
|
||||
"""
|
||||
|
||||
r = self.request(messages.GetAccount(id))
|
||||
r = self.connection.request(messages.GetAccount(id))
|
||||
r.raise_on_error()
|
||||
if r.account is None:
|
||||
return None
|
||||
@ -80,7 +65,7 @@ class OMMClient2:
|
||||
|
||||
:param id: Device id
|
||||
"""
|
||||
r = self.request(messages.GetPPDev(ppn))
|
||||
r = self.connection.request(messages.GetPPDev(ppn))
|
||||
r.raise_on_error()
|
||||
if r.pp is None:
|
||||
return None
|
||||
@ -93,7 +78,7 @@ class OMMClient2:
|
||||
Returns `True` when response is received.
|
||||
"""
|
||||
|
||||
r = self.request(messages.Ping())
|
||||
r = self.connection.request(messages.Ping())
|
||||
if r.errCode is None:
|
||||
return True
|
||||
return False
|
||||
|
@ -32,25 +32,6 @@ class Request:
|
||||
def seq(self, 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:
|
||||
"""
|
||||
Response message class
|
||||
|
Loading…
Reference in New Issue
Block a user