def getData(request): """ POST http://localhost/oai_pmh/api/getdata/ POST data query='{"url":"value"}' """ try: serializer = IdentifySerializer(data=request.DATA) if serializer.is_valid(): url = request.POST['url'] if str(url).__contains__('?'): registryURl = str(url).split('?')[0] #Check if the OAI Registry is available sickle = Sickle(registryURl) sickle.Identify() http_response = requests.get(url) if http_response.status_code == status.HTTP_200_OK: return Response(http_response.text, status=status.HTTP_200_OK) else: raise OAIAPIException(message='An error occurred.', status=http_response.status_code) else: raise OAIAPIException(message='An error occurred, url malformed.', status=status.HTTP_400_BAD_REQUEST) else: raise OAIAPISerializeLabelledException(errors=serializer.errors, status=status.HTTP_400_BAD_REQUEST) except requests.HTTPError, err: content = APIMessage.getMessageLabelled(err.message) return Response(content, status=err.response.status_code)
def objectIdentify(request): """ POST http://localhost/oai_pmh/api/objectidentify POST data query='{"url":"value"}' """ try: serializer = IdentifySerializer(data=request.DATA) if serializer.is_valid(): url = request.DATA['url'] req = objectIdentifyByURL(url) return Response(req.data, status=req.status_code) else: raise OAIAPISerializeLabelledException(errors=serializer.errors, status=status.HTTP_400_BAD_REQUEST) except OAIAPIException as e: return e.response() except Exception: content = APIMessage.getMessageLabelled('An error occurred when attempting to identify resource') return Response(content, status=status.HTTP_500_INTERNAL_SERVER_ERROR)