Esempio n. 1
0
    def get_members(self, api=None):
        """Retrieve dataset members
        :param api: Api instance
        :return: Collection object
        """
        api = api or self._API

        response = api.get(url=self._URL['members'].format(id=self.id))

        data = response.json()
        total = response.headers['x-total-matching-query']
        members = [Member(api=api, **member) for member in data['items']]
        links = [Link(**link) for link in data['links']]
        href = data['href']

        return Collection(resource=Member,
                          href=href,
                          total=total,
                          items=members,
                          links=links,
                          api=api)
Esempio n. 2
0
 def get_members(self, offset=None, limit=None):
     """
     Retrieves project members.
     :param offset: Pagination offset.
     :param limit: Pagination limit.
     :return: Collection object.
     """
     extra = {
         'resource': self.__class__.__name__,
         'query': {'id': self.id}
     }
     logger.info('Get members', extra=extra)
     response = self._api.get(
         url=self._URL['members_query'].format(id=self.id),
         params={'offset': offset, 'limit': limit})
     data = response.json()
     total = response.headers['x-total-matching-query']
     members = [Member(api=self._api, **member) for member in data['items']]
     links = [Link(**link) for link in data['links']]
     href = data['href']
     return Collection(resource=Member, href=href, total=total,
                       items=members, links=links, api=self._api)
Esempio n. 3
0
    def _query(cls, **kwargs):
        """
        Generic query implementation that is used
        by the resources.
        """
        from sevenbridges.models.link import Link
        from sevenbridges.meta.collection import Collection

        #: :type: _HttpClient
        api = kwargs.pop('api', cls._API)
        url = kwargs.pop('url')
        response = api.get(url=url, params=kwargs)
        data = response.json()
        total = response.headers['x-total-matching-query']
        projects = [cls(api=api, **project) for project in data['items']]
        links = [Link(**link) for link in data['links']]
        href = data['href']
        return Collection(resource=cls,
                          href=href,
                          total=total,
                          items=projects,
                          links=links,
                          api=api)
Esempio n. 4
0
    def _query(cls, **kwargs):
        """
        Generic query implementation that is used
        by the resources.
        """
        from sevenbridges.models.link import Link
        from sevenbridges.meta.collection import Collection

        api = kwargs.pop('api', cls._API)
        url = kwargs.pop('url')
        extra = {'resource': cls.__name__, 'query': kwargs}
        logger.info('Querying {} resource'.format(cls), extra=extra)
        response = api.get(url=url, params=kwargs)
        data = response.json()
        total = response.headers['x-total-matching-query']

        items = [cls(api=api, **item) for item in data['items']]
        links = [Link(**link) for link in data['links']]
        href = data['href']
        return Collection(
            resource=cls, href=href, total=total, items=items,
            links=links, api=api
        )
Esempio n. 5
0
 def get_tasks(self, offset=None, limit=None):
     """
     Retrieves tasks in this project.
     :param offset:  Pagination offset.
     :param limit: Pagination limit.
     :return: Collection object.
     """
     response = self._api.get(url=self._URL['tasks'],
                              params={
                                  'project': self.id,
                                  'offset': offset,
                                  'limit': limit
                              })
     data = response.json()
     total = response.headers['x-total-matching-query']
     tasks = [Task(api=self._api, **task) for task in data['items']]
     links = [Link(**link) for link in data['links']]
     href = data['href']
     return Collection(resource=Task,
                       href=href,
                       total=total,
                       items=tasks,
                       links=links,
                       api=self._api)