operation_service.py 1019 B

123456789101112131415161718192021222324252627282930313233
  1. import os
  2. import requests
  3. class OperationService:
  4. base_url = os.environ.get('BILLING_API_URL', 'BILLING_API_URL')
  5. secret_key = os.environ.get('BILLING_API_SECRET_KEY', 'BILLING_API_SECRET_KEY')
  6. @classmethod
  7. def _send_request(cls, method, endpoint, json=None, params=None):
  8. headers = {
  9. "Content-Type": "application/json",
  10. "Billing-Api-Secret-Key": cls.secret_key
  11. }
  12. url = f"{cls.base_url}{endpoint}"
  13. response = requests.request(method, url, json=json, params=params, headers=headers)
  14. return response.json()
  15. @classmethod
  16. def record_utm(cls, tenant_id, args):
  17. params = {
  18. 'tenant_id': tenant_id,
  19. 'utm_source': args['utm_source'],
  20. 'utm_medium': args['utm_medium'],
  21. 'utm_campaign': args['utm_campaign'],
  22. 'utm_content': args['utm_content'],
  23. 'utm_term': args['utm_term']
  24. }
  25. return cls._send_request('POST', '/tenant_utms', params=params)