def find(self, cls, filters=None, sort=None, limit=None): """Find objects by filters @param cls: The class of the object to search for @type cls: class or str @param filters: An Optional array of tuples for the filters like [["description", "!=", "foo"], ['name', '=', ['bar', 'biz', 'fizzle']]] @type filters: list @param sort: Optional param to sort on @type sort: str @param limit: Optional limit to how many results are fetched @type limit: int """ if type(cls) == str: class_name = cls cls = xmlize.get_class(class_name) else: class_name = cls.__name__ url = "/%s%s" % (self.routes[class_name], self._build_query(filters, sort, limit)) resp = self.request("GET", url) return xmlize.loads(resp.read())
def get_by_id(self, cls, id): """Get an object by ID @param cls: The class of the object to fetch @type cls: class or str @param id: The ID of the object to fetch @type id: str """ assert len(id) > 0 if type(cls) == str: class_name = cls cls = xmlize.get_class(class_name) else: class_name = cls.__name__ url = "%s/%s" % (self.routes[class_name], id) resp = self.request("GET", url) return xmlize.loads(resp.read())