forked from MAMV3x3/MLH-Fellowship-pe-portfolio-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
curl-test.sh
executable file
·48 lines (38 loc) · 1.44 KB
/
curl-test.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
#!/bin/bash
# API URL
API_URL="$1"
# Generate a random timeline post
RANDOM_NAME=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)
RANDOM_EMAIL="${RANDOM_NAME}@example.com"
RANDOM_CONTENT="Random content for ${RANDOM_NAME}"
# POST request to create a timeline post
POST_RESPONSE=$(curl --request POST "${API_URL}/api/timeline_post" \
--data "name=${RANDOM_NAME}&email=${RANDOM_EMAIL}&content=${RANDOM_CONTENT}" \
--silent)
# Check if the POST request was successful
if [[ $POST_RESPONSE == *"\"id\""* ]]
then
echo "Timeline post created successfully."
# GET request to retrieve the timeline posts
GET_RESPONSE=$(curl --request GET "${API_URL}/api/timeline_post" --silent)
# Check if the created timeline post is present in the GET response
if [[ $GET_RESPONSE == *"${RANDOM_NAME}"* ]]
then
echo "Timeline post was added successfully."
# Extract the post ID from the post response
POST_ID=$(echo "${POST_RESPONSE}" | jq -r '.id')
# DELETE request to delete the timeline post
DELETE_RESPONSE=$(curl --request DELETE "${API_URL}/api/timeline_post/${POST_ID}" --silent)
# Check if the DELETE request was successful
if [[ $DELETE_RESPONSE == *"Successfully deleted"* ]]
then
echo "Timeline post was deleted successfully."
else
echo "Failed to delete the timeline post."
fi
else
echo "Failed to retrieve the timeline post."
fi
else
echo "Failed to create the timeline post."
fi