Skip to content

Commit 68828cd

Browse files
iredunsendpulse
andauthored
Add custom token path (#21)
* Add token_file_path to init args * Auto create token_file_path Co-authored-by: SendPulse <[email protected]>
1 parent 2ecc1e0 commit 68828cd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pysendpulse/pysendpulse.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class PySendPulse:
4646
MEMCACHED_VALUE_TIMEOUT = 3600
4747
ALLOWED_STORAGE_TYPES = ['FILE', 'MEMCACHED']
4848

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"):
5050
""" SendPulse API constructor
5151
5252
@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
6262
self.__user_id = user_id
6363
self.__secret = secret
6464
self.__storage_type = storage_type.upper()
65+
self.__token_file_path = token_file_path
6566
self.__memcached_host = memcached_host
6667
m = md5()
6768
m.update("{}::{}".format(user_id, secret).encode('utf-8'))
@@ -110,6 +111,9 @@ def __get_token(self):
110111
else:
111112
filepath = "{}{}".format(self.__token_file_path, self.__token_hash_name)
112113
try:
114+
if not os.path.isdir(self.__token_file_path):
115+
os.makedirs(self.__token_file_path, exist_ok=True)
116+
113117
with open(filepath, 'w') as f:
114118
f.write(self.__token)
115119
logger.debug("Set token '{}' into 'FILE' '{}'".format(self.__token, filepath))

0 commit comments

Comments
 (0)