Skip to content

Commit

Permalink
Merge pull request #2 from dnbasta/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dnbasta authored Apr 13, 2024
2 parents 73b37fb + e247d39 commit f7fb1ea
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ ynab_api_import.compare_balances()
```
### Delete current bank authorization
By default you can create only one bank authorization per reference. If you need to replace the authorization under
your current reference you can explicitly do that by setting the `delete_current_auth` option when creating and auth
your current reference you can explicitly do that by setting the `delete_current_auth` option when creating an auth
link.
```py
ynab_api_import.create_auth_link(institution_id='<institution_id>', delete_current_auth=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ynabapiimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from ynabapiimport import YnabApiImport
from ynabapiimport.exceptions import BalancesDontMatchError
from ynabapiimport.models.exceptions import BalancesDontMatchError


@patch('ynabapiimport.ynabapiimport.AccountClient')
Expand Down
3 changes: 0 additions & 3 deletions ynabapiimport/exceptions.py

This file was deleted.

4 changes: 4 additions & 0 deletions ynabapiimport/models/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ class ReferenceNotUnique(Exception):

class ReferenceNotValid(Exception):
pass


class BalancesDontMatchError(Exception):
pass
25 changes: 21 additions & 4 deletions ynabapiimport/ynabapiimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import yaml
from nordigen import NordigenClient

from ynabapiimport.exceptions import BalancesDontMatchError
from ynabapiimport.models.exceptions import BalancesDontMatchError
from ynabapiimport.requisitionhandler import RequisitionHandler
from ynabapiimport.accountclient import AccountClient
from ynabapiimport.memocleaner import MemoCleaner
Expand All @@ -16,13 +16,28 @@
class YnabApiImport:
"""
Class which allows to connect to bank accounts via GoCardless API and import transactions into YNAB
:ivar reference: self chosen reference string to identify connection in GoCardless
:ivar resource_id: GoCardless resource id to specify accounts in case multiple are available
:ivar logger: Logger object which receives info messages from methods
"""

def __init__(self, secret_id: str, secret_key: str, token: str,
reference: str, budget_id: str, account_id: str, resource_id: str = None) -> None:
"""
:param secret_id: Secret id from GoCardless
:param secret_key: Secret Key from GoCardless
:param token: YNAB token
:param reference: self chosen reference string to identify connection in GoCardless
:param budget_id: YNAB budget id
:param account_id: YNAB account id
:param resource_id: GoCardless resource id to specify accounts in case multiple are available
:raises NoRequisitionError: if GoCardless connection is not valid
:raises NoAccountError: if no account is available in authorized GoCardless connection
:raises MultipleAccountsError: if multiple accounts are available in authorized GoCardless connection
"""
self.logger = self._set_up_logger()
self._reference = reference
self._resource_id = resource_id
self.reference = reference
self.resource_id = resource_id
self._ynab_client = YnabClient(token=token, account_id=account_id, budget_id=budget_id)
self._api_client = NordigenClient(secret_id=secret_id, secret_key=secret_key)
self._api_client.generate_token()
Expand Down Expand Up @@ -88,9 +103,11 @@ def create_auth_link(self, institution_id: str, use_max_historical_days: bool =
"""
Creates a link to authenticate access to specified bank through GoCardless. Link needs to be used in browser
:param institution_id: Gocardless id for your bank
:param use_max_historical_days: If set to True will create an auth link for the max_days specified in history for the bank
:param use_max_historical_days: If set to True will create an auth link for the max_days specified in history for the bank (might cause a 500 error with API if bank doesn't support for any reason)
:param delete_current_auth: if set to True will delete currently active auth
:return: Link to authenticate access to bank through Gocardless
:raises ReferenceNotValidError: if reference string contains illegal characters
:raises ReferenceNotUniqueError: if existing connection already uses the reference
"""
rh = RequisitionHandler(client=self._api_client, reference=self._reference)
if delete_current_auth:
Expand Down

0 comments on commit f7fb1ea

Please sign in to comment.