nylas/nylas-python

Refactor APIAccount / Account

Closed this issue · 1 comments

The difference between an APIAccount and an Account is a little confusing. This should be renamed to something similar to "AuthenticatedAccount" and "AccountManager".

One issues caused by this is that you're not able to filter on client.accounts to call the downgrade method. For example - this doesn't work:

client = APIClient(config.get("nylas", "app_id"), config.get("nylas", "app_secret"))
account = client.accounts.get(account_id)
account.downgrade()

Further, there is a collision on client.accounts - it can refer to two different authentication schemes to Nylas' API. Either that regular api.nylas.com, or the account management scopes api.nylas.com/a/. These should be distinct, something like client.manage_accounts and client.account

Right now, if someone wants to downgrade an account they must have a client with the authenticated account connected.

client = APIClient(config.get("nylas", "app_id"), config.get("nylas", "app_secret"), account["nylas_token"])
account_id_to_downgrade = client.account.id
client.revoke_token()
for account in client.accounts:
    if account.id == account_id_to_downgrade:
        account.downgrade()

Ideally, they'd be able to do something like this:

client = APIClient(config.get("nylas", "app_id"), config.get("nylas", "app_secret"))
account = client.manage_accounts.get(account["nylas_id"])
account.downgrade()

@pfista thanks for the suggestion -- we're tracking this internally and will be addressing it shortly.