@@ -15,44 +15,28 @@ class ChurchToolsApiSongs(ChurchToolsApiAbstract):
1515 def __init__ (self ):
1616 super ()
1717
18- def get_songs (self , ** kwargs ):
19- """ Gets list of all songs from the server
20- :key kwargs song_id: int: optional filter by song id
21- :return: list of songs
22- :rtype: list[dict]
18+ def get_songs (self , ** kwargs ) -> list [dict ]:
19+ """Gets list of all songs from the server.
20+
21+ Kwargs:
22+ song_id: int: optional filter by song id
23+
24+ Returns: list of songs
2325 """
2426
25- url = self .domain + ' /api/songs'
27+ url = self .domain + " /api/songs"
2628 if "song_id" in kwargs .keys ():
27- url = url + '/{}' .format (kwargs ["song_id" ])
28- headers = {
29- 'accept' : 'application/json'
30- }
29+ url = url + "/{}" .format (kwargs ["song_id" ])
30+ headers = {"accept" : "application/json" }
3131 response = self .session .get (url = url , headers = headers )
3232
3333 if response .status_code == 200 :
3434 response_content = json .loads (response .content )
35- response_data = response_content ['data' ].copy ()
36- logging .debug (
37- "First response of GET Songs successful {}" .format (response_content ))
38-
39- if 'meta' not in response_content .keys (): # Shortcut without Pagination
40- return [response_data ] if isinstance (
41- response_data , dict ) else response_data
42-
43- # Long part extending results with pagination
44- while response_content ['meta' ]['pagination' ]['current' ] \
45- < response_content ['meta' ]['pagination' ]['lastPage' ]:
46- logging .info ("page {} of {}" .format (response_content ['meta' ]['pagination' ]['current' ],
47- response_content ['meta' ]['pagination' ]['lastPage' ]))
48- params = {
49- 'page' : response_content ['meta' ]['pagination' ]['current' ] + 1 }
50- response = self .session .get (
51- url = url , headers = headers , params = params )
52- response_content = json .loads (response .content )
53- response_data .extend (response_content ['data' ])
54-
55- return response_data
35+ response_data = self .combine_paginated_response_data (
36+ response_content , url = url , headers = headers
37+ )
38+ return [response_data ] if isinstance (response_data , dict ) else response_data
39+
5640 else :
5741 if "song_id" in kwargs .keys ():
5842 logging .info (
0 commit comments