def get_all_available_prefixes_for_account(self, prefix, request_format=None):
     """ 
     Get all the available prefixes for the account
     
     @return: string response         The response from the REST API call
     """
                
     self.preconditionCheck()
     
     if(prefix is None):
         return "Prefix is not set. Please set it and try again!"
     if(request_format is not None):
         self.requestType = request_format
     
     resource = self.url + "addresses?available&prefix=" + prefix
     response = TropoConnect.doGET(self.userName, self.password, resource, self.requestType)
     
     self.tropo_logger_inst.logger(DEBUG, "ResponseCode = %s" % response[u'responseCode'])
     self.tropo_logger_inst.logger(DEBUG, "ResponseValue = %s" % response[u'responseValue'])   
     
     if (response[u'responseCode'] == 200):
         if(self.requestType == data_format.JSON):
             result = response[u'responseValue']
             return result               # returns a list
         else:
             result = response[u'responseValue']
         return result
     else:        
         return "Getting All Available Prefixes failed with the following reason: (Error Code = %s) (Error msg = %s)" % (response[u'responseCode'], response[u'responseValue'])
 def get_all_available_exchanges_for_account(self, request_format=None):
     """ 
     Get all the exchanges associated with the account
     
     @return: List response         The list of all the exchanges
     """
                
     self.preconditionCheck()
     if(request_format is not None):
         self.requestType = request_format
         
     resource = self.url + "exchanges"
     response = TropoConnect.doGET(self.userName, self.password, resource, self.requestType)
     
     self.tropo_logger_inst.logger(DEBUG, "ResponseCode = %s" % response[u'responseCode'])
     self.tropo_logger_inst.logger(DEBUG, "ResponseValue = %s" % response[u'responseValue'])   
     
     if (response[u'responseCode'] == 200):
         if(self.requestType == data_format.JSON):
             result = response[u'responseValue']
             return result               # returns a list
         else:
             result = response[u'responseValue']
         return result
     else:        
         return "Getting All Available Exchanges failed with the following reason: (Error Code = %s) (Error msg = %s)" % (response[u'responseCode'], response[u'responseValue'])
 def get_application_addresses(self, applicationId, request_format=None):
     """ 
     Get all the Application's addresses associated with it
     
     @param applicationId           The ID of the application 
     
     @return: List response         The list of all the addresses associated with an application
     """
     
     self.preconditionCheck()
     if(request_format is not None):
         self.requestType = request_format
         
     resource = self.url + "applications/" + applicationId + "/addresses"
     response = TropoConnect.doGET(self.userName, self.password, resource, self.requestType)
     
     self.tropo_logger_inst.logger(DEBUG, "ResponseCode = %s" % response[u'responseCode'])
     self.tropo_logger_inst.logger(DEBUG, "ResponseValue = %s" % response[u'responseValue'])   
     
     if (response[u'responseCode'] == 200):
         if(self.requestType == data_format.JSON):
             result = response[u'responseValue']
             return result               # returns a list
         else:
             result = response[u'responseValue']
         return result
     else:        
         return "Getting Application Addresses failed with the following reason: (Error Code = %s) (Error msg = %s)" % (response[u'responseCode'], response[u'responseValue'])
 def start_session_webApi(self, method, token=None, request_format=None):
     """ 
     Create a new WebApi Session
     
     @param token        The body of the request
     
     @return: Dict response      The response from the REST API call as a dict containing token
     """
     self.preconditionCheck()
     if(token is None):
         return "Token is not set."
     if(request_format is not None):
         self.requestType = request_format
         
     resource = "https://api.tropo.com/1.0/sessions"
     # resource = "https://api.tropo.com/1.0/sessions?action=create&token=TOKEN&numberToDial=4075551212&customerName=John+Dyer&msg=the+sky+is+falling"
     
     if (method == "POST"):
         
         if self.requestType == data_format.JSON:
             postBody = {"token": token}
             response = TropoConnect.doPOST(self.userName, self.password, resource, postBody, self.requestType)
         
         elif self.requestType == data_format.XML:
             postBody = "<session><token>%s</token></session>" % (token)
             response = TropoConnect.doPOST(self.userName, self.password, resource, postBody, self.requestType)
                              
         elif self.requestType == data_format.FORM_ENCODED:
             postBody = "token=%s" % (token) 
             response = TropoConnect.doPOST(self.userName, self.password, resource, postBody, self.requestType)
         else:
             return "Bad request type."
         
         self.tropo_logger_inst.logger(DEBUG, "ResponseCode = %s" % response[u'responseCode'])
         self.tropo_logger_inst.logger(DEBUG, "ResponseValue = %s" % response[u'responseValue'])   
         
         if (response[u'responseCode'] == 200):
             if(self.requestType == data_format.JSON):
                 result = response[u'responseValue']
                 return result               # returns a list
             else:
                 result = response[u'responseValue']
             return result
         else:        
             return "Starting Session-WebApi failed with the following reason: (Error Code = %s) (Error msg = %s)" % (response[u'responseCode'], response[u'responseValue'])
         
          
     if (method == "GET"):
         resource = resource + "?action=create&token=" + token
         response = TropoConnect.doGET(self.userName, self.password, resource, self.requestType)
         
         self.tropo_logger_inst.logger(DEBUG, "ResponseCode = %s" % response[u'responseCode'])
         self.tropo_logger_inst.logger(DEBUG, "ResponseValue = %s" % response[u'responseValue'])   
         
         if (response[u'responseCode'] == 200):
             if(self.requestType == data_format.JSON):
                 result = response[u'responseValue']
                 return result               # returns a list
             else:
                 result = response[u'responseValue']
             return result
         else:        
             return "Starting Session-WebApi failed with the following reason: (Error Code = %s) (Error msg = %s)" % (response[u'responseCode'], response[u'responseValue'])
 def start_session(self, method, token=None, customerName=None, numberToDial=None, msg=None, request_format=None):
     """ 
     Create a new Application
     
     @param token               The token for the session
     @param customerName        The name of the customer
     @param numberToDial        The number to dial
     @param msg                 The message body
     
     @return: Dict response      The response from the REST API call as a dict containing token
     """
     self.preconditionCheck()
     if(token is None):
         return "Token is not set."
     if(request_format is not None):
         self.requestType = request_format
         
     postBody = ""
     resource = "https://api.tropo.com/1.0/sessions"
     
     if (method == "POST"):
         
         if self.requestType == data_format.JSON:
             postBody = {"token": token, "customerName": customerName, "numberToDial": numberToDial, "msg": msg}
             response = TropoConnect.doPOST(self.userName, self.password, resource, postBody, self.requestType)
         
         elif self.requestType == data_format.XML:
             postBody = "<session><token>%s</token><var name=\"customerName\" value=\"%s\"></var><var name=\"numberToDial\" value=\"%s\"></var><var name=\"msg\" value=\"%s\"></var></session>" % (token, customerName, numberToDial, msg)
             response = TropoConnect.doPOST(self.userName, self.password, resource, postBody, self.requestType)
                              
         elif self.requestType == data_format.FORM_ENCODED:
             postBody = "token=%s&customerName=%s&numberToDial=%s&msg=%s" % (token, customerName, numberToDial, msg) 
             response = TropoConnect.doPOST(self.userName, self.password, resource, postBody, self.requestType)
         else:
             return "Bad request type."
         
         self.tropo_logger_inst.logger(DEBUG, "ResponseCode = %s" % response[u'responseCode'])
         self.tropo_logger_inst.logger(DEBUG, "ResponseValue = %s" % response[u'responseValue'])   
         
         if (response[u'responseCode'] == 200):
             if(self.requestType == data_format.JSON):
                 result = response[u'responseValue']
                 return result               # returns a list
             else:
                 result = response[u'responseValue']
             return result
         else:        
             return "Starting Session failed with the following reason: (Error Code = %s) (Error msg = %s)" % (response[u'responseCode'], response[u'responseValue'])
         
          
     if (method == "GET"):
         params = urllib.urlencode({"token": token, "customerName": customerName, "numberToDial": numberToDial, "msg": msg})
         resource = resource + "?action=create&%s" % (params)
         response = TropoConnect.doGET(self.userName, self.password, resource, self.requestType)
         
         self.tropo_logger_inst.logger(DEBUG, "ResponseCode = %s" % response[u'responseCode'])
         self.tropo_logger_inst.logger(DEBUG, "ResponseValue = %s" % response[u'responseValue'])   
         
         if (response[u'responseCode'] == 200):
             if(self.requestType == data_format.JSON):
                 result = response[u'responseValue']
                 return result               # returns a list
             else:
                 result = response[u'responseValue']
             return result
         else:        
             return "Starting Session failed with the following reason: (Error Code = %s) (Error msg = %s)" % (response[u'responseCode'], response[u'responseValue'])