Skip to content

Commit

Permalink
add: turtle content negotiation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholsn committed Aug 25, 2014
1 parent fc6145c commit fcf1f0f
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions niquery/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import

import os
import json

import rdflib
import requests
Expand Down Expand Up @@ -56,16 +57,9 @@ def __call__(self, *args, **kwargs):
@api.representation('text/turtle')
def turtle(data, code, headers=None):
g = rdflib.Graph()
try:
g.parse(data=data, format='json-ld')
except ValueError as e:
return make_response(e, code)
if list(g.subjects()):
resp = make_response(g.serialize(format='turtle'), code)
resp.headers.extend(headers or {})
else:
raise Exception("Data is not a json-ld graph.",
g.serialize(format='json-ld'))
g.parse(data=json.dumps(data), format='json-ld')
resp = make_response(g.serialize(format='turtle'), code)
resp.headers.extend(headers or {})
return resp

celery = make_celery(app)
Expand All @@ -81,7 +75,8 @@ def bet(in_file_uri):

nipype.config.enable_provenance()

fname = '/anatomy.nii.gz'
os.chdir('/tmp')
fname = 'anatomy.nii.gz'

with open(fname, 'wb') as fd:
response = requests.get(in_file_uri, stream=True)
Expand Down Expand Up @@ -143,14 +138,14 @@ def get(self):
class ComputeResult(Resource):
def get(self, task_id):
retval = bet.AsyncResult(task_id).get(timeout=1.0)
return jsonify(retval)
return json.loads(retval)

# Endpoints
api.add_resource(Validate, '/validate')
api.add_resource(ValidateResult, '/validate/<string:task_id>')
api.add_resource(Inference, '/inference')
api.add_resource(InferenceResult, '/inference/<string:task_id>')
api.add_resource(Compute, '/compute')
api.add_resource(Compute, '/compute', '/compute/')
api.add_resource(ComputeResult, '/compute/<string:task_id>')

if __name__ == "__main__":
Expand Down

0 comments on commit fcf1f0f

Please sign in to comment.