def update_application(self, applicationId, name=None, platform=None, partition=None, request_format=None): """ Update the Application @param applicationId The ID of the application which has to be updated @param name The name of the application @param platform The platform of the application @param partition The partition of the application @return: response The applicationID if headers is JSON. Full response body otherwise. """ self.preconditionCheck() if(request_format is not None): self.requestType = request_format if(name is None and platform is None and partition is None): return "At least one of the parameter (name, platform, partition) needs to be set." resource = self.url + "applications/" + applicationId if self.requestType == data_format.JSON: postBody = {"name": name, "platform": platform, "partition": partition} response = TropoConnect.doPUT(self.userName, self.password, resource, postBody, self.requestType) elif self.requestType == data_format.XML: postBody = "<application><name>%s</name><platform>%s</platform><partition>%s</partition></application>" % (name, platform, partition) response = TropoConnect.doPUT(self.userName, self.password, resource, postBody, self.requestType) elif self.requestType == data_format.FORM_ENCODED: postBody = "name=%s&platform=%s&partition=%s" % (name, platform, partition) response = TropoConnect.doPUT(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'][u'href'].rpartition('/')[2] else: result = response[u'responseValue'] return result else: return "Update Application failed with the following reason: (Error Code = %s) (Error msg = %s)" % (response[u'responseCode'], response[u'responseValue'])
def add_voice_messaging_url(self, applicationId, voiceUrl=None, messagingUrl=None, request_format=None): """ Add a voice and message URL to the Application @param applicationId The ID of the application to which the voice & message url has to be added @param voiceUrl The Voice URL for that application @param messagingUrl The Messaging URL for that application @return: string response The applicationID is headers is JSON. Full response body otherwise. """ self.preconditionCheck() if(request_format is not None): self.requestType = request_format if(voiceUrl is None and messagingUrl is None): return "Adding Voice & Messaging URLs failed as there is nothing to add" resource = self.url + "applications/" + applicationId if self.requestType == data_format.JSON: if(voiceUrl is not None and messagingUrl is not None): postBody = {"voiceUrl":voiceUrl, "messagingUrl":messagingUrl} elif(voiceUrl is not None): postBody = {"voiceUrl":voiceUrl} elif(messagingUrl is not None): postBody = {"messagingUrl":messagingUrl} response = TropoConnect.doPUT(self.userName, self.password, resource, postBody, self.requestType) elif self.requestType == data_format.XML: if(voiceUrl is not None and messagingUrl is not None): postBody = "<application><voiceurl>%s</voiceurl><messagingurl>%s</messagingurl></application>" % (voiceUrl, messagingUrl) elif(voiceUrl is not None): postBody = "<application><voiceurl>%s</voiceurl></application>" % (voiceUrl) elif(messagingUrl is not None): postBody = "<application><messagingurl>%s</messagingurl></application>" % (messagingUrl) response = TropoConnect.doPUT(self.userName, self.password, resource, postBody, self.requestType) elif self.requestType == data_format.FORM_ENCODED: if(voiceUrl is not None and messagingUrl is not None): postBody = "voiceURL=%s&messagingURL=%s" % (voiceUrl, messagingUrl) elif(voiceUrl is not None): postBody = "voiceURL=%s" % (voiceUrl) elif(messagingUrl is not None): postBody = "messagingURL=%s" % (messagingUrl) response = TropoConnect.doPUT(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'][u'href'].rpartition('/')[2] else: result = response[u'responseValue'] return result else: return "Adding Voice & Messaging URLs failed with the following reason: (Error Code = %s) (Error msg = %s)" % (response[u'responseCode'], response[u'responseValue'])