py-3cx/py3cx.py

100 lines
3.7 KiB
Python

class Py3CX:
class _ApiCallBuilder:
apibase='api'
uri='{}/{}/{}'
# TODO: check login URI component
login={
'uri':'',
'method':'POST',
'expect':200
}
# Returns current username, displayed initial(s), 3CX phone system version, current roles, email addresses and information about privileges and enabled features
CurrentUser={
'uri':'CurrentUser',
'method':'GET',
'expepct':200
}
# Returns a list of current calls, including active trunk where available
ActiveCalls={
'uri':'activeCalls',
'method':'GET',
'expepct':200
}
SystemStatus={
'uri':'SystemStatus',
'method':'GET',
'expepct':200
}
# Returns event log entries; optional ?count=INT argument to retrieve specific number of events
EventLog={
'uri':'{}/getEventLog'.format(SystemStatus['uri']),
'method':'GET',
'expect':200
}
# Returns bytes of recording space used and allocated by quota, also returns recording states.
SystemStatusAdditional={
'uri':'{}/AdditionalStatus'.format(SystemStatus['uri']),
'method':'GET',
'expect':200
}
# Returns state of system health (whether firewall, configured trunks and phones meet 3CX support baselines)
SystemStatusHealth={
'uri':'{}/GetSingleStatus'.format(SystemStatus['uri']),
'method':'GET',
'expect':200
}
# TODO: API call 'SystemStatus/getDbInformation'
# TODO: API call 'TrunkList'
# TODO: API call 'InboundRulesList'
# TODO: API call 'OutboundRuleList'
# TODO: API call 'ActivityLog'
# TODO: API call 'ActivityLog/getKeepDays'
# TODO: API call 'ActivityLog/getKeepLogs'
# TODO: API call 'ActivityLog/getLogLevel'
# TODO: API call 'BackupAndRestoreList'
# TODO: API call 'CallLog'
# TODO: API call 'capture/getInterfaces'
# TODO: API call 'CustomParametersList'
# TODO: API call 'ExtensionList'
# TODO: API call 'GroupList'
# TODO: API call 'IpBlackList'
# TODO: API call 'IVRList'
# TODO: API call 'License'
# TODO: API call 'NumberBlackList'
# TODO: API call 'NumberBlackList/new' POST (followed by calls to 'edit/update' and 'edit/save')
# TODO: API call 'NumberBlackList/delete' POST {Ids: ["(number)"]}
# TODO: API call 'PhoneList'
# TODO: API call 'QueueList'
# TODO: API call 'RecordingList'
# TODO: API call 'RingGroupList'
# TODO: API call 'SystemPromptList'
# TODO: API call 'SystemPromptList/promptSets'
# TODO: API call 'SystemPromptList/promptSetUpdates'
# TODO: API call 'UpdateChecker/GetFromParams'
# TODO: API call 'updateChecker/check' POST
# TODO: API call 'updateChecker/isDebian8'
# TODO: API call 'crm/serverCrmUpdates'
# TODO: API call 'crm/clientCrmUpdates'
# TODO: API call 'CrmList/CrmSettings' POST
def __init__(self, uri=None, account=None):
from os import getenv
if uri==None:
uri=getenv('TCX_URI', None)
if account==None:
account={
"username": getenv('TCX_USERNAME', None),
"password": getenv('TCX_PASSWORD', None)
}
assert (len(account['username']>1)), "py3cx was initialised without account information, and TCX_USERNAME does not contain a valid username."
assert (len(account['password']>5)), "py3cx was initialised without account information, and TCX_PASSWORD does not contain a valid password."
#Validation for initialisation parameters
assert (len(uri)>0), "uri must be a full URI to your target 3CX server"
assert (uri.startswith('http')), "uri must be a valid HTTP or HTTPS URI"
assert ('username' in account), "account object must contain username property"
assert ('password' in account), "account object must contain password property"
assert (len(account['username'])>1), "account object must contain a valid username"
assert (len(account['password'])>5), "account object must contain a valid password"
self._base=uri
self._account=account