diff --git a/pyproject.toml b/pyproject.toml index 90039ee..63a0ffd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "simplefin4py" -version = "0.0.9" +version = "0.0.10" description = "" authors = ["Jeef "] readme = "README.md" diff --git a/simplefin4py/simplefin.py b/simplefin4py/simplefin.py index b1ab149..8094b74 100644 --- a/simplefin4py/simplefin.py +++ b/simplefin4py/simplefin.py @@ -27,17 +27,32 @@ class SimpleFin: """SimpleFin Class.""" - # proxy: str | None + @classmethod + def decode_claim_token(cls, token_string: str) -> str: + """Decode a claim token string - or throws an error.""" + try: + claim_url = base64.b64decode(token_string).decode("utf-8") + except binascii.Error as err: + raise SimpleFinInvalidClaimTokenError from err + return claim_url + + @classmethod + def decode_access_url(cls, access_url: str) -> tuple[str, str, str]: + """Decode an access URL string - or throws an error.""" + try: + scheme, rest = access_url.split("//", 1) + auth, rest = rest.split("@", 1) + except ValueError as err: + raise SimpleFinInvalidAccountURLError from err + + return scheme, rest, auth @classmethod async def claim_setup_token( cls, setup_token: str, verify_ssl: bool = True, proxy: str | None = None ) -> str: """Exchanges a 1-time setup token for an access token.""" - try: - claim_url = base64.b64decode(setup_token).decode("utf-8") - except binascii.Error as err: - raise SimpleFinInvalidClaimTokenError from err + claim_url = cls.decode_claim_token(setup_token) auth = BasicAuth( login="", password="" @@ -65,11 +80,12 @@ def __init__( self.access_url = access_url self.verify_ssl = verify_ssl - scheme, rest = access_url.split("//", 1) - try: - self.auth, rest = rest.split("@", 1) - except ValueError as err: - raise SimpleFinInvalidAccountURLError from err + scheme, rest, self.auth = self.decode_access_url(access_url) + # try: + # scheme, rest = access_url.split("//", 1) + # self.auth, rest = rest.split("@", 1) + # except ValueError as err: + # raise SimpleFinInvalidAccountURLError from err self.url = scheme + "//" + rest + "/accounts" self.username, self.password = self.auth.split(":", 1) self.proxy: str | None = proxy