Skip to content
Snippets Groups Projects
Commit 1c262c04 authored by Bruno Nocera Zanette's avatar Bruno Nocera Zanette
Browse files

Add requests

parent a5ca501b
No related branches found
No related tags found
No related merge requests found
Showing
with 415 additions and 0 deletions
login.sh 0 → 100755
EMAIL=${1}
PASSWORD=${2}
DSPACEURL="https://localhost:8443/rest"
TYPE="json"
VERB="POST"
ACTION="login"
if [ $# != 2 ]; then
echo -e "ERROR! Wrong number parameter!"
echo -e "USE:"
echo -e "${0} <USER> <PASSWORD>"
exit 1
fi
RQST="{
\"email\":\"${EMAIL}\",
\"password\":\"${PASSWORD}\"
}"
curl -k -4 \
-H "accept: application/${TYPE}" \
-H "Content-Type: application/${TYPE}" \
-X ${VERB} "${DSPACEURL}/${ACTION}" \
-d "${RQST}"
TOKEN=${1}
DSPACEURL="https://localhost:8443/rest"
TYPE="json"
VERB="POST"
ACTION="logout"
if [ $# != 1 ]; then
echo -e "ERROR! Wrong number parameter!"
echo -e "USE:"
echo -e "${0} <TOKEN>"
exit 1
fi
RQST="{
\"email\":\"${EMAIL}\",
\"password\":\"${PASSWORD}\"
}"
curl -k -4 \
-H "rest-dspace-token: ${TOKEN}" \
-H "accept: application/${TYPE}" \
-H "Content-Type: application/${TYPE}" \
-X ${VERB} "${DSPACEURL}/${ACTION}"
# {}
USER="admin@dspace.com"
PASS="admin"
VERB="GET"
ACTION="status"
RQST_JSON='[]'
RQST_XML=''
# {}
VERB="POST"
ACTION="items/11/metadata"
RQST_JSON='
[
{
"key": "dc.title",
"value": "ADDED BY JSON (POST)",
"language": "en_US"
},
{
"key": "dc.description",
"value": "ADDED BY JSON",
"language": "en_US"
}
]
'
RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
???
'
# {"id":3,"name":"CREATED BY JSON (POST)","handle":"123456789/17","type":"collection","link":"/RESTapi/collections/3","expand":["parentCommunityList","parentCommunity","items","license","logo","all"],"logo":null,"parentCommunity":null,"parentCommunityList":[],"items":[],"license":null,"copyrightText":"CREATED BY JSON (POST)","introductoryText":"CREATED BY JSON (POST)","shortDescription":"CREATED BY JSON (POST)","sidebarText":"CREATED BY JSON (POST)","numberItems":0}
VERB="POST"
ACTION="communities/1/collections"
RQST_JSON='
{
"name":"CREATED BY JSON (POST)",
"copyrightText":"CREATED BY JSON (POST)",
"introductoryText":"CREATED BY JSON (POST)",
"shortDescription":"CREATED BY JSON (POST)",
"sidebarText":"CREATED BY JSON (POST)"
}
'
RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<collection>
<name>CREATED BY XML (POST)</name>
<type>CREATED BY XML (POST)</type>
<copyrightText>CREATED BY XML (POST)</copyrightText>
<introductoryText>CREATED BY XML (POST)</introductoryText>
<shortDescription>CREATED BY XML (POST)</shortDescription>
<sidebarText>CREATED BY XML (POST)</sidebarText>
</collection>
'
# {"id":2,"name":"CREATED BY JSON (POST)","handle":"123456789/19","type":"community","link":"/RESTapi/communities/2","expand":["parentCommunity","collections","subCommunities","logo","all"],"logo":null,"parentCommunity":null,"copyrightText":"CREATED BY JSON (POST)","introductoryText":"CREATED BY JSON (POST)","shortDescription":"CREATED BY JSON (POST)","sidebarText":"CREATED BY JSON (POST)","countItems":0,"subcommunities":[],"collections":[]}
VERB="POST"
ACTION="communities"
RQST_JSON='
{
"name":"CREATED BY JSON (POST)",
"copyrightText":"CREATED BY JSON (POST)",
"introductoryText":"CREATED BY JSON (POST)",
"shortDescription":"CREATED BY JSON (POST)",
"shortDescription":"CREATED BY JSON (POST)",
"sidebarText":"CREATED BY JSON (POST)"
}
'
RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<community>
<name>CREATED BY XML (POST)</name>
<copyrightText>CREATED BY XML (POST)</copyrightText>
<introductoryText>CREATED BY XML (POST)</introductoryText>
<shortDescription>CREATED BY XML (POST)</shortDescription>
<sidebarText>CREATED BY XML (POST)</sidebarText>
</community>
'
# {"id":12,"name":"TESTE 1","handle":"123456789/14","type":"item","link":"/RESTapi/items/12","expand":["metadata","parentCollection","parentCollectionList","parentCommunityList","bitstreams","all"],"lastModified":"2015-01-29 15:51:04.049","parentCollection":null,"parentCollectionList":null,"parentCommunityList":null,"bitstreams":null,"archived":"true","withdrawn":"false"}
VERB="POST"
ACTION="collections/1/items"
RQST_JSON='
{"metadata":[
{
"key": "dc.contributor.author",
"value": "LAST, FIRST"
},
{
"key": "dc.description",
"language": "pt_BR",
"value": "DESCRICAO"
},
{
"key": "dc.description.abstract",
"language": "pt_BR",
"value": "ABSTRACT"
},
{
"key": "dc.title",
"language": "pt_BR",
"value": "TESTE 1"
}
]}
'
RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<item>
<metadata>
<key>dc.contributor.author</key>
<value>LAST, FIRST</value>
<language>en_US</language>
</metadata>
<metadata>
<key>dc.description</key>
<value>DESCRIPTION</value>
<language>en_US</language>
</metadata>
<metadata>
<key>dc.description.abstract</key>
<value>ABSTRACT</value>
<language>en_US</language>
</metadata>
<metadata>
<key>dc.title</key>
<value>TITLE</value>
<language>en_US</language>
</metadata>
</item>'
# {"id":4,"name":"CREATED BY JSON (POST)","handle":"123456789/21","type":"community","link":"/RESTapi/communities/4","expand":["parentCommunity","collections","subCommunities","logo","all"],"logo":null,"parentCommunity":null,"copyrightText":"CREATED BY JSON (POST)","introductoryText":"CREATED BY JSON (POST)","shortDescription":"CREATED BY JSON (POST)","sidebarText":"CREATED BY JSON (POST)","countItems":0,"subcommunities":[],"collections":[]}
VERB="POST"
ACTION="communities/1/communities"
RQST_JSON='
{
"name":"CREATED BY JSON (POST)",
"copyrightText":"CREATED BY JSON (POST)",
"introductoryText":"CREATED BY JSON (POST)",
"shortDescription":"CREATED BY JSON (POST)",
"shortDescription":"CREATED BY JSON (POST)",
"sidebarText":"CREATED BY JSON (POST)"
}
'
RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<community>
<name>CREATED BY XML (POST)</name>
<copyrightText>CREATED BY XML (POST)</copyrightText>
<introductoryText>CREATED BY XML (POST)</introductoryText>
<shortDescription>CREATED BY XML (POST)</shortDescription>
<sidebarText>CREATED BY XML (POST)</sidebarText>
</community>
'
# {}
VERB="PUT"
ACTION="bitstreams/32"
RQST_JSON='
{
"name":"FILE_NAME.pdf",
"description":"DESCRIPTION OF THE FILE"
}
'
RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<bitstream>
<name>FILE_NAME.pdf</name>
<description>DESCRIPTION OF THE FILE</description>
</bitstream>
'
# {}
VERB="PUT"
ACTION="collections/2"
RQST_JSON='
{
"name":"CHANGED BY JSON (PUT)",
"type":"CHANGED BY JSON (PUT)",
"copyrightText":"CHANGED BY JSON (PUT)",
"introductoryText":"CHANGED BY JSON (PUT)",
"shortDescription":"CHANGED BY JSON (PUT)",
"sidebarText":"CHANGED BY JSON (PUT)"
}'
RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<collection>
<name>CHANGED BY XML (PUT)</name>
<type>CHANGED BY XML (PUT)</type>
<copyrightText>CHANGED BY XML (PUT)</copyrightText>
<introductoryText>CHANGED BY XML (PUT)</introductoryText>
<shortDescription>CHANGED BY XML (PUT)</shortDescription>
<sidebarText>CHANGED BY XML (PUT)</sidebarText>
</collection>'
# {}
VERB="PUT"
ACTION="communities/2"
TYPE="json"
RQST_JSON='
{
"name":"CHANGED BY JSON (POST)",
"copyrightText":"CHANGED BY JSON (POST)",
"introductoryText":"CHANGED BY JSON (POST)",
"shortDescription":"CHANGED BY JSON (POST)",
"shortDescription":"CHANGED BY JSON (POST)",
"sidebarText":"CHANGED BY JSON (POST)"
}
'
RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<community>
<name>CHANGED BY XML (POST)</name>
<copyrightText>CHANGED BY XML (POST)</copyrightText>
<introductoryText>CHANGED BY XML (POST)</introductoryText>
<shortDescription>CHANGED BY XML (POST)</shortDescription>
<sidebarText>CHANGED BY XML (POST)</sidebarText>
</community>
'
# {}
VERB="PUT"
ACTION="items/11/metadata"
TYPE="json"
RQST_JSON='
[
{
"key": "dc.title",
"value": "TESTE - CHANGED BY JSON (PUT)",
"language": "pt_BR"
},
{
"key": "dc.description",
"value": "DESCRIPTION - CHANGED BY JSON",
"language": "pt_BR"
}
]
'
RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
???
'
# {}
VERB="PUT"
ACTION="bitstreams/32/data"
FILE="/home/bruno/C3SL/projeto-mec/testes-rest/v_ShellScript/requests/files/DSpaceREST_index.html"
# <?xml version="1.0" encoding="UTF-8" standalone="yes"?><bitstream><expand>parent</expand><expand>policies</expand><expand>all</expand><id>35</id><type>bitstream</type><bundleName>ORIGINAL</bundleName><checkSum checkSumAlgorithm="MD5">357ca1187f7eb6a580fec95fb3cec6f7</checkSum><format>Unknown</format><mimeType>application/octet-stream</mimeType><retrieveLink>/bitstreams/35/retrieve</retrieveLink><sequenceId>-1</sequenceId><sizeBytes>99021</sizeBytes></bitstream>
# {"id":37,"name":null,"handle":null,"type":"bitstream","link":"/RESTapi/bitstreams/37","expand":["parent","policies","all"],"bundleName":"ORIGINAL","description":null,"format":"Unknown","mimeType":"application/octet-stream","sizeBytes":99021,"parentObject":null,"retrieveLink":"/bitstreams/37/retrieve","checkSum":{"value":"791274902ccd308c8a411e0d3395ec03","checkSumAlgorithm":"MD5"},"sequenceId":-1,"policies":null}
VERB="POST"
ACTION="items/11/bitstreams"
FILE="/home/bruno/C3SL/projeto-mec/testes-rest/v_ShellScript/requests/files/pdf1.pdf"
<!-- saved from url=(0029)https://demo.dspace.org/rest/ -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>DSpace REST - index</title><style type="text/css"></style></head><body><h1>DSpace REST API</h1>Server path: /rest<h2>Index</h2><ul><li>GET / - Return this page.</li><li>GET /test - Return the string "REST api is running" for testing purposes.</li><li>POST /login - Method for logging into the DSpace RESTful API. You must post User class. Example: {"email":"test@dspace","password":"pass"}. Returns a token which must be included in future requests in the "rest-dspace-token" header.</li><li>POST /logout - Method for logging out of the DSpace RESTful API. The request must include the "rest-dspace-token" token</li> header.</ul><h2>Communities</h2><ul><li>GET /communities - Return an array of all communities in DSpace.</li><li>GET /communities/top-communities - Returns an array of all top-leve communities in DSpace.</li><li>GET /communities/{communityId} - Returns a community with the specified ID.</li><li>GET /communities/{communityId}/collections - Returns an array of collections of the specified community.</li><li>GET /communities/{communityId}/communities - Returns an array of subcommunities of the specified community.</li><li>POST /communities - Create a new top-level community. You must post a community.</li><li>POST /communities/{communityId}/collections - Create a new collection in the specified community. You must post a collection.</li><li>POST /communities/{communityId}/communities - Create a new subcommunity in the specified community. You must post a community.</li><li>PUT /communities/{communityId} - Update the specified community.</li><li>DELETE /communities/{communityId} - Delete the specified community.</li><li>DELETE /communities/{communityId}/collections/{collectionId} - Delete the specified collection in the specified community.</li><li>DELETE /communities/{communityId}/communities/{communityId2} - Delete the specified subcommunity (communityId2) in the specified community (communityId).</li></ul><h2>Collections</h2><ul><li>GET /collections - Return all DSpace collections in array.</li><li>GET /collections/{collectionId} - Return a collection with the specified ID.</li><li>GET /collections/{collectionId}/items - Return all items of the specified collection.</li><li>POST /collections/{collectionId}/items - Create an item in the specified collection. You must post an item.</li><li>POST /collections/find-collection - Find a collection by name.</li><li>PUT /collections/{collectionId} </li> - Update the specified collection. You must post a collection.<li>DELETE /collections/{collectionId} - Delete the specified collection from DSpace.</li><li>DELETE /collections/{collectionId}/items/{itemId} - Delete the specified item (itemId) in the specified collection (collectionId). </li></ul><h2>Items</h2><ul><li>GET /items - Return a list of items.</li><li>GET /items/{item id} - Return the specified item.</li><li>GET /items/{item id}/metadata - Return metadata of the specified item.</li><li>GET /items/{item id}/bitstreams - Return bitstreams of the specified item.</li><li>POST /items/find-by-metadata-field - Find items by the specified metadata value.</li><li>POST /items/{item id}/metadata - Add metadata to the specified item.</li><li>POST /items/{item id}/bitstreams - Add a bitstream to the specified item.</li><li>PUT /items/{item id}/metadata - Update metadata in the specified item.</li><li>DELETE /items/{item id} - Delete the specified item.</li><li>DELETE /items/{item id}/metadata - Clear metadata of the specified item.</li><li>DELETE /items/{item id}/bitstreams/{bitstream id} - Delete the specified bitstream of the specified item.</li></ul><h2>Bitstreams</h2><ul><li>GET /bitstreams - Return all bitstreams in DSpace.</li><li>GET /bitstreams/{bitstream id} - Return the specified bitstream.</li><li>GET /bitstreams/{bitstream id}/policy - Return policies of the specified bitstream.</li><li>GET /bitstreams/{bitstream id}/retrieve - Return the contents of the specified bitstream.</li><li>POST /bitstreams/{bitstream id}/policy - Add a policy to the specified bitstream.</li><li>PUT /bitstreams/{bitstream id}/data - Update the contents of the specified bitstream.</li><li>PUT /bitstreams/{bitstream id} - Update metadata of the specified bitstream.</li><li>DELETE /bitstreams/{bitstream id} - Delete the specified bitstream from DSpace.</li><li>DELETE /bitstreams/{bitstream id}/policy/{policy_id} - Delete the specified bitstream policy.</li></ul> </body></html>
\ No newline at end of file
File added
#!/bin/bash
if [ $# != 4 ]; then
echo -e "ERRO! Wrong number parameter!"
echo -e "USE:"
echo -e "${0} <DSPACEURL> <TOKEN> <REQUEST_DECRIPTOR_FILE> <REQUEST_TYPE [\"json\"/\"xml\"]>"
exit 1
fi
DSPACEURL=${1}
TOKEN=${2}
REQUEST=${3}
REQUEST_TYPE=${4}
if [ -e ${REQUEST} ]; then
source $REQUEST
else
echo "ERROR! Request descriptor file not found!"
exit 1
fi
curl -k -4 \
-H "rest-dspace-token: ${TOKEN}" \
-H "accept: application/${REQUEST_TYPE}" \
-X ${VERB} "${DSPACEURL}/${ACTION}" \
-F upload=@"${FILE}"
#!/bin/bash
if [ $# != 4 ]; then
echo -e "ERRO! Wrong number parameter!"
echo -e "USE:"
echo -e "${0} <DSPACEURL> <TOKEN> <REQUEST_DECRIPTOR_FILE> <REQUEST_TYPE [\"json\"/\"xml\"]>"
exit 1
fi
DSPACEURL=${1}
TOKEN=${2}
REQUEST=${3}
REQUEST_TYPE=${4}
if [ -e ${REQUEST} ]; then
source $REQUEST
else
echo "ERROR! Request descriptor file not found!"
exit 1
fi
case ${REQUEST_TYPE} in
"json") RQST=${RQST_JSON} ;;
"xml") RQST=${RQST_XML} ;;
*) echo -e "ERROR! TYPE MUST BE: \"json\" OR \"xml\"."; exit 1 ;;
esac
curl -k -4 --silent\
-H "rest-dspace-token: ${TOKEN}" \
-H "accept: application/${REQUEST_TYPE}" \
-H "Content-Type: application/${REQUEST_TYPE}" \
-X ${VERB} "${DSPACEURL}/${ACTION}" \
-d "${RQST}"
DSPACEURL="https://localhost:8443/rest"
EMAIL="admin@dspace.com"
PASSWORD="admin"
TOKEN=$(./login.sh ${EMAIL} ${PASSWORD})
for R in $(ls requests/POST_*); do
for T in json xml; do
echo "EXECUTING REQUEST: $R ($T):"
echo "--------------------------------------------"
./send_request.sh $DSPACEURL $TOKEN $R $T
echo ""
echo "--------------------------------------------"
echo ""
done
done
for R in $(ls requests/PUT_*); do
for T in json xml; do
echo "EXECUTING REQUEST: $R ($T):"
echo "--------------------------------------------"
./send_request.sh $DSPACEURL $TOKEN $R $T
echo ""
echo "--------------------------------------------"
echo ""
done
done
for R in $(ls requests/UPLOAD_*); do
for T in json xml; do
echo "EXECUTING REQUEST: $R ($T):"
echo "--------------------------------------------"
./send_file.sh $DSPACEURL $TOKEN $R $T
echo ""
echo "--------------------------------------------"
echo ""
done
done
./logout.sh ${TOKEN}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment