コード例 #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]
コード例 #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
コード例 #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]
コード例 #4
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]
コード例 #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)
コード例 #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]]
コード例 #7
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)
コード例 #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
コード例 #9
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