From 3908b5dde958ce01f0b004a7c3c99af72642c4f9 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Wed, 28 Apr 2021 01:24:02 +0500 Subject: [PATCH] added adding contacts --- addcontact-bml.sh | 40 ++++++++++++++++++++++++++++++++++++++++ addcontact-menu.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ contactsmenu.sh | 7 ++++--- listcontacts.sh | 3 +++ mainmenu.sh | 0 parser_json_test.sh | 4 ++-- 6 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 addcontact-bml.sh create mode 100644 addcontact-menu.sh mode change 100755 => 100644 contactsmenu.sh create mode 100644 listcontacts.sh mode change 100755 => 100644 mainmenu.sh mode change 100755 => 100644 parser_json_test.sh diff --git a/addcontact-bml.sh b/addcontact-bml.sh new file mode 100644 index 0000000..4c18261 --- /dev/null +++ b/addcontact-bml.sh @@ -0,0 +1,40 @@ + + +printf 'Account Number: ' +read -r ACCOUNT_NUMBER +VALID_NUMBER=$(curl -s -b $COOKIE $BML_URL/validate/account/$ACCOUNT_NUMBER \ + | jq -r .success) + +if [ "$VALID_NUMBER" = "true" ] +then + + NAME=$(curl -s -b $COOKIE $BML_URL/validate/account/$ACCOUNT_NUMBER \ + | jq -r '.["payload"] | .name') + CURRENCY=$(curl -s -b $COOKIE $BML_URL/validate/account/$ACCOUNT_NUMBER \ + | jq -r '.["payload"] | .currency') + echo "Account Name: $NAME" + echo "Currency: $CURRENCY" + echo "" + printf 'Contact Name: ' + read -r CONTACT_NAME + ADDCONTACT=$(curl -s -b $COOKIE $BML_URL/contacts \ + --data-raw contact_type=IAT \ + --data-raw account=$ACCOUNT_NUMBER \ + --data-raw alias=$CONTACT_NAME \ + --compressed \ + | jq -r .success) + + if [ "$ADDCONTACT" = "true" ] + then + echo "Contact added successfully" + else + echo "${red}There was an error${reset}" + source contactsmenu.sh + fi +else + echo "${red}Invalid Account${reset}" 1>&2 + source contactsmenu.sh +fi + +source contactsmenu.sh + diff --git a/addcontact-menu.sh b/addcontact-menu.sh new file mode 100644 index 0000000..55753b1 --- /dev/null +++ b/addcontact-menu.sh @@ -0,0 +1,43 @@ +echo "" +echo "Add Contact" +echo "" +echo "1 - BML" +echo "2 - Domestic" +echo "3 - International" +echo "4 - BillPay" +echo "5 - Go back" +echo "6 - Exit" +echo "" +printf 'Select contact type[1]: ' +read -r CONTACT_TYPE + +if [ "$CONTACT_TYPE" = "1" ] + then + source addcontact-bml.sh +elif [ "$CONTACT_TYPE" = "" ] + then + source addcontact-bml.sh +elif [ "$CONTATC_TYPE" = "2" ] + then + echo "${red}WORK IN PROGRESS${reset}" + source addcontact-menu.sh +elif [ "$CONTATC_TYPE" = "3" ] + then + echo "${red}WORK IN PROGRESS${reset}" + source addcontact-manu.sh +elif [ "$CONTATC_TYPE" = "4" ] + then + echo "${red}WORK IN PROGRESS${reset}" + source addcontact-manu.sh +elif [ "$CONTATC_TYPE" = "5" ] + then + source contactsmenu.sh +elif [ "$CONTATC_TYPE" = "6" ] + then + rm $COOKIE + exit +else + clear + echo "${red}There was an error${reset}" 1>&2 + source contactsmenu.sh +fi diff --git a/contactsmenu.sh b/contactsmenu.sh old mode 100755 new mode 100644 index 3415b08..773ec28 --- a/contactsmenu.sh +++ b/contactsmenu.sh @@ -12,10 +12,10 @@ read -r CONTATCS if [ "$CONTATCS" = "1" ] then - source listcontact.sh + source listcontacts.sh elif [ "$CONTATCS" = "2" ] then - source addcontact.sh + source addcontact-menu.sh elif [ "$CONTATCS" = "3" ] then source delete contact.sh @@ -25,9 +25,10 @@ elif [ "$CONTATCS" = "4" ] elif [ "$CONTATCS" = "5" ] then rm $COOKIE + echo "Cleaning up.." exit else - echo "${red}There was an error${reset}" 1>&2 clear + echo "${red}There was an error${reset}" 1>&2 source contactsmenu.sh fi diff --git a/listcontacts.sh b/listcontacts.sh new file mode 100644 index 0000000..f517801 --- /dev/null +++ b/listcontacts.sh @@ -0,0 +1,3 @@ +curl -s -b $COOKIE $BML_URL/contacts \ +| jq -r '["Account Number","Currency","Account Name","Contact Name"], ["==================================================================="], (.["payload"] | .[] | [.account, .currency, .name, .alias]) | @tsv' +source contactsmenu.sh diff --git a/mainmenu.sh b/mainmenu.sh old mode 100755 new mode 100644 diff --git a/parser_json_test.sh b/parser_json_test.sh old mode 100755 new mode 100644 index 6513eab..538b04d --- a/parser_json_test.sh +++ b/parser_json_test.sh @@ -10,9 +10,9 @@ curl -s -c $COOKIE $BML_URL/login \ --compressed > /dev/null curl -s -b $COOKIE $BML_URL/profile > /dev/null -curl -s -b $COOKIE $BML_URL/contacts | jq -r '["Account Number","Currency","Account Name","Contact Name"], ["==================================================================="], (.["payload"] | .[] | [.account, .currency, .name, .alias]) | @tsv' +#curl -s -b $COOKIE $BML_URL/contacts | jq -r '["Account Number","Currency","Account Name","Contact Name"], ["==================================================================="], (.["payload"] | .[] | [.account, .currency, .name, .alias]) | @tsv' #get this to render nicely in a table, similar to contacts #curl -s -b $COOKIE $BML_URL/dashboard -curl -s -b $COOKIE $BML_URL/api/validate/account/7730000359348 +curl -s -b $COOKIE $BML_URL/api/validate/account/7701134192101