Ejemplo n.º 1
0
    def create_list_item(self, list_id, item_name, raw=False):
        """
        Create an item associated with a list.

        :param list_id: list ID
        :type list_id: basestring
        :param item_name: item name
        :type item_name: basestring
        :param raw: whether to return raw response body
        :type raw: bool
        :return: raw item or model instance
        :rtype: dict | ListItem
        """
        url = "%s/%s/%s/%s" % (self.BASE_URL, 'lists', list_id, 'items')

        data = {"item": {"name": item_name}}

        serialized = self.make_request(requests.post,
                                       url,
                                       data=json.dumps(data)).json()
        if raw:
            return serialized
        return ListItem.from_dict(serialized)
Ejemplo n.º 2
0
    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