Skip to content
Snippets Groups Projects
Commit b0814dc5 authored by Enrique's avatar Enrique
Browse files

update fetch methods

parent 189be17c
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@ class ZenodoAPI:
- Fetches a user's published entries,
- Creates a new deposit,
- Fetches any published record,
- Creates a new version of an existing deposit,
- Uploads files to a specific Zenodo entry,
- Erases a non-published entry / new version draft,
......@@ -28,6 +29,9 @@ class ZenodoAPI:
new_version files),
- Uploads information to the entry (Zenodo compulsory deposit information),
- Publishes an entry
- Find all the published community entries
* per title
* per entry_id
:param access_token: str
......@@ -87,7 +91,11 @@ class ZenodoAPI:
:return: request.get method
"""
url = f"{self.zenodo_api_url}/deposit/depositions/{entry_id}"
# In case of entries created by oneself, and maybe not published yet, the method to fetch them is
# request.get('api/deposit/deposition/{entry_id}')
# To fetch any other entry not belonging/published to yourself/user
url = f"{self.zenodo_api_url}/records/{entry_id}"
return requests.get(url, params=self.parameters)
def upload_file_entry(self, entry_id, name_file, path_file):
......@@ -135,7 +143,11 @@ class ZenodoAPI:
url = f"{self.zenodo_api_url}/deposit/depositions/{entry_id}"
headers = {"Content-Type": "application/json"}
return requests.put(url, data=json.dumps(json_metadata),
# The metadata field is already created, just need to be updated.
# Thus the root 'metadata' key need to be kept, to indicate the field to be updated.
data = {"metadata": json_metadata}
return requests.put(url, data=json.dumps(data),
headers=headers, params=self.parameters)
def erase_entry(self, entry_id):
......@@ -366,7 +378,8 @@ class ZenodoAPI:
print(" * Update metadata status OK !")
pprint.pprint(metadata_entry)
else:
print(" ! ERROR while testing update of metadata\n", update_metadata.json())
print(" ! ERROR while testing update of metadata\n",
update_metadata.json(), "\n", metadata_entry)
print(" ! Erasing dummy test entry...\n")
erase_error = self.erase_entry(test_entry_id)
if erase_error.status_code != 204:
......
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