示例#1
0
文件: base.py 项目: Seraf/fiblary
    def list(self, **kwargs):
        _logger.debug(self.RESOURCE)
        _logger.debug(type(self))

        # Pop jsonpath if exists and pass the rest of arguments to API
        # for some API calls home center handles additional parameters

        json_path = kwargs.pop('jsonpath', None)

        # Home center ignores unknown parameters so there is no need to
        # remove them from REST request.
        try:
            items = self.http_client.get(self.RESOURCE, params=kwargs).json()
        except exceptions.ConnectionError:
            return

        # if there is no explicit defined json_path parameters
        if json_path is None:
            for value in self.API_PARAMS:
                kwargs.pop(value, None)

            condition_expression = ""
            for k, v in six.iteritems(kwargs):
                if k.startswith('p_'):  # search for properties
                    k = "properties." + k[2:]
                condition_expression += self.JSON_CONDITION_BASE.format(
                    k,
                    quote_if_string(v))
                condition_expression += " and "

            if condition_expression is not "":
                # filter the results with json implicit built from
                # remaining parameters

                json_path = "$[?({})]".format(condition_expression[:-5])
            _logger.debug("Implicit JSON Path: {}".format(json_path))

        if json_path:
            _logger.debug("JSON Path: {}".format(json_path))
            filtered_items = jsonpath.jsonpath(items, json_path)
            if filtered_items:
                items = filtered_items
            else:
                return

        # in case there is only one item
        if not isinstance(items, list):
            items = [items]
        for item in items:
            item_obj = self.model(item)
            if item_obj:
                yield item_obj
            else:
                continue
示例#2
0
文件: base.py 项目: Seraf/fiblary
    def list(self, **kwargs):
        _logger.debug(self.RESOURCE)
        _logger.debug(type(self))

        # Pop jsonpath if exists and pass the rest of arguments to API
        # for some API calls home center handles additional parameters

        json_path = kwargs.pop('jsonpath', None)

        # Home center ignores unknown parameters so there is no need to
        # remove them from REST request.
        try:
            items = self.http_client.get(self.RESOURCE, params=kwargs).json()
        except exceptions.ConnectionError:
            return

        # if there is no explicit defined json_path parameters
        if json_path is None:
            for value in self.API_PARAMS:
                kwargs.pop(value, None)

            condition_expression = ""
            for k, v in six.iteritems(kwargs):
                if k.startswith('p_'):  # search for properties
                    k = "properties." + k[2:]
                condition_expression += self.JSON_CONDITION_BASE.format(
                    k, quote_if_string(v))
                condition_expression += " and "

            if condition_expression is not "":
                # filter the results with json implicit built from
                # remaining parameters

                json_path = "$[?({})]".format(condition_expression[:-5])
            _logger.debug("Implicit JSON Path: {}".format(json_path))

        if json_path:
            _logger.debug("JSON Path: {}".format(json_path))
            filtered_items = jsonpath.jsonpath(items, json_path)
            if filtered_items:
                items = filtered_items
            else:
                return

        # in case there is only one item
        if not isinstance(items, list):
            items = [items]
        for item in items:
            item_obj = self.model(item)
            if item_obj:
                yield item_obj
            else:
                continue
示例#3
0
文件: base.py 项目: timmo-d/fiblary
    def list(self, **kwargs):
        """
        :param kwargs: This is a dictionary of parameters passed to GET
        :type kwargs:
        :return: Returns an iterator
        :rtype: iterator function
        """
        _logger.debug(self.RESOURCE)
        _logger.debug(type(self))
        _logger.debug(kwargs)

        # Pop jsonpath if exists and pass the rest of arguments to API
        # for some API calls home center handles additional parameters

        json_path = kwargs.pop('jsonpath', None)

        # Home center ignores unknown parameters so there is no need to
        # remove them from REST request.
        items = self.http_client.get(self.RESOURCE, params=kwargs).json()

        # if there is no explicit defined json_path parameters
        if json_path is None:
            for value in self.API_PARAMS:
                kwargs.pop(value, None)

            condition_expression = ""
            for k, v in six.iteritems(kwargs):
                if k.startswith('p_'):  # search for properties
                    k = "properties." + k[2:]
                condition_expression += self.JSON_CONDITION_BASE.format(
                    k, quote_if_string(v))
                condition_expression += " and "

            if condition_expression is not "":
                # filter the results with json implicit built from
                # remaining parameters

                json_path = "$[?({})]".format(condition_expression[:-5])
            _logger.debug("Implicit JSON Path: {}".format(json_path))

        if json_path:
            _logger.debug("JSON Path: {}".format(json_path))
            filtered_items = jsonpath.jsonpath(items, json_path)
            if filtered_items:
                items = filtered_items
            else:
                items = []

        # in case there is only one item
        items = items if isinstance(items, list) else [items]
        return ifilterfalse(lambda i: i is None, imap(self.model, items))
示例#4
0
文件: base.py 项目: kstaniek/fiblary
    def list(self, **kwargs):
        """
        :param kwargs: This is a dictionary of parameters passed to GET
        :type kwargs:
        :return: Returns an iterator
        :rtype: iterator function
        """
        _logger.debug(self.RESOURCE)
        _logger.debug(type(self))
        _logger.debug(kwargs)

        # Pop jsonpath if exists and pass the rest of arguments to API
        # for some API calls home center handles additional parameters

        json_path = kwargs.pop("jsonpath", None)

        # Home center ignores unknown parameters so there is no need to
        # remove them from REST request.
        items = self.http_client.get(self.RESOURCE, params=kwargs).json()

        # if there is no explicit defined json_path parameters
        if json_path is None:
            for value in self.API_PARAMS:
                kwargs.pop(value, None)

            condition_expression = ""
            for k, v in six.iteritems(kwargs):
                if k.startswith("p_"):  # search for properties
                    k = "properties." + k[2:]
                condition_expression += self.JSON_CONDITION_BASE.format(k, quote_if_string(v))
                condition_expression += " and "

            if condition_expression is not "":
                # filter the results with json implicit built from
                # remaining parameters

                json_path = "$[?({})]".format(condition_expression[:-5])
            _logger.debug("Implicit JSON Path: {}".format(json_path))

        if json_path:
            _logger.debug("JSON Path: {}".format(json_path))
            filtered_items = jsonpath.jsonpath(items, json_path)
            if filtered_items:
                items = filtered_items
            else:
                items = []

        # in case there is only one item
        items = items if isinstance(items, list) else [items]
        return ifilterfalse(lambda i: i is None, imap(self.model, items))