示例#1
0
    def list(self, prefix=None, limit=None):
        params = {}
        if prefix:
            params['prefix'] = prefix
        if limit:
            params['limit'] = limit

        data = self._api.get(url=self._URL['list'].format(id=self.id),
                             params=params).json()

        href = data['href']
        links = [VolumeLink(**link) for link in data['links']]

        objects = [
            VolumeObject(api=self._api, **item) for item in data['items']
        ]
        prefixes = [
            VolumePrefix(api=self._api, **prefix) for prefix in  # noqa: F812
            data['prefixes']
        ]
        return VolumeCollection(href=href,
                                items=objects,
                                links=links,
                                prefixes=prefixes,
                                api=self._api)
 def _load(self, url):
     if self.resource is None:
         raise SbgError('Undefined collection resource.')
     else:
         response = self._api.get(url, append_base=False)
         data = response.json()
         items = [
             self.resource(api=self._api, **group) for group in
             data['items']
         ]
         prefixes = [
             VolumePrefix(api=self._api, **prefix) for prefix in
             data['prefixes']
         ]
         links = [VolumeLink(**link) for link in data['links']]
         href = data['href']
         return VolumeCollection(
             href=href, items=items, links=links,
             prefixes=prefixes, api=self._api
         )