Skip to content

Commit

Permalink
Merge pull request #16 from benselme/enable-test-deposits
Browse files Browse the repository at this point in the history
Add option to use test server for deposits
  • Loading branch information
fabiobatalha authored Mar 23, 2018
2 parents 32323dc + f30e8c3 commit 53f84ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crossref/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '1.2.0'
VERSION = '1.3.0'
14 changes: 10 additions & 4 deletions crossref/restful.py
Original file line number Diff line number Diff line change
Expand Up @@ -1730,12 +1730,18 @@ def works(self, issn):

class Depositor(object):

def __init__(self, prefix, api_user, api_key, etiquette=None):
def __init__(self, prefix, api_user, api_key, etiquette=None,
use_test_server=False):
self.do_http_request = HTTPRequest(throttle=False).do_http_request
self.etiquette = etiquette or Etiquette()
self.prefix = prefix
self.api_user = api_user
self.api_key = api_key
self.use_test_server = use_test_server

def get_endpoint(self, verb):
subdomain = 'test' if self.use_test_server else 'doi'
return "https://{}.crossref.org/servlet/{}".format(subdomain, verb)

def register_doi(self, submission_id, request_xml):
"""
Expand All @@ -1749,7 +1755,7 @@ def register_doi(self, submission_id, request_xml):
compliance with the Crossref Submission Schema.
"""

endpoint = "https://doi.crossref.org/servlet/deposit"
endpoint = self.get_endpoint('deposit')

files = {
'mdFile': ('%s.xml' % submission_id, request_xml)
Expand Down Expand Up @@ -1783,7 +1789,7 @@ def request_doi_status_by_filename(self, file_name, data_type='result'):
result - retrieve a JSON with the status of the submission
"""

endpoint = "https://doi.crossref.org/servlet/submissionDownload"
endpoint = self.get_endpoint('submissionDownload')

params = {
'usr': self.api_user,
Expand Down Expand Up @@ -1813,7 +1819,7 @@ def request_doi_status_by_batch_id(self, doi_batch_id, data_type='result'):
result - retrieve a XML with the status of the submission
"""

endpoint = "https://doi.crossref.org/servlet/submissionDownload"
endpoint = self.get_endpoint('submissionDownload')

params = {
'usr': self.api_user,
Expand Down

0 comments on commit 53f84ee

Please sign in to comment.