66
77class Client :
88
9- def __init__ (self , api_key ):
9+ def __init__ (self , api_key = None ):
1010 self .api_key = api_key
1111 self .base_url = 'https://api.emailable.com/v1/'
1212
13- def verify (self , email , smtp = True , accept_all = False , timeout = None ):
13+ def verify (self ,
14+ email ,
15+ smtp = True ,
16+ accept_all = False ,
17+ timeout = None ,
18+ api_key = None ,
19+ access_token = None ):
1420 options = {
1521 'params' : {
16- 'api_key' : self .api_key ,
1722 'email' : email ,
1823 'smtp' : str (smtp ).lower (),
1924 'accept_all' : str (accept_all ).lower (),
@@ -22,45 +27,44 @@ def verify(self, email, smtp=True, accept_all=False, timeout=None):
2227 }
2328
2429 url = self .base_url + 'verify'
25- return self .__request ('get' , url , options )
30+ return self .__request ('get' , url , options , api_key or access_token )
2631
27- def batch (self , emails , params = {}):
32+ def batch (self , emails , params = {}, api_key = None , access_token = None ):
2833 options = {
2934 'params' : {
30- ** {'api_key' : self .api_key },
3135 ** params
3236 },
3337 'json' : {
3438 'emails' : emails
3539 }
3640 }
3741 url = self .base_url + 'batch'
38- return self .__request ('post' , url , options )
42+ return self .__request ('post' , url , options , api_key or access_token )
3943
40- def batch_status (self , batch_id , simulate = None ):
44+ def batch_status (self ,
45+ batch_id ,
46+ simulate = None ,
47+ api_key = None ,
48+ access_token = None ):
4149 options = {
4250 'params' : {
43- 'api_key' : self .api_key ,
4451 'id' : batch_id ,
4552 'simulate' : simulate
4653 }
4754 }
4855
4956 url = self .base_url + 'batch'
50- return self .__request ('get' , url , options )
51-
52- def account (self ):
53- options = {
54- 'params' : {
55- 'api_key' : self .api_key
56- }
57- }
57+ return self .__request ('get' , url , options , api_key or access_token )
5858
59+ def account (self , api_key = None , access_token = None ):
5960 url = self .base_url + 'account'
60- return self .__request ('get' , url , options )
61+ return self .__request ('get' , url , {}, api_key or access_token )
6162
62- def __request (self , method , url , options ):
63+ def __request (self , method , url , options , key_or_token ):
6364 response = None
65+ options ['headers' ] = {
66+ 'Authorization' : f'Bearer { key_or_token or self .api_key } '
67+ }
6468 try :
6569 response = requests .request (method , url , ** options )
6670 response .raise_for_status ()
0 commit comments