Warning

This document is for an old release of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.

Source code for galaxy.webapps.galaxy.api.webhooks

"""
API Controller providing Galaxy Webhooks
"""

from galaxy.web import _future_expose_api_anonymous_and_sessionless as \
    expose_api_anonymous_and_sessionless
from galaxy.web.base.controller import BaseAPIController

import logging
import random
import imp

log = logging.getLogger(__name__)


[docs]class WebhooksController(BaseAPIController):
[docs] def __init__(self, app): super(WebhooksController, self).__init__(app)
[docs] @expose_api_anonymous_and_sessionless def get_all(self, trans, **kwd): """ *GET /api/webhooks/ Returns all webhooks """ return [ webhook.to_dict() for webhook in self.app.webhooks_registry.webhooks ]
[docs] @expose_api_anonymous_and_sessionless def get_random(self, trans, webhook_type, **kwd): """ *GET /api/webhooks/{webhook_type} Returns a random webhook for a given type """ webhooks = [ webhook for webhook in self.app.webhooks_registry.webhooks if webhook_type in webhook.type and webhook.activate is True ] return random.choice(webhooks).to_dict() if webhooks else {}
[docs] @expose_api_anonymous_and_sessionless def get_all_by_type(self, trans, webhook_type, **kwd): """ *GET /api/webhooks/{webhook_type}/all Returns all webhooks for a given type """ return [ webhook.to_dict() for webhook in self.app.webhooks_registry.webhooks if webhook_type in webhook.type ]
[docs] @expose_api_anonymous_and_sessionless def get_data(self, trans, webhook_name, **kwd): """ *GET /api/webhooks/{webhook_name}/get_data/{params} Returns the result of executing helper function """ params = {} for key, value in kwd.items(): params[key] = value webhook = [ webhook for webhook in self.app.webhooks_registry.webhooks if webhook.name == webhook_name ] return imp.load_source('helper', webhook[0].helper).main( trans, webhook[0], params, ) if webhook and webhook[0].helper != '' else {}