diff --git a/odins_spear/api.py b/odins_spear/api.py index d83a664..c819d36 100644 --- a/odins_spear/api.py +++ b/odins_spear/api.py @@ -1,7 +1,6 @@ from .requester import Requester from .logger import Logger -from .scripter import Scripter -from .reporter import Reporter + from .exceptions import ( OSApiAuthenticationFail, @@ -42,8 +41,6 @@ def __init__( self.logger = Logger.get_instance(self.username) self._requester = Requester(self.base_url, self.rate_limit, self.logger) - self.scripter = Scripter(api=self) - self.reporter = Reporter(api=self) self.administrators = Administrators() self.alternate_numbers = AlternateNumbers() self.authentication = Authentication() @@ -174,6 +171,6 @@ def _update_requester(self, session_response: requests.models.Response): def __str__(self) -> str: return ( - f"API - url: {self.base_url}, username: {self.username}" + f"API - url: {self.base_url}, username: {self.username} " f"Authenticated: {self.authorised}" ) diff --git a/odins_spear/endpoints/services.py b/odins_spear/endpoints/services.py index 1ac2f3f..5e3dff1 100644 --- a/odins_spear/endpoints/services.py +++ b/odins_spear/endpoints/services.py @@ -53,7 +53,7 @@ def get_user_service_settings(self, user_id: str): params = {"userId": user_id} return self._requester.get(endpoint, params=params) - + def get_group_services(self, group_id: str, service_provider_id: str): """ diff --git a/odins_spear/scripts/aa_cc_hg_audit.py b/odins_spear/scripts/aa_cc_hg_audit.py index 3dafca7..9f6d9c5 100644 --- a/odins_spear/scripts/aa_cc_hg_audit.py +++ b/odins_spear/scripts/aa_cc_hg_audit.py @@ -1,74 +1,25 @@ from tqdm import tqdm -def remove_excess_details(aa_cc_hg: dict): - del aa_cc_hg["name"] - del aa_cc_hg["phoneNumber"] - del aa_cc_hg["extension"] - del aa_cc_hg["department"] - del aa_cc_hg["isActive"] - - if aa_cc_hg["typeTag"] == "AA": - del aa_cc_hg["video"] - elif aa_cc_hg["typeTag"] == "CC": - del aa_cc_hg["video"] - del aa_cc_hg["policy"] - elif aa_cc_hg["typeTag"] == "HG": - del aa_cc_hg["serviceProviderId"] - del aa_cc_hg["groupId"] - del aa_cc_hg["policy"] - -def main(api, service_provider_id: str, group_id: str): - """ - This script returns the services assigned to Auto Attendants, - Call Centres, and Hunt Groups. Only services are applied to these - entities and there are scenarios one would need to focus services - assigned to these entities. - - :param service_provider_id: Service Provider ID or Enterprise ID containing the Group ID. - :param group_id: Group ID to generate the report for. +def main(api, service_provider_id: str, group_id: str) -> dict: + return_data = {"auto_attendants": [], "call_centers": [], "hunt_groups": []} - :return JSON: A JSON formatted report of service packs assigned to AA, CC, and HG. - """ + for entity_type, api_method in [ + ("auto_attendants", api.auto_attendants.get_auto_attendants), + ("call_centers", api.call_centers.get_group_call_centers), + ("hunt_groups", api.hunt_groups.get_group_hunt_groups), + ]: + entities = api_method(service_provider_id, group_id) + for entity in tqdm( + entities, desc=f"Analysing {entity_type.replace("_", " ").title()}" + ): + services = api.services.get_user_services_assigned(entity["serviceUserId"]) + return_data[entity_type].append( + { + "serviceUserId": entity["serviceUserId"], + "type": entity.get("type", "None"), + "services": services.get("userServices", []), + } + ) - print("aa_cc_hg_audit start.") - return_data = { - "autoAttendants": [], - "callCenters": [], - "huntGroups": [] - } - auto_attendants = api.get.auto_attendants(service_provider_id, group_id) - call_centers = api.get.group_call_centers(service_provider_id, group_id) - hunt_groups = api.get.group_hunt_groups(service_provider_id, group_id) - - for aa in tqdm(auto_attendants, desc="Analysing Auto Attendants"): - aa["typeTag"] = "AA" - remove_excess_details(aa) - - for cc in tqdm(call_centers, desc="Analysing Call Centers"): - cc["typeTag"] = "CC" - remove_excess_details(cc) - - for hg in tqdm(hunt_groups, desc="Analysing Hunt Groups"): - hg["typeTag"] = "HG" - remove_excess_details(hg) - - aa_cc_hgs = auto_attendants + call_centers + hunt_groups - - for aa_cc_hg in tqdm(aa_cc_hgs, desc="Fetching User Services"): - response = api.get.user_services_assigned(aa_cc_hg["serviceUserId"]) - aa_cc_hg["services"] = response["userServices"] - - if aa_cc_hg["typeTag"] == "AA": - del aa_cc_hg["typeTag"] - return_data["autoAttendants"].append(aa_cc_hg) - elif aa_cc_hg["typeTag"] == "CC": - del aa_cc_hg["typeTag"] - return_data["callCenters"].append(aa_cc_hg) - elif aa_cc_hg["typeTag"] == "HG": - del aa_cc_hg["typeTag"] - return_data["huntGroups"].append(aa_cc_hg) - return return_data - - \ No newline at end of file