예제 #1
0
파일: api.py 프로젝트: yuriybash/todoable
    def get_list(self, list_id, raw=False):
        """
        Get a list by ID.

        :param raw: whether to return raw response body
        :type raw: bool
        :return: the list, either raw or model instances
        :rtype: dict | List
        """
        url = "%s/%s/%s" % (self.BASE_URL, 'lists', list_id)
        serialized = self.make_request(requests.get, url).json()
        serialized.update({'id': list_id})

        if raw:
            return serialized

        return List.from_dict(serialized, )
예제 #2
0
파일: api.py 프로젝트: yuriybash/todoable
    def create_list(self, list_name, raw=False):
        """
        Create a list.

        :param list_name: list name
        :type list_name: basestring
        :param raw: whether to return raw response body
        :type raw: bool
        :return: the list, either raw or model instance
        :rtype: dict | List
        """
        url = "%s/%s" % (self.BASE_URL, 'lists')

        data = {"list": {"name": list_name}}

        serialized = self.make_request(requests.post,
                                       url,
                                       data=json.dumps(data)).json()

        return serialized if raw else List.from_dict(serialized)
예제 #3
0
파일: api.py 프로젝트: yuriybash/todoable
    def get_lists(self, raw=False, include_items=False):
        """
        Get lists.

        :param raw: whether to return raw response body
        :type raw: bool
        :param include_items: whether to include items associated with list
        :type include_items: bool
        :return: the lists, either raw or model instances
        :rtype: [dict] | [List]
        """
        url = "%s/%s" % (self.BASE_URL, 'lists')
        serialized = self.make_request(requests.get, url).json()

        if raw:
            return serialized

        lists = [List.from_dict(l) for l in serialized['lists']]
        if include_items:
            for todo_list in lists:
                items = self.get_list(todo_list.id, raw=True)['items']
                todo_list.items = [ListItem.from_dict(i) for i in items]
        return lists