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
1 merge request!19update fetch methods
Pipeline #120611 passed
...@@ -21,6 +21,7 @@ class ZenodoAPI: ...@@ -21,6 +21,7 @@ class ZenodoAPI:
- Fetches a user's published entries, - Fetches a user's published entries,
- Creates a new deposit, - Creates a new deposit,
- Fetches any published record,
- Creates a new version of an existing deposit, - Creates a new version of an existing deposit,
- Uploads files to a specific Zenodo entry, - Uploads files to a specific Zenodo entry,
- Erases a non-published entry / new version draft, - Erases a non-published entry / new version draft,
...@@ -28,6 +29,9 @@ class ZenodoAPI: ...@@ -28,6 +29,9 @@ class ZenodoAPI:
new_version files), new_version files),
- Uploads information to the entry (Zenodo compulsory deposit information), - Uploads information to the entry (Zenodo compulsory deposit information),
- Publishes an entry - Publishes an entry
- Find all the published community entries
* per title
* per entry_id
:param access_token: str :param access_token: str
...@@ -87,7 +91,11 @@ class ZenodoAPI: ...@@ -87,7 +91,11 @@ class ZenodoAPI:
:return: request.get method :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) return requests.get(url, params=self.parameters)
def upload_file_entry(self, entry_id, name_file, path_file): def upload_file_entry(self, entry_id, name_file, path_file):
...@@ -135,7 +143,11 @@ class ZenodoAPI: ...@@ -135,7 +143,11 @@ class ZenodoAPI:
url = f"{self.zenodo_api_url}/deposit/depositions/{entry_id}" url = f"{self.zenodo_api_url}/deposit/depositions/{entry_id}"
headers = {"Content-Type": "application/json"} 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) headers=headers, params=self.parameters)
def erase_entry(self, entry_id): def erase_entry(self, entry_id):
...@@ -366,7 +378,8 @@ class ZenodoAPI: ...@@ -366,7 +378,8 @@ class ZenodoAPI:
print(" * Update metadata status OK !") print(" * Update metadata status OK !")
pprint.pprint(metadata_entry) pprint.pprint(metadata_entry)
else: 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") print(" ! Erasing dummy test entry...\n")
erase_error = self.erase_entry(test_entry_id) erase_error = self.erase_entry(test_entry_id)
if erase_error.status_code != 204: 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