-
Notifications
You must be signed in to change notification settings - Fork 12
bash client
Jakob Voß edited this page Apr 4, 2022
·
1 revision
This bash script implements read-access via PAIA, e.g. to check your loans. It requires a config file such as the following:
PATRON=012345678
PASSWORD=XXXXXXXX
API=https://paia.gbv.de/DE-7
Copy this script to your PATH as file paia
and make it executable:
#!/bin/bash -e
hash jq 2>/dev/null || { echo >&2 "$0 requires jq to be installed!"; exit 1; }
usage() {
echo "Usage: $0 [patron|items|fees]"
exit $1
}
[[ -z "$1" ]] && usage
CONFIG="$HOME/.config/paia/paia.conf"
if [ -e "$CONFIG" ]; then
. "$CONFIG"
else
echo "Missing config file $CONFIG setting PATRON, PASSWORD and API" >&2
exit 1
fi
login() {
curl -s -X POST $API/auth/login \
-d "username=$PATRON" -d "password=$PASSWORD" -d "grant_type=password" \
-d "scope=read_patron+read_fees+read_items+read_availability" \
| jq -er .access_token
}
if [[ "$1" == "patron" ]]; then
URL=$API/core/$PATRON
elif [[ "$1" == "items" || "$1" == "fees" ]]; then
URL=$API/core/$PATRON/$1
else
usage 1
fi
TOKEN=$(login)
curl -s $URL -H "Authorization: Bearer $TOKEN" | jq .