forked from BrunoNZ/dspace-rest-requests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_request.sh
executable file
·49 lines (41 loc) · 1.06 KB
/
send_request.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
if [ $# != 5 ]; then
echo -e "ERRO! Wrong number parameter!"
echo -e "USE:"
echo -e "${0} <DSPACEURL> <TOKEN> <REQUEST_DECRIPTOR_FILE> <REQUEST_TYPE [\"json\"/\"xml\"]> <DSPACE_VERSION: [4,5,6]>"
exit 1
fi
DSPACEURL=${1}
TOKEN=${2}
REQUEST=${3}
REQUEST_TYPE=${4}
DSPACE_VERSION=${5}
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
if [[ ${DSPACE_VERSION} == 6 ]]; then
AUTH="--cookie \"${TOKEN}\""
else
AUTH="-H \"rest-dspace-token: ${TOKEN}\""
fi
echo -e "curl -k -4 --silent\
${AUTH} \
-H \"accept: application/${REQUEST_TYPE}\" \
-H \"Content-Type: application/${REQUEST_TYPE}\" \
-X ${VERB} \"${DSPACEURL}/${ACTION}\" \
-d \"${RQST}\""
curl -k -4 --silent\
${AUTH} \
-H "accept: application/${REQUEST_TYPE}" \
-H "Content-Type: application/${REQUEST_TYPE}" \
-X ${VERB} "${DSPACEURL}/${ACTION}" \
-d "${RQST}"
echo ""