diff --git a/unit/__init__.py b/unit/__init__.py index 8c40448..371846c 100644 --- a/unit/__init__.py +++ b/unit/__init__.py @@ -28,6 +28,7 @@ from unit.api.reward_resource import RewardResource from unit.api.dispute_resource import DisputeResource from unit.api.received_payment_resource import ReceivedPaymentResource +from unit.api.check_registered_address import CheckRegisteredAddressResource __all__ = ["api", "models", "utils"] @@ -64,3 +65,4 @@ def __init__(self, api_url, token): self.check_stop_payments = CheckStopPaymentResource(api_url, token) self.disputes = DisputeResource(api_url, token) self.received_payments = ReceivedPaymentResource(api_url, token) + self.check_registered_address = CheckRegisteredAddressResource(api_url, token) diff --git a/unit/api/check_registered_address.py b/unit/api/check_registered_address.py new file mode 100644 index 0000000..b6ae299 --- /dev/null +++ b/unit/api/check_registered_address.py @@ -0,0 +1,21 @@ +from unit.api.base_resource import BaseResource +from unit.models import * +from unit.models.check_registered_address import CheckRegisteredAddressRequest, CheckRegisteredAddressResponse +from unit.models.codecs import DtoDecoder + + +class CheckRegisteredAddressResource(BaseResource): + def __init__(self, api_url, token): + super().__init__(api_url, token) + self.resource = "applications/check-registered-agent-address" + + def create(self, request: CheckRegisteredAddressRequest) -> Union[UnitResponse[CheckRegisteredAddressResponse], UnitError]: + payload = request.to_json_api() + response = super().post(self.resource, payload) + + if response.ok: + data = response.json().get("data") + return UnitResponse[CheckRegisteredAddressResponse](DtoDecoder.decode(data), None) + else: + return UnitError.from_json_api(response.json()) + diff --git a/unit/models/check_registered_address.py b/unit/models/check_registered_address.py new file mode 100644 index 0000000..6862a4c --- /dev/null +++ b/unit/models/check_registered_address.py @@ -0,0 +1,55 @@ +from unit.models import * + + + +class CheckRegisteredAddressRequest(UnitRequest): + def __init__( + self, + street: str, + city: str, + state: str, + postal_code: str, + country: str, + street2: Optional[str] = None, + ): + self.type = "checkRegisteredAgentAddress" + + self.attributes = { + "address": { + "street": street, + "city": city, + "state": state, + "postalCode": postal_code, + "country": country, + } + } + + if street2: + self.attributes["address"]["street2"] = street2 + + def to_json_api(self) -> Dict: + payload = { + "data": { + "type": self.type, + "attributes": self.attributes, + } + } + return payload + + +class CheckRegisteredAddressResponse(UnitDTO): + def __init__( + self, + is_registered_agent_address: bool, + ): + self.type = "checkRegisteredAgentAddress" + self.is_registered_agent_address = is_registered_agent_address + self.attributes = { + "isRegisteredAgentAddress": is_registered_agent_address, + } + + @staticmethod + def from_json_api(_id, _type, attributes, relationships): + return CheckRegisteredAddressResponse( + attributes.get("isRegisteredAgentAddress"), + )