def service_handle_new_editable(editable): revision = editable.revisions[-1] data = { 'files': EditingRevisionFileSchema().dump(revision.files, many=True), 'endpoints': { 'revisions': { 'replace': url_for('.api_replace_revision', revision, _external=True) }, 'file_upload': url_for('.api_upload', editable, _external=True) } } try: path = '/event/{}/editable/{}/{}'.format( _get_event_identifier(editable.event), editable.type.name, editable.contribution_id, ) resp = requests.put(_build_url(editable.event, path), headers=_get_headers(editable.event), json=data) resp.raise_for_status() except requests.RequestException as exc: logger.exception('Failed calling listener for editable') raise ServiceRequestFailed(exc)
def service_handle_disconnected(event): try: resp = requests.delete(_build_url( event, '/event/{}'.format(_get_event_identifier(event))), headers=_get_headers(event)) resp.raise_for_status() except requests.RequestException as exc: logger.exception('Disconnecting event from service failed') raise ServiceRequestFailed(exc)
def _log_service_error(exc, msg): payload = None if exc.response is not None: try: payload = exc.response.json() except ValueError: pass if payload is not None: logger.exception('{}: %s'.format(msg), payload) else: logger.exception(msg)
def service_handle_enabled(event): data = { 'title': event.title, 'url': event.external_url, 'token': editing_settings.get(event, 'service_token'), } try: resp = requests.put(_build_url( event, '/event/{}'.format(_make_event_identifier(event))), headers=_get_headers(event, include_token=False), data=data) resp.raise_for_status() except requests.RequestException as exc: logger.exception('Registering event with service failed') raise ServiceRequestFailed(exc)
def service_handle_enabled(event): data = { 'title': event.title, 'url': event.external_url, 'token': editing_settings.get(event, 'service_token'), 'endpoints': { 'tags': { 'create': url_for('.api_create_tag', event, _external=True), 'list': url_for('.api_tags', event, _external=True) }, 'editable_types': url_for('.api_enabled_editable_types', event, _external=True), 'file_types': { t.name: { 'create': url_for('.api_add_file_type', event, type=t.name, _external=True), 'list': url_for('.api_file_types', event, type=t.name, _external=True), } for t in EditableType } } } try: resp = requests.put(_build_url( event, '/event/{}'.format(_get_event_identifier(event))), headers=_get_headers(event, include_token=False), json=data) resp.raise_for_status() except requests.RequestException as exc: logger.exception('Registering event with service failed') raise ServiceRequestFailed(exc)