From f30e8c391b6455f174fd813acae83abadea5b84d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9renger=20Enselme?= Date: Fri, 23 Mar 2018 15:06:08 -0400 Subject: [PATCH] Add option to use test server for deposits --- crossref/__init__.py | 2 +- crossref/restful.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/crossref/__init__.py b/crossref/__init__.py index ee65984..9e23359 100644 --- a/crossref/__init__.py +++ b/crossref/__init__.py @@ -1 +1 @@ -VERSION = '1.2.0' +VERSION = '1.3.0' diff --git a/crossref/restful.py b/crossref/restful.py index dfad139..10795d1 100644 --- a/crossref/restful.py +++ b/crossref/restful.py @@ -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): """ @@ -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) @@ -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, @@ -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,