HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall_forms/buyercall/buyercall/integrations/ams_analytics.py
import os
import logging
import xml.etree.ElementTree as ET
from flask import current_app as app
import requests
import xml.etree.ElementTree as ET
import xmltodict
import json

log = logging.getLogger(__name__)


class AMSAnalytics(object):
    def __init__(self, client_id, url):
        self.post_url = url
        self.client_id = client_id
        self.get_list_url = app.config['AMS_LIST_URL']
        self.get_list_client_key = app.config['AMS_LIST_CLIENT_KEY']
        self.get_list_client_secret = app.config['AMS_LIST_CLIENT_SECRET']

    def post(self, data):
        headers = {'Content-Type': 'application/json'}
        params = {'clientId': self.client_id}
        r = requests.post(self.post_url, json=data, headers=headers, params=params)
        if r.status_code == 200:
            try:
                response_data = r.json()
                return r.status_code, 'Successfully submitted'
            except json.JSONDecodeError:
                log.error(f'Failed to decode JSON response: {r.text}')
                return r.status_code, 'Error posting form lead.'
        else:
            log.error(f'Response: {r.text}')
            return r.status_code, 'Error posting form lead.'



    def get_lists(self):
        headers = {
                    'Content-Type': 'application/json',
                    self.get_list_client_key : self.get_list_client_secret
                }
        endpoint = self.get_list_url
        body = ["States", "MaritalStatuses", "HousingStatuses", "IncomePeriods", "IncomeTypes"]
        r = requests.post(endpoint, json=body, headers=headers)
      
        if r.status_code == 200:
            try:
                response_data = r.json()
                return r.status_code, response_data
            except json.JSONDecodeError:
                log.error(f'Failed to decode JSON response: {r.text}')
                return r.status_code, 'Error decoding JSON response.'
        else:
            log.error(f'Response: {r.text}')
            return r.status_code, 'Error retrieving lists.'