diff --git a/CHANGELOG.md b/CHANGELOG.md index 3167883..bfd95aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ Given a version number MAJOR.MINOR.PATCH, increment: ## [Unreleased] +### Added +- Statistic sub-resource ## [0.11.0] - 2024-03-19 ### Added diff --git a/requirements.txt b/requirements.txt index fbe00ac..5997bde 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -starkcore==0.1.1 \ No newline at end of file +starkcore==0.3.2 \ No newline at end of file diff --git a/starkinfra/pixuser/__pixuser.py b/starkinfra/pixuser/__pixuser.py index 9d0a090..dc3df0a 100644 --- a/starkinfra/pixuser/__pixuser.py +++ b/starkinfra/pixuser/__pixuser.py @@ -1,5 +1,9 @@ from ..utils import rest from starkcore.utils.resource import Resource +from starkcore.utils.api import from_api_json +from .statistic.__statistic import Statistic +from .statistic.__statistic import _sub_resource as _statistic_resource + class PixUser(Resource): @@ -14,7 +18,19 @@ class PixUser(Resource): def __init__(self, id, statistics=None): Resource.__init__(self, id=id) - self.statistics = statistics + self.statistics = _parse_statistic(statistics) + + +def _parse_statistic(statistics): + if statistics is None: + return None + parsed_statistics = [] + for statistic in statistics: + if isinstance(statistic, Statistic): + parsed_statistics.append(statistic) + continue + parsed_statistics.append(from_api_json(_statistic_resource, statistic)) + return parsed_statistics _resource = {"class": PixUser, "name": "PixUser"} diff --git a/starkinfra/pixuser/statistic/__init__.py b/starkinfra/pixuser/statistic/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/starkinfra/pixuser/statistic/__statistic.py b/starkinfra/pixuser/statistic/__statistic.py new file mode 100644 index 0000000..0aaa05e --- /dev/null +++ b/starkinfra/pixuser/statistic/__statistic.py @@ -0,0 +1,23 @@ +from starkcore.utils.subresource import SubResource + + +class Statistic(SubResource): + """# PixUser.Statistic object + The PixUser.Statistic object modifies the behavior of Invoice objects when passed as an argument upon their creation. + ## Parameters (required): + - after [datetime.datetime]: start date filter for the first element count of this element. ex: datetime.datetime(2020, 3, 10, 10, 30, 0, 0) + - source [string]: source of the statistic. ex: "pix-key", "pix-request", "pix-fraud", "pix-infraction"... + - type [string]: type of the statistic source. ex: "registered", "settled", "scam", "mule", "amount", "open", "denied" + - updated [datetime.datetime]: latest update datetime for the Statistic object. ex: datetime.datetime(2020, 3, 10, 10, 30, 0, 0) + - value [integer]: Entity tyoe counter between after and updated. ex: 1234 + """ + + def __init__(self, after, source, type, updated, value): + self.after = after + self.source = source + self.type = type + self.updated = updated + self.value = value + + +_sub_resource = {"class": Statistic, "name": "Statistic"}