Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
jobs:
build:

runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion ntropy_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "5.1.3"
__version__ = "5.2.0"

from typing import TYPE_CHECKING, Optional

Expand Down
8 changes: 8 additions & 0 deletions ntropy_sdk/account_holders.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class AccountHolderCreate(BaseModel):
default=None,
description="The name of the account holder",
)
category_id: Optional[str] = Field(
default=None,
description="The Categories ID that will be used for this account holder's transactions",
)
request_id: Optional[str] = None


Expand Down Expand Up @@ -107,6 +111,7 @@ def create(
id: str,
type: Union[AccountHolderType, str],
name: Optional[str] = None,
category_id: Optional[str] = None,
**extra_kwargs: "Unpack[ExtraKwargs]",
) -> AccountHolderResponse:
"""Create an account holder"""
Expand All @@ -123,6 +128,7 @@ def create(
id=id,
type=type,
name=name,
category_id=category_id,
)
),
**extra_kwargs,
Expand Down Expand Up @@ -231,6 +237,7 @@ async def create(
id: str,
type: Union[AccountHolderType, str],
name: Optional[str] = None,
category_id: Optional[str] = None,
**extra_kwargs: "Unpack[ExtraKwargsAsync]",
) -> AccountHolderResponse:
"""Create an account holder"""
Expand All @@ -247,6 +254,7 @@ async def create(
id=id,
type=type,
name=name,
category_id=category_id,
)
),
**extra_kwargs,
Expand Down
72 changes: 47 additions & 25 deletions ntropy_sdk/categories.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from typing import TYPE_CHECKING, Union
import uuid

Expand All @@ -6,7 +7,12 @@
if TYPE_CHECKING:
from ntropy_sdk import ExtraKwargs, ExtraKwargsAsync, SDK
from ntropy_sdk.async_.sdk import AsyncSDK
from typing_extensions import Unpack
from typing_extensions import Unpack, deprecated
elif sys.version_info >= (3, 13):
from warnings import deprecated
else:
def deprecated(msg):
return lambda f: f


class CategoriesResource:
Expand All @@ -15,56 +21,64 @@ def __init__(self, sdk: "SDK"):

def get(
self,
account_holder_type: Union[AccountHolderType, str],
category_id: Union[AccountHolderType, str],
**extra_kwargs: "Unpack[ExtraKwargs]",
) -> dict:
request_id = extra_kwargs.get("request_id")
if request_id is None:
request_id = uuid.uuid4().hex
extra_kwargs["request_id"] = request_id
if not isinstance(account_holder_type, AccountHolderType):
account_holder_type = AccountHolderType(account_holder_type)
if isinstance(category_id, AccountHolderType):
category_id = category_id.value
resp = self._sdk.retry_ratelimited_request(
method="GET",
url=f"/v3/categories/{account_holder_type.value}",
url=f"/v3/categories/{category_id}",
**extra_kwargs,
)
return resp.json()

def set(
self,
account_holder_type: Union[AccountHolderType, str],
category_id: Union[AccountHolderType, str],
categories: dict,
**extra_kwargs: "Unpack[ExtraKwargs]",
):
request_id = extra_kwargs.get("request_id")
if request_id is None:
request_id = uuid.uuid4().hex
extra_kwargs["request_id"] = request_id
if not isinstance(account_holder_type, AccountHolderType):
account_holder_type = AccountHolderType(account_holder_type)
if isinstance(category_id, AccountHolderType):
category_id = category_id.value
resp = self._sdk.retry_ratelimited_request(
method="POST",
url=f"/v3/categories/{account_holder_type.value}",
url=f"/v3/categories/{category_id}",
payload=categories,
**extra_kwargs,
)
return resp.json()

@deprecated("Use the delete method instead")
def reset(
self,
account_holder_type: Union[AccountHolderType, str],
category_id: Union[AccountHolderType, str],
**extra_kwargs: "Unpack[ExtraKwargs]",
):
return self.delete(category_id, **extra_kwargs)

def delete(
self,
category_id: Union[AccountHolderType, str],
**extra_kwargs: "Unpack[ExtraKwargs]",
):
request_id = extra_kwargs.get("request_id")
if request_id is None:
request_id = uuid.uuid4().hex
extra_kwargs["request_id"] = request_id
if not isinstance(account_holder_type, AccountHolderType):
account_holder_type = AccountHolderType(account_holder_type)
if isinstance(category_id, AccountHolderType):
category_id = category_id.value
resp = self._sdk.retry_ratelimited_request(
method="POST",
url=f"/v3/categories/{account_holder_type.value}/reset",
url=f"/v3/categories/{category_id}/reset",
**extra_kwargs,
)
return resp.json()
Expand All @@ -76,58 +90,66 @@ def __init__(self, sdk: "AsyncSDK"):

async def get(
self,
account_holder_type: Union[AccountHolderType, str],
category_id: Union[AccountHolderType, str],
**extra_kwargs: "Unpack[ExtraKwargsAsync]",
) -> dict:
request_id = extra_kwargs.get("request_id")
if request_id is None:
request_id = uuid.uuid4().hex
extra_kwargs["request_id"] = request_id
if not isinstance(account_holder_type, AccountHolderType):
account_holder_type = AccountHolderType(account_holder_type)
if isinstance(category_id, AccountHolderType):
category_id = category_id.value
resp = await self._sdk.retry_ratelimited_request(
method="GET",
url=f"/v3/categories/{account_holder_type.value}",
url=f"/v3/categories/{category_id}",
**extra_kwargs,
)
async with resp:
return await resp.json()

async def set(
self,
account_holder_type: Union[AccountHolderType, str],
category_id: Union[AccountHolderType, str],
categories: dict,
**extra_kwargs: "Unpack[ExtraKwargsAsync]",
):
request_id = extra_kwargs.get("request_id")
if request_id is None:
request_id = uuid.uuid4().hex
extra_kwargs["request_id"] = request_id
if not isinstance(account_holder_type, AccountHolderType):
account_holder_type = AccountHolderType(account_holder_type)
if isinstance(category_id, AccountHolderType):
category_id = category_id.value
resp = await self._sdk.retry_ratelimited_request(
method="POST",
url=f"/v3/categories/{account_holder_type.value}",
url=f"/v3/categories/{category_id}",
payload=categories,
**extra_kwargs,
)
async with resp:
return await resp.json()

@deprecated("Use the delete method instead")
async def reset(
self,
account_holder_type: Union[AccountHolderType, str],
category_id: Union[AccountHolderType, str],
**extra_kwargs: "Unpack[ExtraKwargsAsync]",
):
return await self.delete(category_id, **extra_kwargs)

async def delete(
self,
category_id: Union[AccountHolderType, str],
**extra_kwargs: "Unpack[ExtraKwargsAsync]",
):
request_id = extra_kwargs.get("request_id")
if request_id is None:
request_id = uuid.uuid4().hex
extra_kwargs["request_id"] = request_id
if not isinstance(account_holder_type, AccountHolderType):
account_holder_type = AccountHolderType(account_holder_type)
if isinstance(category_id, AccountHolderType):
category_id = category_id.value
resp = await self._sdk.retry_ratelimited_request(
method="POST",
url=f"/v3/categories/{account_holder_type.value}/reset",
url=f"/v3/categories/{category_id}/reset",
**extra_kwargs,
)
async with resp:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 5.1.3
current_version = 5.2.0
commit = True
tag = True
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(rc(?P<pre>\d+))?
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@
test_suite="tests",
tests_require=test_requirements,
url="https://github.com/ntropy-network/ntropy-sdk",
version="5.1.3",
version="5.2.0",
zip_safe=False,
)