Skip to content

Instantly share code, notes, and snippets.

@pjvds
Last active April 12, 2018 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjvds/ebfeb1203981814025468ca767a6f92b to your computer and use it in GitHub Desktop.
Save pjvds/ebfeb1203981814025468ca767a6f92b to your computer and use it in GitHub Desktop.
#!/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