Last active
April 12, 2018 07:49
-
-
Save pjvds/ebfeb1203981814025468ca767a6f92b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
[ -z "$EMAIL" ] && echo "Need to set EMAIL" && exit 1; | |
[ -z "$PASSWORD" ] && echo "Need to set PASSWORD" && exit 1; | |
[ -z "$ADMINISTRATIONID" ] && echo "Need to set ADMINISTRATIONID" && exit 1; | |
[ -z "$IMPORTID" ] && echo "Need to set IMPORTID" && exit 1; | |
[ -x "$(command -v http)" ] && echo "Need to install httpie" && exit 1; | |
[ -x "$(command -v jq)" ] && echo "Need to install jq" && exit 1; | |
rlogin=$(mktemp) | |
rimport=$(mktemp) | |
if http --session='moneymonk' --check-status POST \ | |
https://www.moneymonk.nl/api/v1/authentication/login \ | |
'Content-Type:application/x-www-form-urlencoded' \ | |
<<< "{\"email_address\":\"$EMAIL\",\"password\":\"$PASSWORD\", \"client_identifier\":\"RMtyge4S764g0Hitg7Xj\"}" 1> $rlogin; then | |
echo 'login success' | |
else | |
echo 'import trigger failure:' | |
case $? in | |
2) echo 'Request timed out!' ;; | |
3) echo 'Unexpected HTTP 3xx Redirection!' ;; | |
4) echo 'HTTP 4xx Client Error!' ;; | |
5) echo 'HTTP 5xx Server Error!' ;; | |
6) echo 'Exceeded --max-redirects=<n> redirects!' ;; | |
*) echo 'Other Error!' ;; | |
esac | |
exit 1; | |
fi | |
if http --session='moneymonk' --check-status POST "https://www.moneymonk.nl/api/v1/administrations/$ADMINISTRATIONID/integrations/bunq/import/$IMPORTID" 1> $rimport; then | |
echo 'import trigger success' | |
echo "imported: $(cat $rimport | jq '.number_of_transactions')" | |
else | |
echo 'import trigger failure:' | |
case $? in | |
2) echo 'Request timed out!' ;; | |
3) echo 'Unexpected HTTP 3xx Redirection!' ;; | |
4) echo 'HTTP 4xx Client Error!' ;; | |
5) echo 'HTTP 5xx Server Error!' ;; | |
6) echo 'Exceeded --max-redirects=<n> redirects!' ;; | |
*) echo 'Other Error!' ;; | |
esac | |
exit 1; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment