Ejemplo n.º 1
0
    def iter(self):
        """Gets all resources, automating paging through data

        Returns:
            iterable of object: Iterable of resource objects
        """

        page = 1
        fetch_all = True
        url = "{}/{}".format(__endpoint__, self.type.RESOURCE)

        if 'page' in self.params:
            page = self.params['page']
            fetch_all = False

        response = RestClient.get(url, self.params)[self.type.RESOURCE]
        while len(response):
            for item in response:
                yield self.type(item)

            if not fetch_all:
                break
            else:
                page += 1
                self.where(page=page)
            response = RestClient.get(url, self.params)[self.type.RESOURCE]
Ejemplo n.º 2
0
    def all(self):
        """Get all resources, automatically paging through data

        Returns:
            list of object: List of resource objects
        """
        list = []
        page = 1
        fetch_all = True
        url = "{}/{}".format(__endpoint__, self.type.RESOURCE)

        if 'page' in self.params:
            page = self.params['page']
            fetch_all = False

        while True:
            response = RestClient.get(url, self.params)[self.type.RESOURCE]
            if len(response) > 0:
                for item in response:
                    list.append(self.type(item))

                if not fetch_all:
                    break
                else:
                    page += 1
                    self.where(page=page)
            else:
                break

        return list
Ejemplo n.º 3
0
    def array(self):
        """Get all resources and return the result as an array

        Returns:
            array of str: Array of resources
        """
        url = "{}/{}".format(__endpoint__, self.type.RESOURCE)
        return RestClient.get(url, self.params)[self.type.RESOURCE]
    def array(self):
        """Get all resources and return the result as an array

        Returns:
            array of str: Array of resources
        """
        url = "{}/{}".format(__endpoint__, self.type.RESOURCE)
        return RestClient.get(url, self.params)[self.type.RESOURCE]
Ejemplo n.º 5
0
 def find(self, id):
     """Get a resource by its id
     
     Args:
         id (string): Resource id    
     Returns:
         object: Instance of the resource type
     """
     url = "{}/{}/{}".format(__endpoint__, self.type.RESOURCE, id)
     response = RestClient.get(url)[self.type.RESOURCE[:-1]]
     return self.type(response)
Ejemplo n.º 6
0
    def find_many(self, url, type, resource):
        """Get a list of resources

        Args:
            url (string): URL to invoke
            type (class): Class type
            resource (string): The REST Resource
        Returns:
            list of object: List of resource instances
        """
        return [type(item) for item in RestClient.get(url)[resource]]
 def find(self, id):
     """Get a resource by its id
     
     Args:
         id (string): Resource id    
     Returns:
         object: Instance of the resource type
     """
     url = "{}/{}/{}".format(__endpoint__, self.type.RESOURCE, id)
     response = RestClient.get(url)[self.type.RESOURCE[:-1]]
     return self.type(response)
Ejemplo n.º 8
0
    def find_many(self, url, type, resource):
        """Get a list of resources
        
        Args:
            url (string): URL to invoke
            type (class): Class type
            resource (string): The REST Resource
        Returns:
            list of object: List of resource instances
        """
        list = []
        response = RestClient.get(url)[resource]
        if len(response) > 0:
            for item in response:
                list.append(type(item))

        return list
    def find_many(self, url, type, resource):
        """Get a list of resources
        
        Args:
            url (string): URL to invoke
            type (class): Class type
            resource (string): The REST Resource
        Returns:
            list of object: List of resource instances
        """
        list = []
        response = RestClient.get(url)[resource]
        if (len(response) > 0):
            for item in response:
                list.append(type(item))

        return list