Usability

Muss ja kein rohes JSON anzeigen…
This commit is contained in:
Gandalf 2021-03-04 19:44:27 +01:00
parent a69447ca5f
commit e94b3dc78e
2 changed files with 21 additions and 6 deletions

25
fax.sh
View file

@ -1,21 +1,36 @@
#! /bin/bash #! /bin/bash
#Check if I have enough parameters:
if [ -z $2 ]
then
echo "Usage:
$ ./fax.sh <letter.pdf> <recipient>
where <recipient> has to be a german faxline number"
exit 1
fi
. authorization.sh . authorization.sh
#Prepare fax credentials: #Prepare fax credentials:
FILE=$1 FILE=$1
echo $FILE echo -n "Sending file ${FILE} "
REC=$(echo $2 | sed -e 's:[^+0-9]::g' -e 's:^0\([1-9]\):+49\1:') REC=$(echo $2 | sed -e 's:[^+0-9]::g' -e 's:^0\([1-9]\):+49\1:')
echo "to $REC"
#Needs to be base64 encoded: #Needs to be base64 encoded:
CONTENT=$(base64 $FILE -w 0) CONTENT=$(base64 $FILE -w 0)
if [ -z "$CONTENT" ]; if [ -z "$CONTENT" ];
then then
echo "Encoding failed" echo "Encoding failed"
fi fi
DATA='{"faxlineId":"f0", "recipient":"+495512829364", "filename":"fax.pdf", "base64Content":"'${CONTENT}'"}' DATA='{"faxlineId":"f0", "recipient":"'${REC}'", "filename":"fax.pdf", "base64Content":"'${CONTENT}'"}'
#Send fax #Send fax
curl -i --request POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" --data "$DATA" "https://api.sipgate.com/v2/sessions/fax" -s FAXID=$(curl --request POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" --data "$DATA" "https://api.sipgate.com/v2/sessions/fax" -s | jq '.sessionId' | sed -e 's:"::g' )
echo if [ -z $FAXID ]
then
echo "Something went wrong, I didn't receive some fax id back."
else
echo "Sipgate took your fax as sessionID $FAXID"
echo "$FAXID" >> .fax_history
fi
#Check if fax request was accepted by sipgate #Check if fax request was accepted by sipgate
curl --request GET --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" "https://api.sipgate.com/v2/history" -s | jq curl --request GET --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" "https://api.sipgate.com/v2/history/$FAXID" -s | jq '.faxStatusType'
#And show the account balance #And show the account balance
. getbalance.sh . getbalance.sh

View file

@ -2,4 +2,4 @@ BAL=$(curl --request GET --header 'Content-Type: application/json' --header 'Acc
AMOUNT=$(echo $BAL | jq '.amount') AMOUNT=$(echo $BAL | jq '.amount')
CUR=$(echo $BAL | jq '.currency' | sed -e 's:"::g' ) CUR=$(echo $BAL | jq '.currency' | sed -e 's:"::g' )
AMOUNT=$(echo "scale=2; $AMOUNT/10000" | bc -l) AMOUNT=$(echo "scale=2; $AMOUNT/10000" | bc -l)
echo $CUR $AMOUNT echo "Your current balance is "$CUR $AMOUNT