def notify_subscribed_accounts(self, event=None, event_data=None, secret_key=None, endpoint=None, account_id=None): """ Send Webhook requests to all subscribed accounts """ signature = create_signature(secret_key, event_data) request_handler = RequestHandler( verify_ssl=False, request_timeout=REQUEST_TIMEOUT) try: _, status_code = request_handler.post( url=endpoint, json_payload=event_data, event=event, signature=signature) # We don't care about anything but the return status code if client.OK != status_code: raise Exception('Endpoint returning non HTTP 200 status. ' 'Actual code returned: {0}'.format(status_code)) if client.OK == status_code: # Failed count will reset on a good contact update_failed_count(account_id, increment_failed_count=False) except Exception as exc: update_failed_count(account_id, increment_failed_count=True) if self.request.retries == 3: raise self.retry(exc=exc, countdown=DEFAULT_FINAL_RETRY) else: raise self.retry(exc=exc, countdown=DEFAULT_RETRY)
def test_good_secret_key(self): test_signature = hmac.new( str(self.secret_key).encode('utf-8'), str(json.dumps(self.json_data)).encode('utf-8'), digestmod=hashlib.sha1 ).hexdigest() self.assertEqual( test_signature, create_signature(self.secret_key, self.json_data) )
def notify_subscribed_accounts(self, event=None, event_data=None, secret_key=None, endpoint=None, account_id=None): """ Send Webhook requests to all subscribed accounts """ signature = create_signature(secret_key, event_data) request_handler = RequestHandler(verify_ssl=False, request_timeout=REQUEST_TIMEOUT) try: _, status_code = request_handler.post(url=endpoint, json_payload=event_data, event=event, signature=signature) # We don't care about anything but the return status code if client.OK != status_code: raise Exception('Endpoint returning non HTTP 200 status. ' 'Actual code returned: {0}'.format(status_code)) if client.OK == status_code: # Failed count will reset on a good contact update_failed_count(account_id, increment_failed_count=False) except Exception as exc: update_failed_count(account_id, increment_failed_count=True) if self.request.retries == 3: raise self.retry(exc=exc, countdown=DEFAULT_FINAL_RETRY) else: raise self.retry(exc=exc, countdown=DEFAULT_RETRY)