예제 #1
0
 def _parse_response(self, data):
     response = json.loads(data)
     log_entry = LogEntry(
         timestamp=datetime.datetime.now(),
         gatename=self.__class__.__name__,
         status=LogEntry.ERROR if response['status'] == 'error' else LogEntry.OK,
         phone=response.get('phone', ''),
         error_code=response.get('error_code', None),
         error_msg=response.get('error_msg', '')
     )
     log_entry.save()
     return log_entry
예제 #2
0
    def send(self, data):
        url = self._build_url(data)
        post_data = self._get_post_data(data)

        resp = requests.post(url, params=post_data)
        if not resp.ok:
            log_entry = LogEntry(timestamp=datetime.datetime.now(),
                                 gatename=self.__class__.__name__,
                                 status=LogEntry.ERROR,
                                 phone=data.get('phone', ''),
                                 error_code=resp.status_code,
                                 error_msg=resp.reason)
            log_entry.save()
            return log_entry

        return self._parse_response(resp.content)
예제 #3
0
    def send(self, data):
        url = self._build_url(data)
        post_data = self._get_post_data(data)

        resp = requests.post(url, params=post_data)
        if not resp.ok:
            log_entry = LogEntry(
                timestamp=datetime.datetime.now(),
                gatename=self.__class__.__name__,
                status=LogEntry.ERROR,
                phone=data.get('phone', ''),
                error_code=resp.status_code,
                error_msg=resp.reason
            )
            log_entry.save()
            return log_entry

        return self._parse_response(resp.content)
예제 #4
0
 def _parse_response(self, data):
     response = json.loads(data)
     log_entry = LogEntry(
         timestamp=datetime.datetime.now(),
         gatename=self.__class__.__name__,
         status=LogEntry.ERROR if 'error' in response else LogEntry.OK,
         phone=response.get('phone', ''),
         error_code=response.get('error_code', None),
         error_msg=response.get('error', ''))
     # не сохраняем log_entry, так как нам нужно добавить иформацию о номере (реальный гейт ее не возвращает)
     return log_entry