Spaces:
Running
Running
File size: 1,511 Bytes
a0e37e2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
from ask_candid.base.api_base import BaseAPI
from ask_candid.base.config.rest import CDS_API
class OrgSearch(BaseAPI):
def __init__(self):
super().__init__(
url=f"{CDS_API['url']}/v1/organization/search",
headers={"x-api-key": CDS_API["key"]}
)
def __call__(self, name: str, name_only: bool = False, **kwargs):
is_valid = False
payload = {
"names": [{
"value": name,
"type": "main"
}],
"status": "authorized"
}
if name_only:
is_valid = True
else:
if kwargs.get("ein"):
ein = kwargs.get("ein")
if "-" not in ein:
ein = f"{ein[:2]}-{ein[2:]}"
payload["ids"] = [{
"value": ein,
"type": "ein"
}]
is_valid = True
if kwargs.get("street") or kwargs.get("city") or kwargs.get("state") or kwargs.get("postal_code"):
payload["addresses"] = [{
"street1": kwargs.get("street") or "",
"city": kwargs.get("city") or "",
"state": kwargs.get("state") or "",
"postal_code": kwargs.get("postal_code") or ""
}]
is_valid = True
if not is_valid:
return None
result = self.post(payload=payload)
return result.get("payload", [])
|