Commit 7220df76 authored by Lionel Walter's avatar Lionel Walter
Browse files

Write to Drupal API, first step

parent a43c53e8
......@@ -8,6 +8,7 @@ from import_api_app.resources.JobStop import JobStop
from import_api_app.resources.Job import Job
# from import_api_app.resources.ReadJobOptionsFromDrupal import ReadJobOptionsFromDrupal
import import_api_app.configuration
from import_api_app.resources.WriteJobResultsToDrupal import WriteJobResultToDrupal
import os
......@@ -56,6 +57,7 @@ def create_app(test_config=None):
)
api.add_resource(JobStop, '/v1/job/<process_id>/<job_name>/stop')
api.add_resource(Job, '/v1/job/<process_id>/<job_name>')
api.add_resource(WriteJobResultToDrupal, '/v1/drupal/<job_drupal_uuid>/<report>')
# api.add_resource(ReadJobOptionsFromDrupal, '/v1/fromDrupal/<job_drupal_uuid>')
# TODO : maybe take that to a configuration (development vs pod running in
......
from flask_restful import Resource, current_app
import requests
import json
class WriteJobResultToDrupal(Resource):
def post(self, job_drupal_uuid, report):
"""
Write the job summary to Drupal job log
---
tags:
- Drupal
parameters:
- in: path
name: job_drupal_uuid
required: true
description: job log uuid
default: 2b07341f-3b99-408c-a729-6e18dd77c6d5
type: string
- in: path
name: report
required: true
description: The report
default: This was a huge success !
type: string
responses:
200:
description: It was successful
500:
description: There was a problem
"""
# url = 'https://mb-wf1.memobase.unibas.ch/jsonapi'
headers = {
'Content-Type': 'application/vnd.api+json',
'Accept': 'application/vnd.api+json',
'X-API-Key': current_app.config['DRUPAL_API_KEY']
}
data = {
"data": {
"id": "2b07341f-3b99-408c-a729-6e18dd77c6d5",
"type": "paragraph--job_log_result",
"attributes": {
"field_summary": report
}
}
}
url = 'https://mb-wf1.memobase.unibas.ch/jsonapi/paragraph/' + \
'job_log_result/2b07341f-3b99-408c-a729-6e18dd77c6d5'
requests.patch(
url,
headers=headers,
data=json.dumps(data)
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment