Ejemplo n.º 1
0
def put_hook(key: access_token,
      scope: hug.types.one_of(scope_values),
      callback_uri: hug.types.text):
  """Add an explicit subscription for the task completion

  Params:
    - scope: One of the valid webhook scopes
    - callback_uri: This is the URI the webhook callback will be requested
  """
  try:
    hook = Hook()
    hook.scope = scope
    hook.callback = callback_uri
    hook.save()

    return hook.repr
  except ValidationError:
    raise falcon.HTTPBadRequest(
        title='ValidationError',
        description='The parameters provided are invalid')

  except NotUniqueError:
    raise falcon.HTTPBadRequest(
        title='NotUniqueError',
        description='The given scope - callback combination is taken')