示例#1
0
        obj._from_meetmefeatures(obj_dict)
        return obj


class ConfRoomWebService(AbstractWebService):
    _PATH = '/service/ipbx/json.php/restricted/pbx_settings/meetme/'
    _OBJECT_CLASS = ConfRoom

    _ACTIONS = [
        Actions.ADD,
        Actions.DELETE,
        Actions.LIST,
        Actions.SEARCH,
        Actions.VIEW,
    ]

    def search_by_name(self, name):
        name = unicode(name)
        confrooms = self.search(name)
        return [confroom for confroom in confrooms if confroom.name == name]

    def search_by_number(self, number):
        number = unicode(number)
        confrooms = self.search(number)
        return [
            confroom for confroom in confrooms if confroom.number == number
        ]


register_ws_class(ConfRoomWebService, 'confrooms')
示例#2
0
    @classmethod
    def from_list_obj_dict(cls, obj_dict):
        obj = cls()
        obj._from_voicemail(obj_dict)
        return obj


class VoicemailWebService(AbstractWebService):
    _PATH = '/service/ipbx/json.php/restricted/pbx_settings/voicemail/'
    _OBJECT_CLASS = Voicemail

    _ACTIONS = [
        Actions.ADD,
        Actions.DELETE,
        Actions.LIST,
        Actions.SEARCH,
        Actions.VIEW,
    ]

    def search_by_number(self, number):
        number = unicode(number)
        voicemails = self.search(number)
        return [
            voicemail for voicemail in voicemails
            if voicemail.mailbox == number
        ]


register_ws_class(VoicemailWebService, 'voicemails')
示例#3
0
    def from_list_obj_dict(cls, obj_dict):
        obj = cls()
        obj.id = int(obj_dict['id'])
        obj.name = obj_dict['name']
        obj.interface = obj_dict['interface']
        return obj


class CustomTrunkWebService(AbstractWebService):
    _PATH = '/service/ipbx/json.php/restricted/trunk_management/custom/'
    _OBJECT_CLASS = CustomTrunk

    _ACTIONS = [
        Actions.ADD,
        Actions.DELETE,
        Actions.LIST,
        Actions.SEARCH,
        Actions.VIEW,
    ]

    def search_by_name(self, name):
        name = unicode(name)
        custom_trunks = self.search(name)
        return [
            custom_trunk for custom_trunk in custom_trunks
            if custom_trunk.name == name
        ]


register_ws_class(CustomTrunkWebService, 'custom_trunks')
示例#4
0
    _ATTRIBUTES = [
        Attribute('exten', required=True),
        Attribute('stripnum', default=0, required=True),
        Attribute('caller_id', default='', required=True),
    ]

    def _to_obj_dict(self, obj_dict):
        obj_dict.update({
            'id': '0',
            'externprefix': '',
            'prefix': '',
            'exten': self.exten,
            'stripnum': self.stripnum,
            'callerid': self.caller_id,
        })


class OutcallWebService(AbstractWebService):
    _PATH = '/service/ipbx/json.php/restricted/call_management/outcall/'
    _OBJECT_CLASS = Outcall

    _ACTIONS = [
        Actions.ADD,
        Actions.DELETE,
        Actions.LIST,
        Actions.SEARCH,
    ]


register_ws_class(OutcallWebService, 'outcalls')
示例#5
0
    def _to_trunkfeatures(self, obj_dict):
        obj_dict['trunkfeatures'] = {}

    @classmethod
    def from_list_obj_dict(cls, obj_dict):
        obj = cls()
        obj.id = int(obj_dict['id'])
        obj.name = obj_dict['name']
        return obj


class SIPTrunkWebService(AbstractWebService):
    _PATH = '/service/ipbx/json.php/restricted/trunk_management/sip/'
    _OBJECT_CLASS = SIPTrunk

    _ACTIONS = [
        Actions.ADD,
        Actions.EDIT,
        Actions.DELETE,
        Actions.LIST,
        Actions.SEARCH,
    ]

    def search_by_name(self, name):
        name = unicode(name)
        sip_trunks = self.search(name)
        return [sip_trunk for sip_trunk in sip_trunks if sip_trunk.name == name]


register_ws_class(SIPTrunkWebService, 'sip_trunks')
示例#6
0
    _PATH = '/callcenter/json.php/restricted/settings/agents/'
    _OBJECT_CLASS = Agent

    _ACTIONS = [
        Actions.ADD,
        Actions.EDIT,
        Actions.DELETE,
        Actions.DELETE_ALL,
        Actions.LIST,
        Actions.SEARCH,
        Actions.VIEW,
    ]

    def search_by_number(self, number):
        number = unicode(number)
        agents = self.search(number)
        return [agent for agent in agents if agent.number == number]

    def find_one_by_number(self, number):
        agents = self.search_by_number(number)
        nb_agents = len(agents)
        if nb_agents == 1:
            return agents[0]
        elif nb_agents == 0:
            raise Exception('no agent with number %s' % number)
        else:
            raise Exception('%d agents with number %s' % (nb_agents, number))


register_ws_class(AgentWebService, 'agents')
示例#7
0
from __future__ import unicode_literals

from xivo_ws.objects.common import Attribute, AbstractObject, Actions, AbstractWebService
from xivo_ws.registry import register_ws_class


class CTIProfile(AbstractObject):
    _ATTRIBUTES = [
        Attribute('id'),
        Attribute('name'),
    ]

    @classmethod
    def from_list_obj_dict(cls, obj_dict):
        obj = cls()
        obj.id = int(obj_dict['id'])
        obj.name = obj_dict['name']
        return obj


class CTIProfileWebService(AbstractWebService):
    _PATH = '/cti/json.php/restricted/profiles'
    _OBJECT_CLASS = CTIProfile

    _ACTIONS = [
        Actions.LIST,
    ]


register_ws_class(CTIProfileWebService, 'cti_profiles')
示例#8
0
    def _to_obj_dict(self, obj_dict):
        obj_dict['directmedia'] = int(self.directmedia)
        obj_dict['dialtimeout'] = int(self.dialtimeout)
        obj_dict['language'] = unicode(self.language)

    @classmethod
    def from_obj_dict(cls, obj_dict):
        obj = cls()
        obj._from_sccpgeneralsettings(obj_dict['sccpgeneralsettings'])
        return obj

    def _from_sccpgeneralsettings(self, sccpgeneralsettings):
        self.directmedia = convert_directmedia(
            sccpgeneralsettings['directmedia'])
        self.dialtimeout = int(sccpgeneralsettings['dialtimeout'])
        self.language = unicode(sccpgeneralsettings['language'])


class SCCPGeneralSettingsWebService(AbstractWebService):
    _PATH = '/service/ipbx/json.php/restricted/general_settings/sccp/'
    _OBJECT_CLASS = SCCPGeneralSettings

    _ACTIONS = [
        Actions.EDIT,
        Actions.VIEW,
    ]


register_ws_class(SCCPGeneralSettingsWebService, 'sccp_general_settings')
示例#9
0
        obj = cls()
        obj._from_linefeatures(obj_dict)
        obj._from_protocol(obj.protocol, obj_dict)
        return obj


class LineWebService(AbstractWebService):
    _PATH = '/service/ipbx/json.php/restricted/pbx_settings/lines/'
    _OBJECT_CLASS = Line

    _ACTIONS = [
        Actions.LIST,
        Actions.SEARCH,
    ]

    def search_by_number_context(self, number, context):
        def match(line):
            return line.number == number and context == line.context

        number = unicode(number)
        lines = self.search(number)
        return [line for line in lines if match(line)]

    def search_by_name(self, name):
        name = unicode(name)
        lines = self.search(name)
        return [line for line in lines if line.name == name]


register_ws_class(LineWebService, 'lines')
示例#10
0
        obj.cid_dnid = obj_dict['cid_dnid']
        obj.exten = obj_dict['exten']
        obj.context = obj_dict['context']
        obj.channame = obj_dict['channame']
        obj.appname = obj_dict['appname']
        obj.appdata = obj_dict['appdata']
        obj.amaflags = obj_dict['amaflags']
        obj.accountcode = obj_dict['accountcode']
        obj.peeraccount = obj_dict['peeraccount']
        obj.uniqueid = obj_dict['uniqueid']
        obj.linkedid = obj_dict['linkedid']
        obj.userfield = obj_dict['userfield']
        obj.peer = obj_dict['peer']
        return obj


class CELWebService(AbstractWebService):
    _PATH = '/service/ipbx/json.php/restricted/call_management/cel/'
    _OBJECT_CLASS = CEL

    _ACTIONS = [
    ]

    def search_by_id(self, id_beg):
        query_string = 'act=searchid&idbeg=%s' % id_beg
        response = self._ws_client.custom_request(self._PATH, query_string)
        return [CEL.from_list_obj_dict(cel) for cel in json.loads(response)]


register_ws_class(CELWebService, 'cels')
示例#11
0

class GroupWebService(AbstractWebService):
    _PATH = '/service/ipbx/json.php/restricted/pbx_settings/groups/'
    _OBJECT_CLASS = Group

    _ACTIONS = [
        Actions.ADD,
        Actions.EDIT,
        Actions.DELETE,
        Actions.DELETE_ALL,
        Actions.LIST,
        Actions.SEARCH,
        Actions.VIEW,
    ]

    def search_by_number(self, number):
        number = unicode(number)
        groups = self.search(number)
        return [group for group in groups if group.number == number]

    def search_by_name(self, name):
        name = unicode(name)
        groups = self.search(name)
        return [group for group in groups if group.name == name]


register_ws_class(GroupWebService, 'groups')
# deprecated name
register_ws_class(GroupWebService, 'group')
示例#12
0
        obj_dict['trunkfeatures'] = trunkfeatures

    @classmethod
    def from_list_obj_dict(cls, obj_dict):
        obj = cls()
        obj.id = int(obj_dict['id'])
        obj.name = obj_dict['name']
        return obj


class IAXTrunkWebService(AbstractWebService):
    _PATH = '/service/ipbx/json.php/restricted/trunk_management/iax/'
    _OBJECT_CLASS = IAXTrunk

    _ACTIONS = [
        Actions.ADD,
        Actions.DELETE,
        Actions.LIST,
        Actions.SEARCH,
    ]

    def search_by_name(self, name):
        name = unicode(name)
        iax_trunks = self.search(name)
        return [
            iax_trunk for iax_trunk in iax_trunks if iax_trunk.name == name
        ]


register_ws_class(IAXTrunkWebService, 'iax_trunks')
示例#13
0
        obj = cls()
        obj._from_device(obj_dict)
        return obj

    def _from_device(self, device):
        self.id = device.get('id')
        self.ip = device.get('ip')
        self.mac = device.get('mac')
        self.plugin = device.get('plugin')
        self.vendor = device.get('vendor')
        self.model = device.get('model')
        self.version = device.get('version')
        self.status = device.get('status')
        self.template_id = device.get('template_id')

    from_list_obj_dict = from_obj_dict


class DeviceWebService(AbstractWebService):
    _PATH = '/service/ipbx/json.php/restricted/pbx_settings/devices/'
    _OBJECT_CLASS = Device

    _ACTIONS = [
        Actions.LIST,
        Actions.SEARCH,
        Actions.VIEW,
    ]


register_ws_class(DeviceWebService, 'devices')
示例#14
0
    def from_obj_dict(cls, obj_dict):
        obj = cls()
        obj.id = int(obj_dict['id'])
        obj.name = obj_dict['name']
        obj.display_name = obj_dict['displayname']
        return obj

    from_list_obj_dict = from_obj_dict


class EntityWebService(AbstractWebService):
    _PATH = '/xivo/configuration/json.php/restricted/manage/entity/'
    _OBJECT_CLASS = Entity

    _ACTIONS = [
        Actions.ADD,
        Actions.EDIT,
        Actions.DELETE,
        Actions.LIST,
        Actions.SEARCH,
        Actions.VIEW,
    ]

    def search_by_name(self, name):
        name = unicode(name)
        entities = self.search(name)
        return [entity for entity in entities if entity.name == name]


register_ws_class(EntityWebService, 'entities')
示例#15
0
            obj_dict['numberend'] = self.end
        if include_didlength:
            obj_dict['didlength'] = self.did_length
        return obj_dict

    @classmethod
    def from_obj_dict(cls, obj_dict):
        obj = cls()
        obj.start = int(obj_dict['numberbeg'])
        if obj_dict['numberend']:
            obj.end = int(obj_dict['numberend'])
        obj.did_length = int(obj_dict['didlength'])
        return obj


class ContextWebService(AbstractWebService):
    _PATH = '/service/ipbx/json.php/restricted/system_management/context/'
    _OBJECT_CLASS = Context

    _ACTIONS = [
        Actions.ADD,
        Actions.EDIT,
        Actions.DELETE,
        Actions.LIST,
        Actions.SEARCH,
        Actions.VIEW,
    ]


register_ws_class(ContextWebService, 'contexts')
示例#16
0
        obj.period1 = obj_dict['period1']
        obj.period2 = obj_dict['period2']
        obj.period3 = obj_dict['period3']
        obj.period4 = obj_dict['period4']
        obj.period5 = obj_dict['period5']
        obj.monday = obj_dict['monday']
        obj.tuesday = obj_dict['tuesday']
        obj.wednesday = obj_dict['wednesday']
        obj.thursday = obj_dict['thursday']
        obj.friday = obj_dict['friday']
        obj.saturday = obj_dict['saturday']
        obj.sunday = obj_dict['sunday']
        return obj


class StatconfWebService(AbstractWebService):
    _PATH = '/statistics/call_center/json.php/restricted/settings/configuration/'
    _OBJECT_CLASS = Statconf

    _ACTIONS = [
        Actions.ADD,
        Actions.EDIT,
        Actions.DELETE,
        Actions.LIST,
        Actions.SEARCH,
        Actions.VIEW,
    ]


register_ws_class(StatconfWebService, 'statconfs')
示例#17
0
        Attribute('password'),
    ]

    def _add_voicemail(self, obj_dict):
        self._check_required_attributes()
        voicemail_dict = {
            'name': self.name,
            'number': self.number,
            'context': self.context
        }
        if self.password is not None:
            voicemail_dict['password'] = self.password
        obj_dict['voicemail'] = voicemail_dict


class UserWebService(AbstractWebService):
    _PATH = '/service/ipbx/json.php/restricted/pbx_settings/users/'
    _OBJECT_CLASS = User

    _ACTIONS = [
        Actions.ADD,
        Actions.EDIT,
        Actions.DELETE,
        Actions.DELETE_ALL,
        Actions.LIST,
        Actions.SEARCH,
    ]


register_ws_class(UserWebService, 'users')
示例#18
0
class ScheduleWebService(AbstractWebService):
    _PATH = '/service/ipbx/json.php/restricted/call_management/schedule/'
    _OBJECT_CLASS = Schedule

    _ACTIONS = [
        Actions.ADD,
        Actions.DELETE,
        Actions.LIST,
        Actions.VIEW,
    ]


def _same_hours(lefts, rights):
    if not lefts and not rights:
        return True

    if len(lefts) != len(rights):
        return False

    fields = ['hours', 'months', 'monthdays', 'weekdays']
    for i in xrange(len(lefts)):
        left, right = lefts[i], rights[i]
        for field in fields:
            if left[field] != right[field]:
                return False
    return True


register_ws_class(ScheduleWebService, 'schedules')
示例#19
0
    @classmethod
    def from_list_obj_dict(cls, obj_dict):
        obj = cls()
        obj.id = int(obj_dict['id'])
        obj.number = obj_dict['exten']
        obj.context = obj_dict['context']
        return obj


class IncallWebService(AbstractWebService):
    _PATH = '/service/ipbx/json.php/restricted/call_management/incall/'
    _OBJECT_CLASS = Incall

    _ACTIONS = [
        Actions.ADD,
        Actions.EDIT,
        Actions.DELETE,
        Actions.DELETE_ALL,
        Actions.LIST,
        Actions.SEARCH,
    ]

    def search_by_number(self, number):
        number = unicode(number)
        incalls = self.search(number)
        return [incall for incall in incalls if incall.number == number]


register_ws_class(IncallWebService, 'incalls')