示例#1
0
def load(core_rest_api):
    blueprint = Blueprint("voicemails", __name__, url_prefix="/%s/voicemails" % config.API_VERSION)
    document = core_rest_api.content_parser.document(
        Field("id", Int()),
        Field("name", Unicode()),
        Field("number", Unicode(), Regexp.compile(r"\d+", "wrong type. Should be a numeric string")),
        Field("context", Unicode()),
        Field("password", Unicode(), Regexp.compile(r"\d+", "wrong type. Should be a numeric string")),
        Field("email", Unicode()),
        Field("language", Unicode()),
        Field("timezone", Unicode()),
        Field("pager", Unicode()),
        Field("max_messages", Int()),
        Field("attach_audio", Boolean()),
        Field("delete_messages", Boolean()),
        Field("ask_password", Boolean()),
        Field("enabled", Boolean()),
        Field("options", OptionType()),
    )

    converter = Converter.resource(document, Voicemail)
    sysconfd_client = new_client()
    validator = build_validators()

    service = VoicemailService(dao, validator, notifier, sysconfd_client)
    resource = CRUDResource(service, converter)

    DecoratorChain.register_scrud(core_rest_api, blueprint, resource)
示例#2
0
def load(core_rest_api):
    blueprint = Blueprint('lines', __name__, url_prefix='/%s/lines' % config.API_VERSION)

    document = core_rest_api.content_parser.document(
        Field('id', Int()),
        Field('context', Unicode()),
        Field('name', Unicode()),
        Field('protocol', Unicode()),
        Field('provisioning_extension', Unicode()),
        Field('device_slot', Int()),
        Field('device_id', Unicode()),
    )
    converter = Converter.resource(document, Line)

    line_services.setup_provd_client(core_rest_api.provd_client())

    actions_sip.load(core_rest_api)

    service = LineServiceProxy(line_services)
    resource = CRUDResource(service, converter)

    chain = DecoratorChain(core_rest_api, blueprint)
    chain.search().decorate(resource.search)
    chain.get().decorate(resource.get)

    core_rest_api.register(blueprint)
示例#3
0
def load(core_rest_api):
    blueprint = Blueprint('infos', __name__, url_prefix='/%s/infos' % config.API_VERSION)
    document = core_rest_api.content_parser.document(Field('uuid', Unicode()))

    converter = Converter.resource(document, Infos, 'infos', 'uuid')
    resource = InfoResource(dao, converter)

    chain = DecoratorChain(core_rest_api, blueprint)
    chain.get('').decorate(resource.get)

    core_rest_api.register(blueprint)
示例#4
0
def load(core_rest_api):
    blueprint = Blueprint('infos', __name__, url_prefix='/%s/infos' % config.API_VERSION)
    document = core_rest_api.content_parser.document(Field('uuid', Unicode()))

    converter = Converter.resource(document, Infos, 'infos', 'uuid')
    resource = InfoResource(dao, converter)

    chain = DecoratorChain(core_rest_api, blueprint)
    chain.get('').decorate(resource.get)

    core_rest_api.register(blueprint)
示例#5
0
def load(core_rest_api):
    blueprint = Blueprint('configuration',
                          __name__,
                          url_prefix='/%s/configuration' % config.API_VERSION)
    document = core_rest_api.content_parser.document(Field('enabled', Boolean()))
    converter = Converter.association(document, LiveReload)

    service = LiveReloadService(dao, validator, notifier)
    resource = LiveReloadResource(service, converter)

    chain = DecoratorChain(core_rest_api, blueprint)
    chain.get('/live_reload').decorate(resource.get)
    chain.edit('/live_reload').decorate(resource.edit)

    core_rest_api.register(blueprint)
示例#6
0
def load(core_rest_api):
    blueprint = Blueprint('cti_profiles', __name__, url_prefix='/%s/cti_profiles' % config.API_VERSION)
    document = core_rest_api.content_parser.document(
        Field('id', Int()),
        Field('name', Unicode())
    )
    converter = Converter.resource(document, CtiProfile, 'cti_profiles')

    service = CtiProfileService(dao)
    resource = CRUDResource(service, converter)

    chain = DecoratorChain(core_rest_api, blueprint)
    chain.search().decorate(resource.search)
    chain.get().decorate(resource.get)

    core_rest_api.register(blueprint)
示例#7
0
def load(core_rest_api):
    blueprint = Blueprint('lines_sip', __name__, url_prefix='/%s/lines_sip' % config.API_VERSION)
    document = core_rest_api.content_parser.document(
        Field('id', Int()),
        Field('context', Unicode()),
        Field('username', Unicode()),
        Field('secret', Unicode()),
        Field('provisioning_extension', Unicode()),
        Field('device_slot', Int()),
        Field('callerid', Unicode()),
    )
    converter = Converter.resource(document, LineSIP, 'lines_sip')

    service = LineSIPServiceProxy(line_services)
    resource = CRUDResource(service, converter)

    DecoratorChain.register_scrud(core_rest_api, blueprint, resource)
示例#8
0
def load(core_rest_api):
    blueprint = Blueprint('extensions',
                          __name__,
                          url_prefix='/%s/extensions' % config.API_VERSION)

    document = core_rest_api.content_parser.document(
        Field('id', Int()),
        Field('exten', Unicode()),
        Field('context', Unicode()),
        Field('commented', Boolean())
    )
    converter = Converter.resource(document, Extension)

    service = ExtensionService(dao, line_extension_dao, line_dao, validator, notifier)
    resource = CRUDResource(service, converter, ['type'])

    DecoratorChain.register_scrud(core_rest_api, blueprint, resource)
示例#9
0
def load(core_rest_api):
    blueprint = Blueprint('voicemails',
                          __name__,
                          url_prefix='/%s/voicemails' % config.API_VERSION)
    document = core_rest_api.content_parser.document(
        Field('id', Int()), Field('name', Unicode()),
        Field('number', Unicode()), Field('context', Unicode()),
        Field('password', Unicode()), Field('email', Unicode()),
        Field('language', Unicode()), Field('timezone', Unicode()),
        Field('pager', Unicode()), Field('max_messages', Int()),
        Field('attach_audio', Boolean()), Field('delete_messages', Boolean()),
        Field('ask_password', Boolean()), Field('enabled', Boolean()),
        Field('options', OptionType()))

    converter = Converter.resource(document, Voicemail)

    service = build_service()
    resource = VoicemailResource(service, converter)

    DecoratorChain.register_scrud(core_rest_api, blueprint, resource)
示例#10
0
def load(core_rest_api):
    blueprint = Blueprint('queues',
                          __name__,
                          url_prefix='/%s/queues' % config.API_VERSION)
    document = core_rest_api.content_parser.document(Field('queue_id', Int()),
                                                     Field('agent_id', Int()),
                                                     Field('penalty', Int()))
    converter = Converter.association(document,
                                      QueueMemberAgent,
                                      rename={
                                          'parent_id': 'queue_id',
                                          'resource_id': 'agent_id'
                                      })

    service = QueueMemberService(dao, validator, notifier)
    resource = QueueMemberAssociationResource(service, converter)

    chain = DecoratorChain(core_rest_api, blueprint)

    (chain.get('/<int:parent_id>/members/agents/<int:resource_id>').decorate(
        resource.get_association))

    (chain.edit('/<int:parent_id>/members/agents/<int:resource_id>').decorate(
        resource.edit_association))

    (chain.create('/<int:parent_id>/members/agents').decorate(
        resource.associate_collection))

    (chain.delete(
        '/<int:parent_id>/members/agents/<int:resource_id>').decorate(
            resource.dissociate_collection))

    core_rest_api.register(blueprint)
示例#11
0
def load(core_rest_api):
    blueprint = Blueprint('configuration',
                          __name__,
                          url_prefix='/%s/configuration' % config.API_VERSION)
    document = core_rest_api.content_parser.document(Field('enabled', Boolean()))
    converter = Converter.association(document, LiveReload)

    service = LiveReloadService(dao, validator, notifier)
    resource = LiveReloadResource(service, converter)

    chain = DecoratorChain(core_rest_api, blueprint)
    chain.get('/live_reload').decorate(resource.get)
    chain.edit('/live_reload').decorate(resource.edit)

    core_rest_api.register(blueprint)
示例#12
0
def load(core_rest_api):
    blueprint = Blueprint('cti_profiles',
                          __name__,
                          url_prefix='/%s/cti_profiles' % config.API_VERSION)
    document = core_rest_api.content_parser.document(Field('id', Int()),
                                                     Field('name', Unicode()))
    converter = Converter.resource(document, CtiProfile, 'cti_profiles')

    service = CtiProfileService(dao)
    resource = CtiProfileResource(service, converter)

    chain = DecoratorChain(core_rest_api, blueprint)
    chain.search().decorate(resource.search)
    chain.get().decorate(resource.get)

    core_rest_api.register(blueprint)
示例#13
0
def load(core_rest_api):
    blueprint = Blueprint('users', __name__, url_prefix='/%s/users' % config.API_VERSION)

    user_document = core_rest_api.content_parser.document(
        Field('id', Int()),
        Field('uuid', Unicode()),
        Field('firstname', Unicode()),
        Field('lastname', Unicode()),
        Field('caller_id', Unicode()),
        Field('outgoing_caller_id', Unicode()),
        Field('username', Unicode()),
        Field('password', Unicode()),
        Field('music_on_hold', Unicode()),
        Field('mobile_phone_number', Unicode()),
        Field('userfield', Unicode()),
        Field('timezone', Unicode()),
        Field('language', Unicode()),
        Field('description', Unicode()),
        Field('preprocess_subroutine', Unicode())
    )

    directory_document = core_rest_api.content_parser.document(
        Field('id', Int()),
        Field('line_id', Int()),
        Field('agent_id', Int()),
        Field('firstname', Unicode()),
        Field('lastname', Unicode()),
        Field('exten', Unicode()),
        Field('mobile_phone_number', Unicode()),
        Field('userfield', Unicode()),
        Field('description', Unicode()),
    )

    user_converter = Converter.resource(user_document, User)
    directory_converter = Converter(parser=DocumentParser(directory_document),
                                    mapper=DocumentMapper(directory_document, UserDirectory),
                                    serializer=DirectorySerializer(),
                                    builder=ModelBuilder(directory_document, UserDirectory))

    resource = UserResource(user_services, user_converter, directory_converter)

    chain = DecoratorChain(core_rest_api, blueprint)
    chain.search().decorate(resource.search)
    chain.get().decorate(resource.get)
    chain.get('/<uuid:resource_uuid>').decorate(resource.get_by_uuid)
    chain.create().decorate(resource.create)
    chain.edit().decorate(resource.edit)
    chain.edit('/<uuid:resource_uuid>').decorate(resource.edit_by_uuid)
    chain.delete().decorate(resource.delete)
    chain.delete('/<uuid:resource_uuid>').decorate(resource.delete_by_uuid)

    core_rest_api.register(blueprint)
示例#14
0
def load(core_rest_api):
    document = core_rest_api.content_parser.document(
        Field('id', Unicode()),
        Field('ip', Unicode()),
        Field('mac', Unicode()),
        Field('sn', Unicode()),
        Field('plugin', Unicode()),
        Field('vendor', Unicode()),
        Field('model', Unicode()),
        Field('version', Unicode()),
        Field('description', Unicode()),
        Field('status', Unicode()),
        Field('template_id', Unicode()),
        Field('options', Dict())
    )

    blueprint = Blueprint('devices', __name__, url_prefix='/%s/devices' % config.API_VERSION)

    converter = Converter.resource(document, Device)

    provd_client = core_rest_api.provd_client()

    device_dao = builder.build_dao(provd_client)
    device_service = builder.build_service(device_dao)
    device_updater = builder.build_device_updater(device_dao)
    association_service = builder.build_line_device_associator(device_updater)

    resource = DeviceResource(device_service, association_service, converter)

    chain = DecoratorChain(core_rest_api, blueprint)
    chain.search().decorate(resource.search)
    chain.get('/<resource_id>').decorate(resource.get)
    chain.create().decorate(resource.create)
    chain.edit('/<resource_id>').decorate(resource.edit)
    chain.delete('/<resource_id>').decorate(resource.delete)

    (chain
     .get('/<device_id>/synchronize')
     .decorate(resource.synchronize))

    (chain
     .get('/<device_id>/autoprov')
     .decorate(resource.autoprov))

    (chain
     .limit_localhost()
     .get('/<device_id>/associate_line/<int:line_id>')
     .decorate(resource.associate_line))

    (chain
     .limit_localhost()
     .get('/<device_id>/remove_line/<int:line_id>')
     .decorate(resource.remove_line))

    core_rest_api.register(blueprint)
示例#15
0
def load(core_rest_api):
    validator = fk_validator.build_validators()
    bsfilter_validator = fk_validator.BSFilterValidator(bsfilter_dao)

    funckey_converter = fk_converter.build_funckey_converter(exclude=['agent', 'bsfilter'])
    user_funckey_converter = fk_converter.build_funckey_converter()

    template_converter = fk_converter.build_template_converter(funckey_converter)
    user_template_converter = fk_converter.build_template_converter(user_funckey_converter)

    association_converter = fk_converter.build_association_converter(core_rest_api.content_parser)

    provd_client = core_rest_api.provd_client()
    device_dao = device_builder.build_dao(provd_client)
    device_updater = device_builder.build_device_updater(device_dao)

    service = fk_service.TemplateService(validator,
                                         template_dao,
                                         user_dao,
                                         notifier,
                                         device_updater)

    template_manipulator = TemplateManipulator(service, device_updater, user_dao)

    template_resource = CRUDResource(service, template_converter)
    funckey_resource = FuncKeyResource(template_manipulator, funckey_converter, association_converter)
    user_funckey_resource = UserFuncKeyResource(template_manipulator,
                                                user_funckey_converter,
                                                association_converter,
                                                bsfilter_validator,
                                                user_dao)
    user_template_resource = UserTemplateResource(template_manipulator,
                                                  user_template_converter,
                                                  association_converter)

    blueprint = Blueprint('func_key_templates', __name__, url_prefix='/%s/funckeys/templates' % config.API_VERSION)
    fk_blueprint = Blueprint('func_keys', __name__, url_prefix='/%s/funckeys' % config.API_VERSION)
    user_blueprint = core_rest_api.blueprint('users')

    chain = DecoratorChain(core_rest_api, blueprint)
    fk_chain = DecoratorChain(core_rest_api, fk_blueprint)

    # /funckeys
    fk_chain.get("/destinations").decorate(funckey_resource.get_destinations)

    # /funckeys/templates
    chain.search().decorate(template_resource.search)
    chain.get().decorate(template_resource.get)
    chain.create().decorate(template_resource.create)
    chain.delete().decorate(template_resource.delete)

    # /funckeys/templates/:id/:position
    chain.edit("/<int:template_id>/<int:position>").decorate(funckey_resource.update_funckey)
    chain.delete("/<int:template_id>/<int:position>").decorate(funckey_resource.remove_funckey)
    chain.get("/<int:template_id>/<int:position>").decorate(funckey_resource.get_funckey)
    chain.get("/<int:template_id>/users").decorate(funckey_resource.get_associations)

    user_chain = DecoratorChain(core_rest_api, user_blueprint)

    # /users/:id/funckeys
    user_chain.get("/<int:user_id>/funckeys/<int:position>").decorate(user_funckey_resource.get_funckey)
    user_chain.edit("/<int:user_id>/funckeys/<int:position>").decorate(user_funckey_resource.update_funckey)
    user_chain.delete("/<int:user_id>/funckeys/<int:position>").decorate(user_funckey_resource.remove_funckey)

    # /users/:id/funckeys/templates
    user_chain.get("/<int:user_id>/funckeys").decorate(user_template_resource.get_unified_template)
    user_chain.edit("/<int:user_id>/funckeys/templates/<int:template_id>").decorate(user_template_resource.associate_template)
    user_chain.delete("/<int:user_id>/funckeys/templates/<int:template_id>").decorate(user_template_resource.dissociate_template)
    user_chain.get("/<int:user_id>/funckeys/templates").decorate(user_template_resource.get_associations)

    core_rest_api.register(blueprint)
    core_rest_api.register(user_blueprint)
    core_rest_api.register(fk_blueprint)