Unverified Commit a7004c78 authored by Stephen Rees's avatar Stephen Rees Committed by GitHub
Browse files

Update README.md

parent d721c54a
# ZenodoPHP
A PHP library for utilizing the Zenodo API
A PHP library for utilizing the Zenodo API. Requires >= PHP 7.0.
Zenodo is part of CERN and provides permanent archive and Digital Object Identifier (DOI) capabilities for free. You can sign up separately for their production environment at https://zenodo.org and for their sandbox environment at https://sandbox.zenodo.org
You will need to have an account with Zenodo to utilize this library for their REST API, which is documented at https://developers.zenodo.org. This library follow the documentation posted as of April 2020, with the exception of a couple minor details that Zenodo had not yet updated their documentation with.
# Example 1 - Retrieve all existing depositions
include_once('zenodoPHP.php');
$sandboxtoken = '';//your sandbox token
$connection = new zenodoConnection($sandboxtoken, 'sandbox');
$collection_obj = new ZenodoDepositionCollection($connection);
try{
$collection = $collection_obj->list_depositions();//returns an array of deposition objects
}catch (HttpRuntimeException $e){
//you should only have to catch the runtime exception the first time you request data from Zenodo
echo $e->getMessage();
echo var_export($connection->last_response());//this is where you will find details on any errors
return;
}catch(HttpResponseException $e){
//you should catch a response exception every time you request data from Zenodo.
echo $e->getMessage();
echo var_export($connection->last_response());
return;
}
echo var_export($collection);
# Example 2 - Retrieve a specific deposition
//leaving off the exception handling this time
$connection = new zenodoConnection('your_sandbox_token', 'sandbox');
$deposition = new zenodoDeposition($connection);
$deposition->retrieve_deposition(12345);//whatever your deposition ID is...
echo var_export($deposition->clean());//clean returns a cloned object stripped of extraneous data such as the connection
# Example 3 - Create a deposition
$connection = new zenodoConnection('your_sandbox_token', 'sandbox');
$deposition = new zenodoDeposition($connection);
$deposition->create_deposition();//deposition object is now created with Zenodo and ready to be populated with metadata
$deposition->add_file('path_to_file');//file should be uploaded to Zenodo with this call
//Or if you want to rename it...
$zenodo_file = $deposition->add_file('path_to_file');
$zenodo_file->filename('new name');
$zenodo_file->update_file();
//provide metadata for the deposition
$deposition->metadata->title('My First Deposition');
$deposition->metadata->description('This is an example of how to create a deposition with the Zenodo API');
$deposition->metadata->keywords(array('first','example'));
$deposition->update_deposition();
//Want to publish it? This locks it against changes and deletion permanently
$deposition->publish_deposition();
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