1010from churchtools_api .calendar import ChurchToolsApiCalendar
1111from churchtools_api .resources import ChurchToolsApiResources
1212
13+ logger = logging .getLogger (__name__ )
1314
1415class ChurchToolsApi (ChurchToolsApiPersons , ChurchToolsApiEvents , ChurchToolsApiGroups ,
1516 ChurchToolsApiSongs , ChurchToolsApiFiles , ChurchToolsApiCalendar , ChurchToolsApiResources ):
@@ -48,7 +49,7 @@ def __init__(self, domain, ct_token=None, ct_user=None, ct_password=None):
4849 elif ct_user is not None and ct_password is not None :
4950 self .login_ct_rest_api (ct_user = ct_user , ct_password = ct_password )
5051
51- logging .debug ('ChurchToolsApi init finished' )
52+ logger .debug ('ChurchToolsApi init finished' )
5253
5354 def login_ct_rest_api (self , ** kwargs ):
5455 """
@@ -68,26 +69,26 @@ def login_ct_rest_api(self, **kwargs):
6869 self .session = requests .Session ()
6970
7071 if 'ct_token' in kwargs .keys ():
71- logging .info ('Trying Login with token' )
72+ logger .info ('Trying Login with token' )
7273 url = self .domain + '/api/whoami'
7374 headers = {"Authorization" : 'Login ' + kwargs ['ct_token' ]}
7475 response = self .session .get (url = url , headers = headers )
7576
7677 if response .status_code == 200 :
7778 response_content = json .loads (response .content )
78- logging .info (
79+ logger .info (
7980 'Token Login Successful as {}' .format (
8081 response_content ['data' ]['email' ]))
8182 self .session .headers ['CSRF-Token' ] = self .get_ct_csrf_token ()
8283 return json .loads (response .content )['data' ]['id' ]
8384 else :
84- logging .warning (
85+ logger .warning (
8586 "Token Login failed with {}" .format (
8687 response .content .decode ()))
8788 return False
8889
8990 elif 'ct_user' in kwargs .keys () and 'ct_password' in kwargs .keys ():
90- logging .info ('Trying Login with Username/Password' )
91+ logger .info ('Trying Login with Username/Password' )
9192 url = self .domain + '/api/login'
9293 data = {
9394 'username' : kwargs ['ct_user' ],
@@ -97,11 +98,11 @@ def login_ct_rest_api(self, **kwargs):
9798 if response .status_code == 200 :
9899 response_content = json .loads (response .content )
99100 person = self .who_am_i ()
100- logging .info (
101+ logger .info (
101102 'User/Password Login Successful as {}' .format (person ['email' ]))
102103 return person ['id' ]
103104 else :
104- logging .warning (
105+ logger .warning (
105106 "User/Password Login failed with {}" .format (response .content .decode ()))
106107 return False
107108
@@ -118,11 +119,11 @@ def get_ct_csrf_token(self):
118119 response = self .session .get (url = url )
119120 if response .status_code == 200 :
120121 csrf_token = json .loads (response .content )["data" ]
121- logging .info (
122+ logger .info (
122123 "CSRF Token erfolgreich abgerufen {}" .format (csrf_token ))
123124 return csrf_token
124125 else :
125- logging .warning (
126+ logger .warning (
126127 "CSRF Token not updated because of Response {}" .format (
127128 response .content .decode ()))
128129
@@ -139,17 +140,17 @@ def who_am_i(self):
139140 if response .status_code == 200 :
140141 response_content = json .loads (response .content )
141142 if 'email' in response_content ['data' ].keys ():
142- logging .info (
143+ logger .info (
143144 'Who am I as {}' .format (
144145 response_content ['data' ]['email' ]))
145146 return response_content ['data' ]
146147 else :
147- logging .warning (
148+ logger .warning (
148149 'User might not be logged in? {}' .format (
149150 response_content ['data' ]))
150151 return False
151152 else :
152- logging .warning (
153+ logger .warning (
153154 "Checking who am i failed with {}" .format (
154155 response .status_code ))
155156 return False
@@ -166,10 +167,10 @@ def check_connection_ajax(self):
166167 }
167168 response = self .session .post (url = url , headers = headers )
168169 if response .status_code == 200 :
169- logging .debug ("Response AJAX Connection successful" )
170+ logger .debug ("Response AJAX Connection successful" )
170171 return True
171172 else :
172- logging .debug (
173+ logger .debug (
173174 "Response AJAX Connection failed with {}" .format (
174175 json .load (
175176 response .content )))
@@ -188,12 +189,12 @@ def get_global_permissions(self) -> dict:
188189 if response .status_code == 200 :
189190 response_content = json .loads (response .content )
190191 response_data = response_content ['data' ].copy ()
191- logging .debug (
192+ logger .debug (
192193 "First response of Global Permissions successful {}" .format (response_content ))
193194
194195 return response_data
195196 else :
196- logging .warning (
197+ logger .warning (
197198 "Something went wrong fetching global permissions: {}" .format (
198199 response .status_code ))
199200
@@ -226,10 +227,10 @@ def get_services(self, **kwargs):
226227 result [item ['id' ]] = item
227228 response_data = result
228229
229- logging .debug ("Services load successful {} " .format (response_data ))
230+ logger .debug ("Services load successful with {} entries " .format (len ( response_data ) ))
230231 return response_data
231232 else :
232- logging .info (
233+ logger .info (
233234 "Services requested failed: {}" .format (
234235 response .status_code ))
235236 return None
@@ -257,10 +258,10 @@ def get_tags(self, type='songs'):
257258 if response .status_code == 200 :
258259 response_content = json .loads (response .content )
259260 response_data = response_content ['data' ].copy ()
260- logging .debug (
261+ logger .debug (
261262 "SongTags load successful {}" .format (response_content ))
262263
263264 return response_content ['data' ]
264265 else :
265- logging .warning (
266+ logger .warning (
266267 "Something went wrong fetching Song-tags: {}" .format (response .status_code ))
0 commit comments