예제 #1
0
    def unicode_urlencode(self, params):
        """
        Convert lists to JSON encoded strings, and correctly handle any
        unicode URL parameters.
        """
        if isinstance(params, dict):
            params = list(six.iteritems(params))
        for i, param in enumerate(params):
            if isinstance(param[1], list):
                params[i] = (param[0], json.dumps(param[1]),)

        return urlencode(
            [(_tobytes(k), _tobytes(v)) for k, v in params]
        )
예제 #2
0
    def unicode_urlencode(self, params):
        """
        Convert lists to JSON encoded strings, and correctly handle any
        unicode URL parameters.
        """
        if isinstance(params, dict):
            params = list(six.iteritems(params))
        for i, param in enumerate(params):
            if isinstance(param[1], list):
                params[i] = (param[0], json.dumps(param[1]),)

        return urlencode(
            [(_tobytes(k), _tobytes(v)) for k, v in params]
        )
예제 #3
0
    def _hash_args(self, args, secret=None):
        """
        Hashes arguments by joining key=value pairs, appending the api_secret, and
        then taking the MD5 hex digest.
        """
        for arg in args:
            if isinstance(args[arg], list):
                args[arg] = json.dumps(args[arg])

        arg_strings = ["{}={}".format(arg, args[arg]) for arg in sorted(args.keys())]
        args_joined_string = ''.join(arg_strings)
        args_joined = _tobytes(args_joined_string)

        hash = hashlib.md5(args_joined)

        if secret:
            hash.update(_tobytes(secret))
        elif self.client.api_secret:
            hash.update(_tobytes(self.client.api_secret))
        return hash.hexdigest()
예제 #4
0
 def authenticate(self, url, params):
     """
     returns a request object ready to be issued to the Mixpanel API
     """
     request_url = '{base_url}?{encoded_params}'.format(
         base_url=url,
         encoded_params=_unicode_urlencode(params)
     )
     request_headers = {
         'Authorization': 'Basic ' + _totext(base64.standard_b64encode(_tobytes("{}:".format(self.client.api_secret))))
     }
     return url_request.Request(request_url, headers=request_headers)
예제 #5
0
    def hash_args(self, args, secret=None):
        """
        Hashes arguments by joining key=value pairs, appending the api_secret, and
        then taking the MD5 hex digest.
        """
        for a in args:
            if isinstance(args[a], list):
                args[a] = json.dumps(args[a])

        args_joined = six.b('')
        for a in sorted(args.keys()):
            args_joined += _tobytes(a)
            args_joined += six.b('=')
            args_joined += _tobytes(args[a])

        hash = hashlib.md5(args_joined)

        if secret:
            hash.update(_tobytes(secret))
        elif self.api_secret:
            hash.update(_tobytes(self.api_secret))
        return hash.hexdigest()
예제 #6
0
 def authenticate(self, url, params):
     """
     returns a request object ready to be issued to the Mixpanel API
     """
     request_url = '{base_url}?{encoded_params}'.format(
         base_url=url, encoded_params=_unicode_urlencode(params))
     request_headers = {
         'Authorization':
         'Basic ' + _totext(
             base64.standard_b64encode(
                 _tobytes("{}:".format(self.client.api_secret))))
     }
     return url_request.Request(request_url, headers=request_headers)
예제 #7
0
    def _hash_args(self, args, secret=None):
        """
        Hashes arguments by joining key=value pairs, appending the api_secret, and
        then taking the MD5 hex digest.
        """
        for arg in args:
            if isinstance(args[arg], list):
                args[arg] = json.dumps(args[arg])

        arg_strings = [
            "{}={}".format(arg, args[arg]) for arg in sorted(args.keys())
        ]
        args_joined_string = ''.join(arg_strings)
        args_joined = _tobytes(args_joined_string)

        hash = hashlib.md5(args_joined)

        if secret:
            hash.update(_tobytes(secret))
        elif self.client.api_secret:
            hash.update(_tobytes(self.client.api_secret))
        return hash.hexdigest()
예제 #8
0
    def hash_args(self, args, secret=None):
        """
        Hashes arguments by joining key=value pairs, appending the api_secret, and
        then taking the MD5 hex digest.
        """
        for a in args:
            if isinstance(args[a], list):
                args[a] = json.dumps(args[a])

        args_joined = six.b('')
        for a in sorted(args.keys()):
            args_joined += _tobytes(a)
            args_joined += six.b('=')
            args_joined += _tobytes(args[a])

        hash = hashlib.md5(args_joined)

        if secret:
            hash.update(_tobytes(secret))
        elif self.client.api_secret:
            hash.update(_tobytes(self.client.api_secret))
        return hash.hexdigest()