Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to use test server for deposits #16

Merged
merged 1 commit into from
Mar 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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