File tree Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Original file line number Diff line number Diff line change 1
1
from typing import Optional
2
2
from ..nocodb import (
3
+ JWTAuthToken ,
3
4
NocoDBClient ,
4
5
NocoDBProject ,
5
6
AuthToken ,
12
13
13
14
14
15
class NocoDBRequestsClient (NocoDBClient ):
15
- def __init__ (self , auth_token : AuthToken , base_uri : str ):
16
+ def __init__ (
17
+ self ,
18
+ base_uri : str ,
19
+ auth_token : AuthToken = None ,
20
+ email : str = None ,
21
+ password : str = None ,
22
+ ):
16
23
self .__session = requests .Session ()
24
+ self .__api_info = NocoDBAPI (base_uri )
25
+
26
+ if not auth_token and not (email and password ):
27
+ raise ValueError ("Either сredentials or token must be provided" )
28
+
29
+ if not auth_token and (email and password ):
30
+ auth_token = JWTAuthToken (self .get_auth_token (email , password ))
31
+
17
32
self .__session .headers .update (
18
- auth_token .get_header (),
19
- )
33
+ auth_token .get_header (),
34
+ )
20
35
self .__session .headers .update ({"Content-Type" : "application/json" })
21
- self .__api_info = NocoDBAPI (base_uri )
36
+
37
+ def get_auth_token (self , email : str , password : str ) -> str :
38
+ auth_token = self .__session .post (
39
+ self .__api_info .get_auth_uri (),
40
+ json = dict (email = email , password = password )
41
+ ).json ()['token' ]
42
+ return auth_token
22
43
23
44
def table_row_list (
24
45
self ,
You can’t perform that action at this time.
0 commit comments