-
Notifications
You must be signed in to change notification settings - Fork 75
/
apiClientExample.sh
executable file
·78 lines (59 loc) · 2.18 KB
/
apiClientExample.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
# This script registers a new account at a stakepool, waits a bit
# for the email verification link to be clicked, submits an address,
# requests the ticket purchasing information for the account, and
# then requests the pool's statistics.
apiKEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0ODE3MzAzNjYsImlzcyI6Imh0dHA6Ly8xMjcuMC4wLjE6ODAwMCIsImxvZ2dlZEluQXMiOjY0fQ.DS49iqN3hFjAqwTnUKIbJ-Mg3sdwKUVE_diwp7dTok4"
apiURL="http://127.0.0.1:8000/api/v1"
#cookieFile=$(mktemp /tmp/stakepoolapiclient.XXXXXXXXXX)
email="[email protected]"
password="blake256"
pubKeyAddr="TkKnJTAQTQ42nAwLj9wSXJcrKadSJneNkXT9LW25kqBKH646N4Bws"
secsForEmailVerification=15
apiCmd() {
# $1 = cmd, $2 = data
if [ -z "$2" ]; then
echo "running curl -s -H \"Authorization: Bearer $apiKEY\" $apiURL/$1"
r=$(curl -s -H "Authorization: Bearer $apiKEY" $apiURL/$1)
else
echo "running curl -s -H \"Authorization: Bearer $apiKEY\" --data $2 $apiURL/$1"
r=$(curl -s -H "Authorization: Bearer $apiKEY" --data "$2" $apiURL/$1)
fi
if [ -z "$r" ]; then
fatal "command $1 failed"
fi
status=$(echo $r |jq -r .status)
if [ "$status" == "error" ]; then
echo "WARNING: command returned with error"
fi
# can add additional processing of the result here
echo $r
}
cleanUp() {
echo "removing $cookieFile"
rm $cookieFile
}
fatal() {
echo >&2 "$1"
#cleanUp
exit 1
}
updateCsrfToken() {
csrftoken=$(grep XSRF-TOKEN $cookieFile |awk '{print $7}')
}
waitForVerification() {
echo "sleeping $secsForEmailVerification seconds to allow email verification link to be clicked"
for i in `seq $secsForEmailVerification -1 1`;
do echo "$i seconds left to verify email"; sleep 1
done
}
command -v jq >/dev/null 2>&1 || { fatal "I require the binary jq (https://stedolan.github.io/jq/) but it's not installed. Aborting."; }
#echo "using cookieFile $cookieFile"
#apiCmd "startsession"
#apiCmd "register" "email=$email&password=$password&passwordrepeat=$password"
#waitForVerification
#apiCmd "login" "email=$email&password=$password"
apiCmd "address" "UserPubKeyAddr=$pubKeyAddr"
apiCmd "getpurchaseinfo"
apiCmd "stats"
#cleanUp