-
Notifications
You must be signed in to change notification settings - Fork 0
/
requests.sh
executable file
·63 lines (56 loc) · 1.74 KB
/
requests.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
function put_game() {
echo "posting game"
curl -X PUT -H "Content-Type: application/json" -d "{\"maxScore\": 2, \"score1\": 2, \"score2\": 1}" 127.0.0.1:3000/api/games
}
function post_game() {
if [[ -z ${1+x} ]]; then
echo "please enter a game id"
fi
curl -X POST -H "Content-Type: application/json" -d "{\"maxScore\": 2, \"score1\": 2, \"score2\": 1}" 127.0.0.1:3000/api/games
}
function post_player_add() {
echo "==== Adding new player ===="
# extract sample player id for other test calls
res=`curl -X POST -H "Content-Type: application/json" -d "{\"name\":\"testname\",\"elo\":12345}" 127.0.0.1:3000/api/players/add -s`
echo $res
playerId=`perl -e '$ARGV[0] =~ /(?<=\"_id\":\")\w{24}/; print $&;' $res`
}
function post_player() {
echo "==== Editing player ===="
if [[ -z $playerId ]]; then
echo "make sure a valid player id was extracted by calling post_player_add before"
else
curl -X POST -H "Content-Type: application/json" -d "{\"name\":\"newTestName\",\"elo\":54321}" 127.0.0.1:3000/api/players/$playerId -s
fi
}
function delete_player() {
echo ''
echo "==== Deleting player ===="
if [[ -z $playerId ]]; then
echo "make sure a valid player id was extracted by calling post_player_add before"
else
curl -X DELETE 127.0.0.1:3000/api/players/$playerId
fi
}
# Check the number of arguments
if [[ "$#" -lt 1 ]]; then
echo "Please specify what to execute"
exit 1
fi
case "$1" in
putGame )
put_game
;;
post_player )
post_player_add
post_player $playerId
delete_player $playerId
;;
all )
put_game
;;
* )
echo "invalid argument: $1"
;;
esac