def send(self, values): """Send this ARI request substituting the given values""" uri = var_replace(self.uri, values) url = self.ari.build_url(uri) requests_method = getattr(requests, self.method) params = dict((key, var_replace(val, values)) for key, val in self.params.iteritems()) response = requests_method(url, params=params, data=self.body, headers=self.headers, auth=self.ari.userpass) if self.response_body: match = self.response_body.get('match') return all_match(match, response.json()) if self.expect: if response.status_code != self.expect: LOGGER.error('sent %s %s %s expected %s response %d %s', self.method, self.uri, self.params, self.expect, response.status_code, response.text) return False else: if response.status_code / 100 != 2: LOGGER.error('sent %s %s %s response %d %s', self.method, self.uri, self.params, response.status_code, response.text) return False LOGGER.info('sent %s %s %s response %d %s', self.method, self.uri, self.params, response.status_code, response.text) return response
def send(self, values): """Send this ARI request substituting the given values""" uri = var_replace(self.uri, values) url = self.ari.build_url(uri) requests_method = getattr(requests, self.method) params = dict((key, var_replace(val, values)) for key, val in self.params.iteritems()) response = requests_method( url, params=params, data=self.body, headers=self.headers, auth=self.ari.userpass) if self.expect: if response.status_code != self.expect: LOGGER.error('sent %s %s %s expected %s response %d %s', self.method, self.uri, self.params, self.expect, response.status_code, response.text) return False else: if response.status_code / 100 != 2: LOGGER.error('sent %s %s %s response %d %s', self.method, self.uri, self.params, response.status_code, response.text) return False LOGGER.info('sent %s %s %s response %d %s', self.method, self.uri, self.params, response.status_code, response.text) return response
def send(self, values): """Send this ARI request substituting the given values""" uri = var_replace(self.uri, values) url = self.ari.build_url(uri) requests_method = getattr(requests, self.method) response = requests_method(url, params=self.params, data=self.body, headers=self.headers, auth=self.ari.userpass) if self.expect: if response.status_code != self.expect: LOGGER.error('sent %s %s %s expected %s response %d %s', self.method, self.uri, self.params, self.expect, response.status_code, response.text) return False else: if response.status_code / 100 != 2: LOGGER.error('sent %s %s %s response %d %s', self.method, self.uri, self.params, response.status_code, response.text) return False LOGGER.info('sent %s %s %s response %d %s', self.method, self.uri, self.params, response.status_code, response.text) return response
def replace_ami_vars(mydict, values): outdict = {} for key, value in mydict.iteritems(): outdict[key] = var_replace(value, values) return outdict