From e057ee06690e9f0e467d787e6bc14e785a8c60e6 Mon Sep 17 00:00:00 2001 From: Geert Kapteijns <ghkapteijns@gmail.com> Date: Sun, 23 Apr 2017 16:30:09 +0200 Subject: [PATCH] Start with DOICaller, which wraps crossref call and reading of JSON into class. --- scipost/services.py | 22 +++++++++++++++++++--- scipost/test_services.py | 11 ++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/scipost/services.py b/scipost/services.py index 395e61e7e..085b86986 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 e724b7856..d2aca0066 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) -- GitLab