コード例 #1
0
    def batch_unclaim(self, unclaims: Union[List[Dict[str, Any]],
                                            List[Tuple[str, str]]]):
        """ Batch unclaims of owner-object combination

        https://smartobjects.mnubo.com/documentation/api_ingestion.html#post-api-v3-owners-unclaim-batch

        :param unclaims:
            the unclaims argument can either a fully constructed batch-unclaim object as specified in the documentation
            or a list of pair (username, deviceId)
        :return: list of Result objects with the status of each operation

        Example:
        >>> client.owners.unclaim([{ "x_device_id": "object1", "username": "******", "x_timestamp": "2015-01-22T00:01:25-02:00" }, { "x_device_id": "object2", "username": "******" }])
        or
        >>> client.owners.unclaim([("usertest1","object1"), ("usertest2", "object2")])
        """
        if isinstance(unclaims, list) and all([
                isinstance(unclaim, tuple) and len(unclaim) == 2
                for unclaim in unclaims
        ]):
            # transform a list of (user, device) pair to a unclaim dictionary
            unclaims = list(
                map(
                    lambda claim: {
                        "username": claim[0],
                        "x_device_id": claim[1]
                    }, unclaims))

        [self._validate_claim(unclaim) for unclaim in unclaims]

        r = self.api_manager.post(f'{self.api_version}/owners/unclaim',
                                  unclaims)
        return [Result(**result) for result in r.json()]
コード例 #2
0
    def create_update(self, owners: List[Dict[str, str]]):
        """ Create or update a batch of owners at once

        https://smartobjects.mnubo.com/documentation/api_ingestion.html#put-api-v3-owners-batch

        :param owners: list of owners to be sent to the smartobjects platform. If the owner already exists, it will be
            updated with the new content, otherwise it will be created
        :return: list of Result objects with the status of each operation
        """
        [self._validate_owner(owner) for owner in owners]

        r = self.api_manager.put(f'{self.api_version}/owners', owners)
        return [Result(**result) for result in r.json()]
コード例 #3
0
    def create_update(self, objects: List[Dict[str, Any]]) -> List[Result]:
        """ create or update a batch of objects

        https://smartobjects.mnubo.com/documentation/api_ingestion.html#put-api-v3-objects-batch
        a single batch can contain up to 1000 objects.

        :param objects: list of objects to be sent to smartobjects. If the object already exists, it will be
            updated with the new content, otherwise it will be created
        :return: list of Result objects with the status of each operations
        """
        [self._validate_object(obj, validate_object_type=False) for obj in objects]
        r = self.api_manager.put(f'{self.api_version}/objects', objects)
        return [Result(**result) for result in r.json()]
コード例 #4
0
    def batch_claim(self, claims):
        """ Batch claims of owner to object

        https://smartobjects.mnubo.com/apps/doc/api_ingestion.html#post-api-v3-owners-claim-batch

        :param claims:
            the claims argument can either a fully constructed batch-claim object as specified in the documentation
            or a list of pair (username, deviceId)
        :return: list of Result objects with the status of each operation

        Example:
        >>> client.owners.claim([{ "x_device_id": "object1", "username": "******", "x_timestamp": "2015-01-22T00:01:25-02:00" }, { "x_device_id": "object2", "username": "******" }])
        or
        >>> client.owners.claim([("usertest1","object1"), ("usertest2", "object2")])
        """
        if isinstance(claims, list) and all([isinstance(claim, tuple) and len(claim) == 2 for claim in claims]):
            # transform a list of (user, device) pair to a claim dictionary
            claims = list(map(lambda claim: {"username": claim[0], "x_device_id": claim[1]}, claims))

        [self._validate_claim(claim) for claim in claims]

        r = self.api_manager.post('owners/claim', claims)
        return [Result(**result) for result in r.json()]