Implemented "account del" action
This commit is contained in:
22
starling
22
starling
@@ -189,7 +189,12 @@ class StarlingClient:
|
||||
print(f'Response:')
|
||||
print(response.text)
|
||||
sys.exit(1)
|
||||
if response.status_code == 204: # No Content
|
||||
return None
|
||||
try:
|
||||
return json.loads(response.text, object_hook=lambda obj: types.SimpleNamespace(**obj))
|
||||
except:
|
||||
sys.exit(f'ERROR: failed to parse response:\n{response}')
|
||||
|
||||
def make_signature(self, method, url, date, digest):
|
||||
path = urllib.parse.urlparse(url).path
|
||||
@@ -349,6 +354,18 @@ class StarlingClient:
|
||||
print(f'Failed to create account: {response}')
|
||||
sys.exit(1)
|
||||
|
||||
def account_del(self, account_uid):
|
||||
payee_uid = self.get_payee_uid_from_account(account_uid)
|
||||
self.delete(f'payees/{payee_uid}/account/{account_uid}')
|
||||
print(f'Successfully deleted account {account_uid} for payee {payee_uid}')
|
||||
|
||||
def get_payee_uid_from_account(self, account_uid):
|
||||
for payee in self.payees().payees:
|
||||
for account in payee.accounts:
|
||||
if account.payeeAccountUid == account_uid:
|
||||
return payee.payeeUid
|
||||
sys.exit(f'ERROR: Can\'t find payee for account {account_uid}')
|
||||
|
||||
def pay(self, payee_uid, amount, ref):
|
||||
match = self.amount_re.match(amount)
|
||||
if match is None:
|
||||
@@ -408,7 +425,8 @@ parser = argparse.ArgumentParser(
|
||||
payees - list the customer's payees
|
||||
payee add - adds a new payee
|
||||
payee del <payee_uid> - deletes an existing payee
|
||||
account add <payee_uid> - adds a new account to a payee
|
||||
account add - adds a new account to a payee
|
||||
account del <account_uid> - removes an account from a payee
|
||||
pay <account_uid> <amount> <ref> - pay an existing payee
|
||||
''')
|
||||
parser.add_argument('action', help='which action to perform', nargs='*')
|
||||
@@ -455,7 +473,7 @@ elif action == 'account':
|
||||
parser.error(f'Too few arguments for "{action} {subaction}" action')
|
||||
if count > 2:
|
||||
parser.error(f'Too many arguments for "{action} {subaction}" action')
|
||||
client.account_del(*actuon_args)
|
||||
client.account_del(*action_args)
|
||||
else:
|
||||
parser.error(f'Unknown "{action} {subaction}" action')
|
||||
elif action == 'pay':
|
||||
|
||||
Reference in New Issue
Block a user