Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Integration of auth functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDaub committed May 5, 2017
1 parent e27c239 commit e78418a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 48 deletions.
11 changes: 4 additions & 7 deletions omi_api/views/compositions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from flask import Blueprint
from flask_restful import reqparse, Resource, Api

Expand All @@ -13,11 +15,6 @@


class CompositionListApi(Resource):
#def get(self, entity_id):
# composition = entities.Work.from_persist_id(
# entity_id, plugin=coalaip.plugin, force_load=True)
# return composition.to_jsonld()

def post(self):
parser = reqparse.RequestParser()

Expand All @@ -40,8 +37,8 @@ def post(self):
}

copyright_holder = {
"public_key": "Cxj6Pct7T2hLhUh455tbvDWkVDY1vW5aoRGHZCtQkNKQ",
"private_key": "8vVgr68Cb5RzUm89nkALvVBmmSoBdC58MTAmqGr8HfYy",
"public_key": os.environ.get('OMI_PUBLIC_KEY', None),
"private_key": os.environ.get('OMI_PRIVATE_KEY', None)
}

work = coalaip.register_work(
Expand Down
76 changes: 35 additions & 41 deletions omi_api/views/recordings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from flask import Blueprint
from flask_restful import reqparse, Resource, Api

Expand All @@ -13,50 +15,42 @@
recording_api = Api(recording_views)


class RecordingApi(Resource):
def get(self, entity_id):
recording = entities.Manifestation.from_persist_id(
entity_id, plugin=coalaip.plugin, force_load=True)
return recording.to_jsonld()


class RecordingListApi(Resource):
def post(self):
parser = reqparse.RequestParser()
#TODO: Change to parse OMI body
#parser.add_argument('manifestation', type=manifestation_model,
# required=True, location='json')
#parser.add_argument('work', type=work_model, required=True,
# location='json')
#parser.add_argument('copyrightHolder', type=user_model, required=True,
# location='json')
#args = parser.parse_args()

#manifestation = args['manifestation']
#work = args['work']

#copyright_holder = args['copyrightHolder']
#copyright_holder = {
# 'public_key': copyright_holder.pop('publicKey'),
# 'private_key': copyright_holder.pop('privateKey')
#}

#copyright_, manifestation, work = coalaip.register_manifestation(
# manifestation_data=manifestation,
# copyright_holder=copyright_holder,
# work_data=work)

# Add the appropraite @id to the JSON-LD
res = {}
#for (entity, id_template, key) in [
# (copyright_, '../rights/{}', 'copyright'),
# (manifestation, '{}', 'manifestation'),
# (work, '../works/{}', 'work')]:
# ld_data = entity.to_jsonld()
# ld_data['@id'] = id_template.format(entity.persist_id)
# res[key] = ld_data

return res

# These are the required parameters
parser.add_argument('title', type=str, required=True, location='json')
parser.add_argument('composers', type=list, required=True,
location='json')
parser.add_argument('songwriters', type=list, required=True,
location='json')
parser.add_argument('publishers', type=list, required=True,
location='json')
args = parser.parse_args()

# Here we're transforming from OMI to COALA
work = {
'name': args['title'],
'composers': args['composers'],
'songwriters': args['songwriters'],
'publishers': args['publishers'],
}

copyright_holder = {
"public_key": os.environ.get('OMI_PUBLIC_KEY', None),
"private_key": os.environ.get('OMI_PRIVATE_KEY', None)
}

# TODO: Do a mongodb query to extract the id of the work

copyright_, manifestation, work = coalaip.register_manifestation(
manifestation_data=manifestation,
copyright_holder=copyright_holder,
work_data=work
)

return 'The recording was successfully registered.', 200


recording_api.add_resource(RecordingListApi, '/recordings',
Expand Down

0 comments on commit e78418a

Please sign in to comment.