# Path: solvebio/resource/apiresource.py
# class ListableAPIResource(APIResource):
#     """Has one method: *all()* which lists everything in the resource."""
# 
#     @classmethod
#     def all(cls, **params):
#         _client = params.pop('client', None) or cls._client or client
#         url = cls.class_url()
#         response = _client.get(url, params)
#         results = convert_to_solve_object(response, client=_client)
# 
#         # If the object has LIST_FIELDS, setup tabulate
#         if len(results.data) > 0:
#             list_fields = getattr(results.data[0], 'LIST_FIELDS', None)
#             if list_fields:
#                 fields, headers = list(zip(*list_fields))
#                 results.set_tabulate(fields, headers=headers, sort=False)
# 
#         return results
# 
#     @classmethod
#     def _retrieve_helper(cls, model_name, field_name, error_value, **params):
#         _client = params.pop('client', None) or cls._client or client
#         url = cls.class_url()
#         response = _client.get(url, params)
#         results = convert_to_solve_object(response, client=_client)
#         objects = results.data
#         allow_multiple = params.pop('allow_multiple', None)
#         if len(objects) > 1:
#             if allow_multiple:
#                 return objects
#             else:
#                 raise Exception('Multiple {0}s found with {1} "{2}"'
#                                 .format(model_name, field_name, error_value))
#         elif len(objects) == 1:
#             return objects[0]
#         else:
#             raise NotFoundError('No {0} found with {1} "{2}"'
#                                 .format(model_name, field_name, error_value))
# 
#     @classmethod
#     def pager(cls, **params):
#         return pager(cls.all, **params)
# 
#     def __repr__(self):
#         return tabulate(list(self.items()), ['Fields', 'Data'],
#                         aligns=['right', 'left'], sort=True)
# 
# Path: solvebio/resource/apiresource.py
# class DeletableAPIResource(APIResource):
# 
#     def delete(self, **params):
#         printable_name = class_to_api_name(
#             self.class_name(), pluralize=False).replace('_', ' ')
#         if not params.pop('force', False):
#             res = raw_input('Are you sure you want to delete this %s? '
#                             '[y/N] ' % printable_name)
#             if res.strip().lower() != 'y':
#                 print('Not performing deletion.')
#                 return
# 
#         response = self.request('delete', self.instance_url(), params=params)
#         return convert_to_solve_object(response, client=self._client)
# 
# Path: solvebio/resource/apiresource.py
# class UpdateableAPIResource(APIResource):
# 
#     def save(self):
#         self.refresh_from(self.request('patch', self.instance_url(),
#                                        data=self.serialize(self)))
#         return self
# 
#     def serialize(self, obj):
#         params = {}
#         unsaved_values = obj._unsaved_values
# 
#         # adding 'metadata' attribute to be serialized
#         if getattr(obj, 'metadata', None) is not None:
#             unsaved_values.add('metadata')
# 
#         for k in unsaved_values:
#             if k == 'id' or k == self.ID_ATTR:
#                 continue
# 
#             attr = getattr(obj, k)
# 
#             if isinstance(attr, SolveObject):
#                 params[k] = dict(attr)
#             else:
#                 params[k] = attr
# 
#         return params
# 
# Path: solvebio/resource/apiresource.py
# class CreateableAPIResource(APIResource):
# 
#     @classmethod
#     def create(cls, **params):
#         _client = params.pop('client', None) or cls._client or client
#         url = cls.class_url()
#         response = _client.post(url, data=params)
#         return convert_to_solve_object(response, client=_client)
# 
# Path: solvebio/resource/solveobject.py
# def convert_to_solve_object(resp, **kwargs):
#     from . import types
# 
#     _client = kwargs.pop('client', None)
# 
#     if isinstance(resp, list):
#         return [convert_to_solve_object(i, client=_client) for i in resp]
#     elif isinstance(resp, dict) and not isinstance(resp, SolveObject):
#         resp = resp.copy()
#         klass_name = resp.get('class_name')
#         if isinstance(klass_name, six.string_types):
#             klass = types.get(klass_name, SolveObject)
#         else:
#             klass = SolveObject
#         return klass.construct_from(resp, client=_client)
#     else:
#         return resp


from .apiresource import ListableAPIResource
from .apiresource import DeletableAPIResource
from .apiresource import UpdateableAPIResource
from .apiresource import CreateableAPIResource
from .solveobject import convert_to_solve_object
        from . import Object
    )

    def members(self, **params):
        response = self._client.get(self.memberships_url, params)
        results = convert_to_solve_object(response, client=self._client)
        results.set_tabulate(
            ['id', 'full_name', 'username', 'email', 'role'],
            headers=['ID', 'Full Name', 'Username', 'Email', 'Role'],
            aligns=['left', 'left', 'left', 'left', 'left'], sort=False)

        return results

    def _get_vaults(self, **params):
        response = self._client.get(self.vaults_url, params)
        return convert_to_solve_object(response, client=self._client)

    def vaults(self, **params):
        results = self._get_vaults(**params)
        results.set_tabulate(
            ['id', 'name', 'permission', 'vault_permissions'],
            headers=['ID', 'Vault', 'Permission', 'Permissions Detail'],
            aligns=['left', 'left', 'left', 'left'], sort=False)

        return results

    def datasets(self, **params):
        vaults = self._get_vaults(**params)
        objects_url = Object.class_url() + '?object_type=dataset&' + \
            '&'.join(['vault_id={0}'.format(v.id) for v in vaults])
        response = self._client.get(objects_url, params)

# Path: solvebio/resource/apiresource.py
# class ListableAPIResource(APIResource):
#     """Has one method: *all()* which lists everything in the resource."""
# 
#     @classmethod
#     def all(cls, **params):
#         _client = params.pop('client', None) or cls._client or client
#         url = cls.class_url()
#         response = _client.get(url, params)
#         results = convert_to_solve_object(response, client=_client)
# 
#         # If the object has LIST_FIELDS, setup tabulate
#         if len(results.data) > 0:
#             list_fields = getattr(results.data[0], 'LIST_FIELDS', None)
#             if list_fields:
#                 fields, headers = list(zip(*list_fields))
#                 results.set_tabulate(fields, headers=headers, sort=False)
# 
#         return results
# 
#     @classmethod
#     def _retrieve_helper(cls, model_name, field_name, error_value, **params):
#         _client = params.pop('client', None) or cls._client or client
#         url = cls.class_url()
#         response = _client.get(url, params)
#         results = convert_to_solve_object(response, client=_client)
#         objects = results.data
#         allow_multiple = params.pop('allow_multiple', None)
#         if len(objects) > 1:
#             if allow_multiple:
#                 return objects
#             else:
#                 raise Exception('Multiple {0}s found with {1} "{2}"'
#                                 .format(model_name, field_name, error_value))
#         elif len(objects) == 1:
#             return objects[0]
#         else:
#             raise NotFoundError('No {0} found with {1} "{2}"'
#                                 .format(model_name, field_name, error_value))
# 
#     @classmethod
#     def pager(cls, **params):
#         return pager(cls.all, **params)
# 
#     def __repr__(self):
#         return tabulate(list(self.items()), ['Fields', 'Data'],
#                         aligns=['right', 'left'], sort=True)
# 
# Path: solvebio/resource/apiresource.py
# class DeletableAPIResource(APIResource):
# 
#     def delete(self, **params):
#         printable_name = class_to_api_name(
#             self.class_name(), pluralize=False).replace('_', ' ')
#         if not params.pop('force', False):
#             res = raw_input('Are you sure you want to delete this %s? '
#                             '[y/N] ' % printable_name)
#             if res.strip().lower() != 'y':
#                 print('Not performing deletion.')
#                 return
# 
#         response = self.request('delete', self.instance_url(), params=params)
#         return convert_to_solve_object(response, client=self._client)
# 
# Path: solvebio/resource/apiresource.py
# class UpdateableAPIResource(APIResource):
# 
#     def save(self):
#         self.refresh_from(self.request('patch', self.instance_url(),
#                                        data=self.serialize(self)))
#         return self
# 
#     def serialize(self, obj):
#         params = {}
#         unsaved_values = obj._unsaved_values
# 
#         # adding 'metadata' attribute to be serialized
#         if getattr(obj, 'metadata', None) is not None:
#             unsaved_values.add('metadata')
# 
#         for k in unsaved_values:
#             if k == 'id' or k == self.ID_ATTR:
#                 continue
# 
#             attr = getattr(obj, k)
# 
#             if isinstance(attr, SolveObject):
#                 params[k] = dict(attr)
#             else:
#                 params[k] = attr
# 
#         return params
# 
# Path: solvebio/resource/apiresource.py
# class CreateableAPIResource(APIResource):
# 
#     @classmethod
#     def create(cls, **params):
#         _client = params.pop('client', None) or cls._client or client
#         url = cls.class_url()
#         response = _client.post(url, data=params)
#         return convert_to_solve_object(response, client=_client)
# 
# Path: solvebio/resource/solveobject.py
# def convert_to_solve_object(resp, **kwargs):
#     from . import types
# 
#     _client = kwargs.pop('client', None)
# 
#     if isinstance(resp, list):
#         return [convert_to_solve_object(i, client=_client) for i in resp]
#     elif isinstance(resp, dict) and not isinstance(resp, SolveObject):
#         resp = resp.copy()
#         klass_name = resp.get('class_name')
#         if isinstance(klass_name, six.string_types):
#             klass = types.get(klass_name, SolveObject)
#         else:
#             klass = SolveObject
#         return klass.construct_from(resp, client=_client)
#     else:
#         return resp


# Path: solvebio/resource/group.py
from .apiresource import ListableAPIResource
from .apiresource import DeletableAPIResource
from .apiresource import UpdateableAPIResource
from .apiresource import CreateableAPIResource
from .solveobject import convert_to_solve_object
        from . import Object

    )

    def members(self, **params):
        response = self._client.get(self.memberships_url, params)
        results = convert_to_solve_object(response, client=self._client)
        results.set_tabulate(
            ['id', 'full_name', 'username', 'email', 'role'],
            headers=['ID', 'Full Name', 'Username', 'Email', 'Role'],
            aligns=['left', 'left', 'left', 'left', 'left'], sort=False)

        return results

    def _get_vaults(self, **params):
        response = self._client.get(self.vaults_url, params)
        return convert_to_solve_object(response, client=self._client)

    def vaults(self, **params):
        results = self._get_vaults(**params)
        results.set_tabulate(
            ['id', 'name', 'permission', 'vault_permissions'],
            headers=['ID', 'Vault', 'Permission', 'Permissions Detail'],
            aligns=['left', 'left', 'left', 'left'], sort=False)

        return results

    def datasets(self, **params):
        vaults = self._get_vaults(**params)
        objects_url = Object.class_url() + '?object_type=dataset&' + \
            '&'.join(['vault_id={0}'.format(v.id) for v in vaults])
        response = self._client.get(objects_url, params)

        datasets = convert_to_solve_object(response, client=self._client)