# coding: utf-8

"""
    Klaviyo API

    Empowering creators to own their destiny  # noqa: E501

    OpenAPI spec version: 2021.11.26
    
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""

from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

# retry imports
from custom_retry import retry_if_qualifies
import tenacity


from swagger_client.api_client import ApiClient


class TrackIdentifyApi(object):
    """NOTE: This class is auto generated by the swagger code generator program.

    Do not edit the class manually.
    Ref: https://github.com/swagger-api/swagger-codegen
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client
        self.warned = []

    def identify_get(self, data, **kwargs):  # noqa: E501
        """Identify Profile  # noqa: E501

        This endpoint is also used to identify a profile and update its properties without an associated event. It takes as input the same payload as the above POST request, but as a base64-encoded string passed as a query parameter. NOTE: This is offered for backwards compatibility; we recommend all new implementations use the POST approach above.    **EXAMPLE:**      ```   {       \"token\": \"PUBLIC_KEY\",       \"properties\": {         \"$email\": \"abraham.lincoln@klaviyo.com\",         \"$first_name\": \"Abraham\",         \"$last_name\": \"Lincoln\",         \"$city\": \"Springfield\",         \"$region\": \"Illinois\"       }   }   ```   Gets encoded into the following string, which is passed into the `data` parameter:    `eyJ0b2tlbiI6ICJQVUJMSUNfS0VZIiwicHJvcGVydGllcyI6IHsiJGVtYWlsIjogImFicmFoYW0ubGluY29sbkBrbGF2aXlvLmNvbSIsIiRmaXJzdF9uYW1lIjogIkFicmFoYW0iLCIkbGFzdF9uYW1lIjogIkxpbmNvbG4iLCIkY2l0eSI6ICJTcHJpbmdmaWVsZCIsIiRyZWdpb24iOiAiSWxsaW5vaXMifX0K`       # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.identify_get(data, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str data: String representation of base64 encoded JSON object (required)
        :return: str
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.identify_get_with_http_info(data, **kwargs)  # noqa: E501
        else:
            (data) = self.identify_get_with_http_info(data, **kwargs)  # noqa: E501
            return data

    def identify_get_with_http_info(self, data, **kwargs):  # noqa: E501
        """Identify Profile  # noqa: E501

        This endpoint is also used to identify a profile and update its properties without an associated event. It takes as input the same payload as the above POST request, but as a base64-encoded string passed as a query parameter. NOTE: This is offered for backwards compatibility; we recommend all new implementations use the POST approach above.    **EXAMPLE:**      ```   {       \"token\": \"PUBLIC_KEY\",       \"properties\": {         \"$email\": \"abraham.lincoln@klaviyo.com\",         \"$first_name\": \"Abraham\",         \"$last_name\": \"Lincoln\",         \"$city\": \"Springfield\",         \"$region\": \"Illinois\"       }   }   ```   Gets encoded into the following string, which is passed into the `data` parameter:    `eyJ0b2tlbiI6ICJQVUJMSUNfS0VZIiwicHJvcGVydGllcyI6IHsiJGVtYWlsIjogImFicmFoYW0ubGluY29sbkBrbGF2aXlvLmNvbSIsIiRmaXJzdF9uYW1lIjogIkFicmFoYW0iLCIkbGFzdF9uYW1lIjogIkxpbmNvbG4iLCIkY2l0eSI6ICJTcHJpbmdmaWVsZCIsIiRyZWdpb24iOiAiSWxsaW5vaXMifX0K`       # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.identify_get_with_http_info(data, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str data: String representation of base64 encoded JSON object (required)
        :return: str
                 If the method is called asynchronously,
                 returns the request thread.
        """


        all_params = ['data']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method identify_get" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'data' is set
        if ('data' not in params or
                params['data'] is None):
            raise ValueError("Missing the required parameter `data` when calling `identify_get`")  # noqa: E501

        collection_formats = {}

        path_params = {}

        query_params = []
        if 'data' in params:
            query_params.append(('data', params['data']))  # noqa: E501

        header_params = {}


        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['text/html'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/identify', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='str',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def identify_post(self, **kwargs):  # noqa: E501
        """Identify Profile  # noqa: E501

        This endpoint is used to track and update properties about an individual without tracking an associated event. The following data is stored in a JSON object.     **JSON OBJECT STRUCTURE:**    __token: *string*__   This is your public API key.      __properties: *JSON Object or null*__   Properties of the profile to track/update. You must identify the person by their email using a $email key (or by their phone number using a `$phone_number` key if you have SMS-only contacts). Other than that, you can include any data you want and it can then be used to create segments of people. For example, if you wanted to create a list of people on trial plans, include a person's plan type in this JSON object so you can use that information later.         **SPECIAL FIELDS:**    The Klaviyo CRM has the following special fields you can set for customer **properties** with the **Identify** endpoint, to unlock additional functionality:      **$email:** _string_   **$first_name:** _string_   **$last_name:** _string_   **$phone_number:** _string; eg: \"+13239169023\"_   **$city:** _string_   **$region:** _string; state, or other region_   **$country:** _string_   **$zip:** _string_   **$image:** _string; url to a photo of a person_   **$consent:** _list of strings; eg: ['sms', 'email', 'web', 'directmail', 'mobile']_         **EXAMPLE:**      ```   {       \"token\": \"PUBLIC_KEY\",       \"properties\": {         \"$email\": \"abraham.lincoln@klaviyo.com\",         \"$first_name\": \"Abraham\",         \"$last_name\": \"Lincoln\",         \"$city\": \"Springfield\",         \"$region\": \"Illinois\"       }   }      # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.identify_post(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str data:
        :return: str
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.identify_post_with_http_info(**kwargs)  # noqa: E501
        else:
            (data) = self.identify_post_with_http_info(**kwargs)  # noqa: E501
            return data

    def identify_post_with_http_info(self, **kwargs):  # noqa: E501
        """Identify Profile  # noqa: E501

        This endpoint is used to track and update properties about an individual without tracking an associated event. The following data is stored in a JSON object.     **JSON OBJECT STRUCTURE:**    __token: *string*__   This is your public API key.      __properties: *JSON Object or null*__   Properties of the profile to track/update. You must identify the person by their email using a $email key (or by their phone number using a `$phone_number` key if you have SMS-only contacts). Other than that, you can include any data you want and it can then be used to create segments of people. For example, if you wanted to create a list of people on trial plans, include a person's plan type in this JSON object so you can use that information later.         **SPECIAL FIELDS:**    The Klaviyo CRM has the following special fields you can set for customer **properties** with the **Identify** endpoint, to unlock additional functionality:      **$email:** _string_   **$first_name:** _string_   **$last_name:** _string_   **$phone_number:** _string; eg: \"+13239169023\"_   **$city:** _string_   **$region:** _string; state, or other region_   **$country:** _string_   **$zip:** _string_   **$image:** _string; url to a photo of a person_   **$consent:** _list of strings; eg: ['sms', 'email', 'web', 'directmail', 'mobile']_         **EXAMPLE:**      ```   {       \"token\": \"PUBLIC_KEY\",       \"properties\": {         \"$email\": \"abraham.lincoln@klaviyo.com\",         \"$first_name\": \"Abraham\",         \"$last_name\": \"Lincoln\",         \"$city\": \"Springfield\",         \"$region\": \"Illinois\"       }   }      # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.identify_post_with_http_info(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str data:
        :return: str
                 If the method is called asynchronously,
                 returns the request thread.
        """


        all_params = ['data']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method identify_post" % key
                )
            params[key] = val
        del params['kwargs']

        collection_formats = {}

        path_params = {}

        query_params = []

        header_params = {}


        form_params = []
        local_var_files = {}
        if 'data' in params:
            form_params.append(('data', params['data']))  # noqa: E501

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['text/html'])  # noqa: E501

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.select_header_content_type(  # noqa: E501
            ['application/x-www-form-urlencoded'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/identify', 'POST',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='str',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def track_get(self, data, **kwargs):  # noqa: E501
        """Track Profile Activity  # noqa: E501

        This endpoint is also used to track a profile's activity. It takes as input the same payload as the above POST request, but as a base64-encoded string passed as a query parameter. NOTE: This is offered for backwards compatibility; we recommend all new implementations use the POST approach above.      **EXAMPLE:**      ```   {     \"token\": \"PUBLIC_KEY\",     \"event\": \"Ordered Product\",     \"customer_properties\": {       \"$email\": \"abraham.lincoln@klaviyo.com\"     },     \"properties\": {       \"item_name\": \"Boots\",       \"$value\": 100     }   }    ```   Gets encoded into the following string, which is passed into the `data` parameter:    `eyJ0b2tlbiI6ICJQVUJMSUNfS0VZIiwiZXZlbnQiOiAiT3JkZXJlZEl0ZW0iLCJjdXN0b21lcl9wcm9wZXJ0aWVzIjogeyIkZW1haWwiOiAiYWJyYWhhbS5saW5jb2xuQGtsYXZpeW8uY29tIn0sInByb3BlcnRpZXMiOiB7Iml0ZW1fbmFtZSI6ICJCb290cyIsIiR2YWx1ZSI6IDEwMH19`   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.track_get(data, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str data: String representation of base64 encoded JSON object (required)
        :return: str
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.track_get_with_http_info(data, **kwargs)  # noqa: E501
        else:
            (data) = self.track_get_with_http_info(data, **kwargs)  # noqa: E501
            return data

    def track_get_with_http_info(self, data, **kwargs):  # noqa: E501
        """Track Profile Activity  # noqa: E501

        This endpoint is also used to track a profile's activity. It takes as input the same payload as the above POST request, but as a base64-encoded string passed as a query parameter. NOTE: This is offered for backwards compatibility; we recommend all new implementations use the POST approach above.      **EXAMPLE:**      ```   {     \"token\": \"PUBLIC_KEY\",     \"event\": \"Ordered Product\",     \"customer_properties\": {       \"$email\": \"abraham.lincoln@klaviyo.com\"     },     \"properties\": {       \"item_name\": \"Boots\",       \"$value\": 100     }   }    ```   Gets encoded into the following string, which is passed into the `data` parameter:    `eyJ0b2tlbiI6ICJQVUJMSUNfS0VZIiwiZXZlbnQiOiAiT3JkZXJlZEl0ZW0iLCJjdXN0b21lcl9wcm9wZXJ0aWVzIjogeyIkZW1haWwiOiAiYWJyYWhhbS5saW5jb2xuQGtsYXZpeW8uY29tIn0sInByb3BlcnRpZXMiOiB7Iml0ZW1fbmFtZSI6ICJCb290cyIsIiR2YWx1ZSI6IDEwMH19`   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.track_get_with_http_info(data, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str data: String representation of base64 encoded JSON object (required)
        :return: str
                 If the method is called asynchronously,
                 returns the request thread.
        """


        all_params = ['data']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method track_get" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'data' is set
        if ('data' not in params or
                params['data'] is None):
            raise ValueError("Missing the required parameter `data` when calling `track_get`")  # noqa: E501

        collection_formats = {}

        path_params = {}

        query_params = []
        if 'data' in params:
            query_params.append(('data', params['data']))  # noqa: E501

        header_params = {}


        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['text/html'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/track', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='str',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def track_post(self, **kwargs):  # noqa: E501
        """Track Profile Activity  # noqa: E501

        This endpoint is used to track a profile's activity. The following data is encoded in a JSON object. NOTE: an account can have up to 200 unique metrics (event types). This endpoint can accept payloads up to approximately 1MB.     **JSON OBJECT STRUCTURE:**    __token: *string*__   This is your public API key.      __event: *string*__   Name of the event you want to track.       __customer_properties: *JSON Object or null*__   Properties of the profile that triggered this event. You must identify the person by their email using a $email key (or by their phone number using a `$phone_number` key if you have SMS-only contacts). Other than that, you can include any data you want and it can then be used to create segments of people. For example, if you wanted to create a list of people on trial plans, include a person's plan type in this JSON object so you can use that information later.      __properties: *optional; JSON Object or null*__   Properties of this event. Any properties included here can be used for creating segments later For example, if you track an event called \"Ordered Product\" you could include a property for item type (e.g. image, article, etc.), size, etc.    __time: *optional; 10-digit UNIX timestamp or null*__   When this event occurred. By default, Klaviyo assumes events happen when a request is made. If you'd like to track an event that happened in past, use this property.         **SPECIAL FIELDS:**      The Klaviyo CRM has the following special fields you can set for **customer_properties** with the **Track** endpoint, to unlock additional functionality:      **$email:** _string_   **$first_name:** _string_   **$last_name:** _string_   **$phone_number:** _string; eg: \"+13239169023\"_   **$city:** _string_   **$region:** _string; state, or other region_   **$country:** _string_   **$zip:** _string_   **$image:** _string; url to a photo of a person_   **$consent:** _list of strings; eg: ['sms', 'email', 'web', 'directmail', 'mobile']_      You can also set the following special fields in event **properties** with the **Track** endpoint:      **$event_id:** _a unique identifier for an event_   **$value:** _a numeric value to associate with this event (e.g. the dollar value of a purchase)_      **EXAMPLE:**      ```   {     \"token\": \"PUBLIC_KEY\",     \"event\": \"Ordered Product\",     \"customer_properties\": {       \"$email\": \"abraham.lincoln@klaviyo.com\"     },     \"properties\": {       \"item_name\": \"Boots\",       \"$value\": 100     }   }   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.track_post(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str data:
        :return: str
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.track_post_with_http_info(**kwargs)  # noqa: E501
        else:
            (data) = self.track_post_with_http_info(**kwargs)  # noqa: E501
            return data

    def track_post_with_http_info(self, **kwargs):  # noqa: E501
        """Track Profile Activity  # noqa: E501

        This endpoint is used to track a profile's activity. The following data is encoded in a JSON object. NOTE: an account can have up to 200 unique metrics (event types). This endpoint can accept payloads up to approximately 1MB.     **JSON OBJECT STRUCTURE:**    __token: *string*__   This is your public API key.      __event: *string*__   Name of the event you want to track.       __customer_properties: *JSON Object or null*__   Properties of the profile that triggered this event. You must identify the person by their email using a $email key (or by their phone number using a `$phone_number` key if you have SMS-only contacts). Other than that, you can include any data you want and it can then be used to create segments of people. For example, if you wanted to create a list of people on trial plans, include a person's plan type in this JSON object so you can use that information later.      __properties: *optional; JSON Object or null*__   Properties of this event. Any properties included here can be used for creating segments later For example, if you track an event called \"Ordered Product\" you could include a property for item type (e.g. image, article, etc.), size, etc.    __time: *optional; 10-digit UNIX timestamp or null*__   When this event occurred. By default, Klaviyo assumes events happen when a request is made. If you'd like to track an event that happened in past, use this property.         **SPECIAL FIELDS:**      The Klaviyo CRM has the following special fields you can set for **customer_properties** with the **Track** endpoint, to unlock additional functionality:      **$email:** _string_   **$first_name:** _string_   **$last_name:** _string_   **$phone_number:** _string; eg: \"+13239169023\"_   **$city:** _string_   **$region:** _string; state, or other region_   **$country:** _string_   **$zip:** _string_   **$image:** _string; url to a photo of a person_   **$consent:** _list of strings; eg: ['sms', 'email', 'web', 'directmail', 'mobile']_      You can also set the following special fields in event **properties** with the **Track** endpoint:      **$event_id:** _a unique identifier for an event_   **$value:** _a numeric value to associate with this event (e.g. the dollar value of a purchase)_      **EXAMPLE:**      ```   {     \"token\": \"PUBLIC_KEY\",     \"event\": \"Ordered Product\",     \"customer_properties\": {       \"$email\": \"abraham.lincoln@klaviyo.com\"     },     \"properties\": {       \"item_name\": \"Boots\",       \"$value\": 100     }   }   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.track_post_with_http_info(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str data:
        :return: str
                 If the method is called asynchronously,
                 returns the request thread.
        """


        all_params = ['data']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method track_post" % key
                )
            params[key] = val
        del params['kwargs']

        collection_formats = {}

        path_params = {}

        query_params = []

        header_params = {}


        form_params = []
        local_var_files = {}
        if 'data' in params:
            form_params.append(('data', params['data']))  # noqa: E501

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['text/html'])  # noqa: E501

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.select_header_content_type(  # noqa: E501
            ['application/x-www-form-urlencoded'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/track', 'POST',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='str',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)
