1212import sys
1313from pathlib import Path
1414import os
15-
15+ import json
1616from requests import Session
1717from requests .auth import HTTPBasicAuth
1818import re
@@ -94,14 +94,42 @@ def get_locations(
9494 except Fault as e :
9595 return e
9696
97+ def run_sql_query (self , query ):
98+ result = {'num_rows' : 0 ,
99+ 'query' : query }
100+
101+ try :
102+ sql_result = self .client .executeSQLQuery (sql = query )
103+ print (sql_result )
104+ except Exception as fault :
105+ sql_result = None
106+ self .last_exception = fault
107+
108+ num_rows = 0
109+ result_rows = []
110+
111+ if sql_result is not None :
112+ if sql_result ['return' ] is not None :
113+ for row in sql_result ['return' ]['row' ]:
114+ result_rows .append ({})
115+ for column in row :
116+ result_rows [num_rows ][column .tag ] = column .text
117+ num_rows += 1
118+
119+ result ['num_rows' ] = num_rows
120+ if num_rows > 0 :
121+ result ['rows' ] = result_rows
122+
123+ return result
124+
97125 def sql_query (self , query ):
98126 """
99127 Execute SQL query
100128 :param query: SQL Query to execute
101129 :return: result dictionary
102130 """
103131 try :
104- return self .client .executeSQLQuery (query )[" return" ]
132+ return self .client .executeSQLQuery (query )[' return' ]
105133 except Fault as e :
106134 return e
107135
@@ -1854,7 +1882,7 @@ def update_cti_route_point(self, **args):
18541882 except Fault as e :
18551883 return e
18561884
1857- def get_phones (self , tagfilter = {
1885+ def get_phones (self , query = { "name" : "%" }, tagfilter = {
18581886 "name" : "" ,
18591887 "product" : "" ,
18601888 "description" : "" ,
@@ -1867,7 +1895,7 @@ def get_phones(self, tagfilter={
18671895 def inner (skip ):
18681896 while True :
18691897 res = self .client .listPhone (
1870- { "name" : "%" } , returnedTags = tagfilter , first = 1000 , skip = skip
1898+ searchCriteria = query , returnedTags = tagfilter , first = 1000 , skip = skip
18711899 )["return" ]
18721900 skip = skip + 1000
18731901 if res is not None and 'phone' in res :
@@ -2644,7 +2672,7 @@ def add_called_party_xform(
26442672 description = "" ,
26452673 partition = "" ,
26462674 calledPartyPrefixDigits = "" ,
2647- calledPartyTransformationmask = "" ,
2675+ calledPartyTransformationMask = "" ,
26482676 digitDiscardInstructionName = "" ,
26492677 ):
26502678 """
@@ -2669,7 +2697,7 @@ def add_called_party_xform(
26692697 "description" : description ,
26702698 "routePartitionName" : partition ,
26712699 "calledPartyPrefixDigits" : calledPartyPrefixDigits ,
2672- "calledPartyTransformationmask " : calledPartyTransformationmask ,
2700+ "calledPartyTransformationMask " : calledPartyTransformationMask ,
26732701 "digitDiscardInstructionName" : digitDiscardInstructionName ,
26742702 }
26752703 )
@@ -2745,7 +2773,7 @@ def add_calling_party_xform(
27452773 description = "" ,
27462774 partition = "" ,
27472775 callingPartyPrefixDigits = "" ,
2748- callingPartyTransformationmask = "" ,
2776+ callingPartyTransformationMask = "" ,
27492777 digitDiscardInstructionName = "" ,
27502778 ):
27512779 """
@@ -2770,7 +2798,7 @@ def add_calling_party_xform(
27702798 "description" : description ,
27712799 "routePartitionName" : partition ,
27722800 "callingPartyPrefixDigits" : callingPartyPrefixDigits ,
2773- "callingPartyTransformationmask " : callingPartyTransformationmask ,
2801+ "callingPartyTransformationMask " : callingPartyTransformationMask ,
27742802 "digitDiscardInstructionName" : digitDiscardInstructionName ,
27752803 }
27762804 )
@@ -2797,7 +2825,7 @@ def update_calling_party_xform(self, **args):
27972825 :param pattern: pattern - required
27982826 :param routePartitionName: partition required
27992827 :param description: Route pattern description
2800- :param calledPartyTransformationmask :
2828+ :param callingPartyTransformationMask :
28012829 :param dialPlanName:
28022830 :param digitDiscardInstructionName:
28032831 :param routeFilterName:
0 commit comments