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: 2 additions & 0 deletions unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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)
21 changes: 21 additions & 0 deletions unit/api/check_registered_address.py
Original file line number Diff line number Diff line change
@@ -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())

55 changes: 55 additions & 0 deletions unit/models/check_registered_address.py
Original file line number Diff line number Diff line change
@@ -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"),
)
Loading