Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
ESCAPE2020
WP3
ZenodoCI
Commits
7c410898
Commit
7c410898
authored
Aug 03, 2020
by
Enrique Garcia
Browse files
add new method erase_file_entry
parent
129e0519
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
7 deletions
+26
-7
.zenodoci/zenodoapi.py
.zenodoci/zenodoapi.py
+26
-7
No files found.
.zenodoci/zenodoapi.py
View file @
7c410898
...
...
@@ -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: request
s
.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_file
s
_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 request
s
.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: request
s
.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: request
s
.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: request
s
.post answer
"""
url
=
f
"
{
self
.
zenodo_api_url
}
deposit/depositions/
{
entry_id
}
/actions/newversion"
parameters
=
{
'access_token'
:
self
.
access_token
}
...
...
Enrique Garcia
@garcia
mentioned in issue
#2 (moved)
·
Aug 03, 2020
mentioned in issue
#2 (moved)
mentioned in issue #2
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment