2
2
_api.py
3
3
"""
4
4
5
- from typing import Any , Callable
5
+ from typing import Any , Callable , Optional
6
6
7
7
from httpx ._types import HeaderTypes
8
8
9
9
from ._abc import Api
10
10
from ._request import HttpClient , make_request , make_request_function
11
- from ._types import ApiFunc , Entity , ReturnEntity
11
+ from ._types import ApiFunc , Entity , HookFunc , ReturnEntity , SerializeFunc
12
12
13
13
14
14
class Apy (Api ):
15
15
"""
16
16
Apy class
17
17
"""
18
18
19
- def __init__ (self , host : str , headers : HeaderTypes ) -> None :
19
+ def __init__ (
20
+ self ,
21
+ host : str ,
22
+ headers : HeaderTypes ,
23
+ hook_func : Optional [HookFunc ] = None ,
24
+ serialize_func : Optional [SerializeFunc ] = None ,
25
+ ) -> None :
26
+ self .hook_func = hook_func if hook_func else None
27
+ self .serialize_func = serialize_func if serialize_func else None
20
28
self .http_client = HttpClient (base_url = host , headers = headers )
21
29
22
30
def get (self , path : str ) -> Callable [[ApiFunc ], ReturnEntity ]:
23
- return make_request (path , self .http_client .get_request )
31
+ return make_request (
32
+ path , self .http_client .get_request , self .hook_func , self .serialize_func
33
+ )
24
34
25
35
def post (self , path : str ) -> Callable [[ApiFunc ], ReturnEntity ]:
26
- return make_request (path , self .http_client .post_request )
36
+ return make_request (
37
+ path , self .http_client .post_request , self .hook_func , self .serialize_func
38
+ )
27
39
28
40
def put (self , path : str ) -> Callable [[ApiFunc ], ReturnEntity ]:
29
- return make_request (path , self .http_client .put_request )
41
+ return make_request (
42
+ path , self .http_client .put_request , self .hook_func , self .serialize_func
43
+ )
30
44
31
45
def delete (self , path : str ) -> Callable [[ApiFunc ], ReturnEntity ]:
32
- return make_request (path , self .http_client .delete_request )
46
+ return make_request (
47
+ path , self .http_client .delete_request , self .hook_func , self .serialize_func
48
+ )
33
49
34
50
def patch (self , path : str ) -> Callable [[ApiFunc ], ReturnEntity ]:
35
- return make_request (path , self .http_client .patch_request )
51
+ return make_request (
52
+ path , self .http_client .patch_request , self .hook_func , self .serialize_func
53
+ )
36
54
37
55
38
56
def get (path : str ) -> Callable [[ApiFunc ], ReturnEntity ]:
39
57
def _get (func : ApiFunc ) -> ReturnEntity :
40
58
def wrapper (self : Apy , * args : Any , ** kwargs : Any ) -> Entity :
41
59
return make_request_function (func , self , * args , ** kwargs )(
42
- path , self .http_client .get_request
60
+ path , self .http_client .get_request , self . hook_func , self . serialize_func
43
61
)
44
62
45
63
return wrapper
@@ -51,7 +69,7 @@ def post(path: str) -> Callable[[ApiFunc], ReturnEntity]:
51
69
def _post (func : ApiFunc ) -> ReturnEntity :
52
70
def wrapper (self : Apy , * args : Any , ** kwargs : Any ) -> Entity :
53
71
return make_request_function (func , self , * args , ** kwargs )(
54
- path , self .http_client .post_request
72
+ path , self .http_client .post_request , self . hook_func , self . serialize_func
55
73
)
56
74
57
75
return wrapper
@@ -63,7 +81,7 @@ def put(path: str) -> Callable[[ApiFunc], ReturnEntity]:
63
81
def _put (func : ApiFunc ) -> ReturnEntity :
64
82
def wrapper (self : Apy , * args : Any , ** kwargs : Any ) -> Entity :
65
83
return make_request_function (func , self , * args , ** kwargs )(
66
- path , self .http_client .put_request
84
+ path , self .http_client .put_request , self . hook_func , self . serialize_func
67
85
)
68
86
69
87
return wrapper
@@ -75,7 +93,10 @@ def delete(path: str) -> Callable[[ApiFunc], ReturnEntity]:
75
93
def _delete (func : ApiFunc ) -> ReturnEntity :
76
94
def wrapper (self : Apy , * args : Any , ** kwargs : Any ) -> Entity :
77
95
return make_request_function (func , self , * args , ** kwargs )(
78
- path , self .http_client .delete_request
96
+ path ,
97
+ self .http_client .delete_request ,
98
+ self .hook_func ,
99
+ self .serialize_func ,
79
100
)
80
101
81
102
return wrapper
@@ -87,7 +108,10 @@ def patch(path: str) -> Callable[[ApiFunc], ReturnEntity]:
87
108
def _patch (func : ApiFunc ) -> ReturnEntity :
88
109
def wrapper (self : Apy , * args : Any , ** kwargs : Any ) -> Entity :
89
110
return make_request_function (func , self , * args , ** kwargs )(
90
- path , self .http_client .patch_request
111
+ path ,
112
+ self .http_client .patch_request ,
113
+ self .hook_func ,
114
+ self .serialize_func ,
91
115
)
92
116
93
117
return wrapper
0 commit comments