How to use the keen.utilities.headers function in keen

To help you get started, we’ve selected a few keen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github keenlabs / KeenClient-Python / keen / api.py View on Github external
def update_access_key_full(self, access_key_id, name, is_active, permitted, options):
        """
        Replaces the 'name', 'is_active', 'permitted', and 'options' values of a given key.
        A master key must be set first.

        :param access_key_id: the 'key' value of the access key for which the values will be replaced
        :param name: the new name desired for this access key
        :param is_active: whether the key should become enabled (True) or revoked (False)
        :param permitted: the new list of permissions desired for this access key
        :param options: the new dictionary of options for this access key
        """
        url = "{0}/{1}/projects/{2}/keys/{3}".format(self.base_url, self.api_version,
                                                     self.project_id, access_key_id)
        headers = utilities.headers(self.master_key)
        payload_dict = {
            "name": name,
            "is_active": is_active,
            "permitted": permitted,
            "options": options
        }
        payload = json.dumps(payload_dict)
        response = self.fulfill(HTTPMethods.POST, url, data=payload, headers=headers, timeout=self.get_timeout)
        self._error_handling(response)
        return response.json()
github keenlabs / KeenClient-Python / keen / api.py View on Github external
def get_access_key(self, access_key_id):
        """
        Returns details on a particular access key. A master key must be set first.

        :param access_key_id: the 'key' value of the access key to retreive data from
        """
        url = "{0}/{1}/projects/{2}/keys/{3}".format(self.base_url, self.api_version, self.project_id,
                                                     access_key_id)
        headers = utilities.headers(self.master_key)
        response = self.fulfill(HTTPMethods.GET, url, headers=headers, timeout=self.get_timeout)
        self._error_handling(response)

        return response.json()
github keenlabs / KeenClient-Python / keen / cached_datasets.py View on Github external
def _get_json(self, http_method, url, key, *args, **kwargs):
        response = self.api.fulfill(
            http_method,
            url,
            headers=headers(key),
            *args,
            **kwargs)

        self.api._error_handling(response)

        try:
            response = response.json()
        except ValueError:
            response = "No JSON available."

        return response
github keenlabs / KeenClient-Python / keen / api.py View on Github external
def list_access_keys(self):
        """
        Returns a list of all access keys in this project. A master key must be set first.
        """
        url = "{0}/{1}/projects/{2}/keys".format(self.base_url, self.api_version, self.project_id)
        headers = utilities.headers(self.master_key)
        response = self.fulfill(HTTPMethods.GET, url, headers=headers, timeout=self.get_timeout)
        self._error_handling(response)

        return response.json()
github keenlabs / KeenClient-Python / keen / api.py View on Github external
def post_events(self, events):

        """
        Posts a single event to the Keen IO API. The write key must be set first.

        :param events: an Event to upload
        """

        url = "{0}/{1}/projects/{2}/events".format(self.base_url, self.api_version,
                                                   self.project_id)
        headers = utilities.headers(self.write_key)
        payload = json.dumps(events)
        response = self.fulfill(HTTPMethods.POST, url, data=payload, headers=headers, timeout=self.post_timeout)
        self._error_handling(response)
        return self._get_response_json(response)