@@ -46,7 +46,7 @@ class PySendPulse:
46
46
MEMCACHED_VALUE_TIMEOUT = 3600
47
47
ALLOWED_STORAGE_TYPES = ['FILE' , 'MEMCACHED' ]
48
48
49
- def __init__ (self , user_id , secret , storage_type = "FILE" , memcached_host = "127.0.0.1:11211" ):
49
+ def __init__ (self , user_id , secret , storage_type = "FILE" , token_file_path = "" , memcached_host = "127.0.0.1:11211" ):
50
50
""" SendPulse API constructor
51
51
52
52
@param user_id: string REST API ID from SendPulse settings
@@ -62,6 +62,7 @@ def __init__(self, user_id, secret, storage_type="FILE", memcached_host="127.0.0
62
62
self .__user_id = user_id
63
63
self .__secret = secret
64
64
self .__storage_type = storage_type .upper ()
65
+ self .__token_file_path = token_file_path
65
66
self .__memcached_host = memcached_host
66
67
m = md5 ()
67
68
m .update ("{}::{}" .format (user_id , secret ).encode ('utf-8' ))
@@ -110,6 +111,9 @@ def __get_token(self):
110
111
else :
111
112
filepath = "{}{}" .format (self .__token_file_path , self .__token_hash_name )
112
113
try :
114
+ if not os .path .isdir (self .__token_file_path ):
115
+ os .makedirs (self .__token_file_path , exist_ok = True )
116
+
113
117
with open (filepath , 'w' ) as f :
114
118
f .write (self .__token )
115
119
logger .debug ("Set token '{}' into 'FILE' '{}'" .format (self .__token , filepath ))
0 commit comments