Commit 7c410898 authored by Enrique Garcia's avatar Enrique Garcia
Browse files

add new method erase_file_entry

parent 129e0519
......@@ -7,7 +7,7 @@ import requests
class ZenodoAPI:
def __init__(self, access_token, sandbox=True):
"""
Manages the communication with the (sandbox.)zenodo REST API.
Manages the communication with the (sandbox.)zenodo REST API through the Python request library.
This class is **EXCLUSIVELY** developed to be used within a CI/CD pipeline and to **EXCLUSIVELY PERFORM**
five tasks within the (sandbox.)zenodo api environment:
......@@ -37,7 +37,7 @@ class ZenodoAPI:
Create a new entry / deposition in (sandbox.)zenodo
POST method to {zenodo_api_url}/deposit/depositions
:return: request.put answer
:return: requests.put answer
"""
url = f"{self.zenodo_api_url}/deposit/depositions"
headers = {"Content-Type": "application/json"}
......@@ -45,7 +45,7 @@ class ZenodoAPI:
return requests.post(url, headers=headers, params=parameters)
def upload_files_entry(self, entry_id, name_file, path_file):
def upload_file_entry(self, entry_id, name_file, path_file):
"""
Upload a file to a Zenodo entry. If first retrieve the entry by a GET method to the
{zenodo_api_url}/deposit/depositions/{entry_id}.
......@@ -58,7 +58,7 @@ class ZenodoAPI:
:param path_file: str
Path to the file to be uploaded
:return: json request.put object
:return: json requests.put object
"""
# 1 - Retrieve and recover information of an existing deposit
parameters = {'access_token': self.access_token}
......@@ -85,7 +85,7 @@ class ZenodoAPI:
:param data: object
json object containing the metadata (compulsory fields) that are enclosed when a new entry is created.
:return: request.put answer
:return: requests.put answer
"""
url = f"{self.zenodo_api_url}/deposit/depositions/{entry_id}"
headers = {"Content-Type": "application/json"}
......@@ -93,6 +93,25 @@ class ZenodoAPI:
return requests.put(url, data=json.dump(data), headers=headers, params=parameters)
def erase_file_entry(self, entry_id, file_id):
"""
Erase a file from an entry resource.
This method is intended to be used for substitution of files (deletion) within an entry by their correspondent
new versions.
DELETE method to {zenodo_api_url}/deposit/depositions/{entry_id}/files/{file_id}
:param entry_id: str
deposition_id of the Zenodo entry
:param file_id: str
Id of the files stored in Zenodo
:return: requests.delete answer
"""
url = f"{self.zenodo_api_url}/deposit/depositions/{entry_id}/files/{file_id}"
parameters = {'access_token': self.access_token}
return requests.delete(url, params=parameters)
def publish_entry(self, entry_id):
"""
Publishes an entry in (sandbox.)zenodo
......@@ -101,7 +120,7 @@ class ZenodoAPI:
:param entry_id: str
deposition_id of the Zenodo entry
:return: request.put answer
:return: requests.put answer
"""
url = f"{self.zenodo_api_url}/deposit/depositions/{entry_id}/actions/publish"
parameters = {'access_token': self.access_token}
......@@ -116,7 +135,7 @@ class ZenodoAPI:
:param entry_id: str
deposition_id of the Zenodo entry
:return: request.post answer
:return: requests.post answer
"""
url = f"{self.zenodo_api_url}deposit/depositions/{entry_id}/actions/newversion"
parameters = {'access_token': self.access_token}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment