Skip to content

Commit 2620488

Browse files
committed
feat: added all of routes to client + some changes on how request is send + added make_url function to utils
1 parent fccdd68 commit 2620488

23 files changed

+385
-39
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from zohal_sdk import Client
2+
from os import getenv
3+
4+
token = getenv("TOKEN")
5+
client = Client(token)
6+
7+
matched = client.check_card_with_national_code(
8+
"0123456789",
9+
"1900/1/1",
10+
"1234123412341234"
11+
)
12+
13+
print(matched.response_body.data.matched)

zohal_sdk/client.py

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
""" Zohal RestAPI Client """
2-
from typing import Optional, Union
2+
from typing import Union
3+
import io
4+
from .types import RequestData
35
import logging
46

57
from requests import Session
68
from requests.exceptions import (Timeout, HTTPError as RHTTPError,
79
JSONDecodeError)
810

9-
from .types import RequestData, ResponseData
10-
from .types.national_identity import NationalIdentity
11-
from .types.shahkar import Shahkar
12-
13-
from .models.shahkar import ShahkarRequest
14-
from .models.national_identity_inquery import NationalIdentityInqueryRequest
1511
from .exceptions import HTTPError, TimeoutError, ZohalError
12+
from .services import InquiryMixin
1613

1714
logger = logging.getLogger(__name__)
1815

19-
BASE_URL = "https://service.zohal.io/api"
20-
2116

22-
class Client:
17+
class Client(InquiryMixin):
2318

2419
def __init__(self, token: str):
2520
if token is None:
@@ -29,17 +24,22 @@ def __init__(self, token: str):
2924
self.session = Session()
3025
self.session.headers['Authorization'] = f'Bearer {self.token}'
3126

32-
def _request(self,
33-
url: str,
34-
data: Union[RequestData, dict, None] = None,
35-
method: str = "GET"):
27+
def request(self,
28+
url: str,
29+
data: Union[RequestData, dict, None] = None,
30+
files=None,
31+
method: str = "GET"):
3632
logger.debug(f"request to {url=} with {method=}")
3733
try:
3834
kwargs = {"url": url, "method": method}
3935
if method in ["POST", "PUT", "PATCH"] and isinstance(
4036
data, RequestData):
41-
data = data.to_dict()
42-
kwargs['json'] = data
37+
if data:
38+
data = data.to_dict()
39+
kwargs['json'] = data
40+
41+
if files:
42+
kwargs['files'] = files
4343

4444
response = self.session.request(**kwargs)
4545
logger.debug(
@@ -63,23 +63,3 @@ def _request(self,
6363
f"raised error while loads json data {e.response.status_code} cause {e.response.text}"
6464
)
6565
raise e
66-
67-
def national_identity_inquiry(self,
68-
national_code: str,
69-
birth_date: str,
70-
gender: Optional[bool] = None):
71-
data = NationalIdentityInqueryRequest(national_code=national_code,
72-
birth_date=birth_date,
73-
gender=gender)
74-
response = self._request(
75-
f"{BASE_URL}/v0/services/inquiry/national_identity_inquiry",
76-
data,
77-
method="POST")
78-
return ResponseData.serialize(NationalIdentity, response)
79-
80-
def shahkar(self, national_code: str, mobile: str):
81-
data = ShahkarRequest(national_code=national_code, mobile=mobile)
82-
response = self._request(f"{BASE_URL}/v0/services/inquiry/shahkar",
83-
data,
84-
method="POST")
85-
return ResponseData.serialize(Shahkar, response)

zohal_sdk/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BASE_URL = "https://service.zohal.io/api"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from dataclasses import dataclass
2+
from dataclasses_json import dataclass_json
3+
from ..types import RequestData
4+
from ..types.bank import BankCode
5+
6+
7+
@dataclass_json
8+
@dataclass
9+
class AccountToIBANRequest(RequestData):
10+
bank_account: str
11+
bank_code: BankCode

zohal_sdk/models/card_inquiry.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from dataclasses import dataclass
2+
from dataclasses_json import dataclass_json
3+
from ..types import RequestData
4+
5+
6+
@dataclass_json
7+
@dataclass
8+
class CardInquiryRequest(RequestData):
9+
card_number: str
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from dataclasses import dataclass
2+
from dataclasses_json import dataclass_json
3+
4+
from ..types import RequestData
5+
6+
7+
@dataclass_json
8+
@dataclass
9+
class CardToAccountRequest(RequestData):
10+
card_number: str

zohal_sdk/models/card_to_iban.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ..types import RequestData
2+
from dataclasses_json import dataclass_json
3+
from dataclasses import dataclass
4+
5+
6+
@dataclass_json
7+
@dataclass
8+
class CardToIBANRequest(RequestData):
9+
card_number: str
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from dataclasses import dataclass
2+
from dataclasses_json import dataclass_json
3+
4+
from ..types import RequestData
5+
6+
7+
@dataclass_json
8+
@dataclass
9+
class CheckCardWithNameRequest(RequestData):
10+
card_number: str
11+
name: str
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from dataclasses import dataclass
2+
from dataclasses_json import dataclass_json
3+
4+
from ..types import RequestData
5+
6+
7+
@dataclass_json
8+
@dataclass
9+
class CheckCardWithNationalCodeRequest(RequestData):
10+
national_code: str
11+
birth_date: str
12+
card_number: str
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from dataclasses import dataclass
2+
from dataclasses_json import dataclass_json
3+
4+
from ..types import RequestData
5+
6+
7+
@dataclass_json
8+
@dataclass
9+
class CheckIBANWithNameRequest (RequestData):
10+
IBAN: str
11+
name: str

0 commit comments

Comments
 (0)