
from service import Service


class UserData(Service):

    endpoint = 'api.tags.bluekai.com'
    path = '/getdata/{site_id}/v1.2'

    def send(self, site_id, phints={}, **params):
        return self.common_call(site_id, phints, 0, **params)

    def get(self, site_id, phints={}, **params):
        return self.common_call(site_id, phints, 1, **params)

    def common_call(self, site_id, phints, target, **params):

        # Are we sending or receving data?
        params.update({'target': target})

        # Create phints
        if len(phints) > 0:
            mapped_phints = {"phint": ["=".join([k, v]) for k, v in phints.iteritems()]}
            params.update(mapped_phints)

        return self._get(self.path.format(site_id=site_id), **params)
