aboutsummaryrefslogtreecommitdiffstats
path: root/fatcat/api_client.py
diff options
context:
space:
mode:
Diffstat (limited to 'fatcat/api_client.py')
-rw-r--r--fatcat/api_client.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/fatcat/api_client.py b/fatcat/api_client.py
index 12c70407..181c3ca7 100644
--- a/fatcat/api_client.py
+++ b/fatcat/api_client.py
@@ -9,11 +9,9 @@ class FatCatApiClient:
self.host_url = host_url
self.session = requests.Session()
-
def get(self, path):
return self.session.get(self.host_url + path)
-
def post(self, path, data=None, headers=None):
hdrs = {"content-type": "application/json"}
if headers:
@@ -22,22 +20,27 @@ class FatCatApiClient:
# data = json.dumps(data, indent=None).encode('utf-8')
return self.session.post(self.host_url + path, json=data, headers=hdrs)
-
def import_crossref_file(self, json_file):
+ eg = self.new_edit_group()
with open(json_file, 'r') as file:
for line in file:
obj = json.loads(line)
- self.import_crossref_dict(obj)
-
+ self.import_crossref_dict(obj, editgroup=eg)
+ self.accept_editgroup(eg)
def new_edit_group(self):
- rv = self.post('/v0/editgroup')
+ rv = self.post('/v0/editgroup', data=dict(
+ editor=1))
assert rv.status_code == 200
editgroup_id = rv.json()['id']
return editgroup_id
+ def accept_editgroup(self, eg):
+ rv = self.post('/v0/editgroup/{}/accept'.format(eg))
+ assert rv.status_code == 200
+ return rv
- def import_crossref_dict(self, meta):
+ def import_crossref_dict(self, meta, editgroup=None):
# creators
creators = []
@@ -71,7 +74,7 @@ class FatCatApiClient:
# work and release
title = meta['title'][0]
rv = self.post('/v0/work',
- data=dict(title=title)) #work_type="book"
+ data=dict(title=title, editgroup=editgroup)) #work_type="book"
assert rv.status_code == 200
work_id = rv.json()['id']
@@ -88,6 +91,7 @@ class FatCatApiClient:
issue=meta.get('issue', None),
volume=meta.get('volume', None),
pages=meta.get('page', None),
+ editgroup=editgroup,
extra=dict(crossref={
'links': meta.get('link', []),
'subject': meta['subject'],
@@ -96,7 +100,6 @@ class FatCatApiClient:
assert rv.status_code == 200
release_id = rv.json()['id']
-
def health(self):
rv = self.get("/health")
assert rv.status_code == 200