2016-08-28 19:20:14 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
from typing import Any, Dict, Text
|
|
|
|
|
2017-05-25 19:16:40 +02:00
|
|
|
from zerver.outgoing_webhooks.generic import GenericOutgoingWebhookService
|
2017-05-26 16:37:45 +02:00
|
|
|
from zerver.models import GENERIC_INTERFACE, Service
|
2017-05-25 19:16:40 +02:00
|
|
|
|
|
|
|
AVAILABLE_OUTGOING_WEBHOOK_INTERFACES = {
|
|
|
|
GENERIC_INTERFACE: GenericOutgoingWebhookService
|
|
|
|
} # type: Dict[Text, Any]
|
2016-08-28 19:20:14 +02:00
|
|
|
|
|
|
|
def get_service_interface_class(interface):
|
|
|
|
# type: (Text) -> Any
|
2017-05-25 19:16:40 +02:00
|
|
|
if interface is None or interface not in AVAILABLE_OUTGOING_WEBHOOK_INTERFACES:
|
|
|
|
return AVAILABLE_OUTGOING_WEBHOOK_INTERFACES[GENERIC_INTERFACE]
|
|
|
|
else:
|
|
|
|
return AVAILABLE_OUTGOING_WEBHOOK_INTERFACES[interface]
|
2017-05-26 16:37:45 +02:00
|
|
|
|
|
|
|
def get_outgoing_webhook_service_handler(service):
|
|
|
|
# type: (Service) -> Any
|
|
|
|
|
|
|
|
service_interface_class = get_service_interface_class(service.interface_name())
|
|
|
|
service_interface = service_interface_class(base_url=service.base_url,
|
|
|
|
token=service.token,
|
|
|
|
user_profile=service.user_profile,
|
|
|
|
service_name=service.name)
|
|
|
|
return service_interface
|