diff --git a/scipost/services.py b/scipost/services.py index 395e61e7ea5859a147a2170994c84e43ab6c16c3..085b8698630ea6e162edfd6c538d3ad2e179631d 100644 --- a/scipost/services.py +++ b/scipost/services.py @@ -9,6 +9,22 @@ from .behaviors import ArxivCallable from strings import arxiv_caller_errormessages +class DOICaller: + def __init__(self, doi_string): + self.doi_string = doi_string + self._call_crosslink() + self._format_data() + + def _call_crosslink(self): + url = 'http://api.crossref.org/works/%s' % self.doi_string + self.crossref_data = requests.get(url).json() + + def _collect_data(self): + # read out json here. + + + +# I'm going to revamp this whole thing... class BaseCaller(object): '''Base mixin for caller (Arxiv, DOI). The basic workflow is to initiate the caller, call process() to make the actual call @@ -158,9 +174,9 @@ class BaseCaller(object): return t.render(Context(self.errorvariables)) -class DOICaller(BaseCaller): - """Perform a DOI lookup for a given identifier.""" - pass +# class DOICaller(BaseCaller): +# """Perform a DOI lookup for a given identifier.""" +# pass class ArxivCaller(BaseCaller): diff --git a/scipost/test_services.py b/scipost/test_services.py index e724b7856b0d5ec1a280239d440a66c1b758885b..d2aca0066b533a60216d26b40fa4d3c00de5b39e 100644 --- a/scipost/test_services.py +++ b/scipost/test_services.py @@ -1,6 +1,6 @@ from django.test import TestCase -from .services import ArxivCaller +from .services import ArxivCaller, DOICaller from submissions.models import Submission @@ -44,3 +44,12 @@ class ArxivCallerTest(TestCase): caller.process() self.assertEqual(caller.is_valid(), False) self.assertEqual(caller.errorcode, 'bad_identifier') + + +class DOICallerTest(TestCase): + def setUp(self): + self.doi_string = '10.1103/PhysRevB.92.214427' + self.caller = DOICaller(self.doi_string) + + def test_collects_data(self): + print(self.caller.crossref_data)