import json, requests, datetime, time
from api_auth import APICredentials, APIParams

class Audience:
    def __init__(self):
        self.host = "https://services.uplynk.com"

    def run(self):
        """
        Create an audience.
        """
        self._create_audience()

    def _create_audience(self):
        url = "{}{}".format(self.host, "/api/v4/audiences")

        payload = {
            'desc': 'My New audience', # Replace with the audience's name.
            'country_codes': ['US', 'CA', 'MX'], # Replace with the desired country codes.
            'external_id': 'NorthAmerica', # Replace with the audience's external ID.
            'match_type': 'ANY' # Determines when a viewer qualifies for this audience.            
        }

        headers = {'Content-Type': 'application/json'}

        response = requests.post(
            url, params=APIParams(APICredentials()).get_params({}), data=json.dumps(payload), headers=headers 
        )

        print(response.json())

Audience().run()