SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit e057ee06 authored by Geert Kapteijns's avatar Geert Kapteijns
Browse files

Start with DOICaller, which wraps crossref call and reading of JSON into class.

parent c3088ebf
No related branches found
No related tags found
No related merge requests found
......@@ -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):
......
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment