Exemplo n.º 1
0
    def add_card(self, list_id, name="", description="", label_colour=[]):
        url = "/1/cards"
        _list = self.get_list_by_id(list_id)
        labels = []
        if _list.id:
            labels = [
                l.id
                for l in self.get_board_labels(_list.board_id)
                if l.colour in label_colour
            ]

        if not labels:
            raise Exception(f"Unable to find label: {label_colour}")

        query_string = {
            "idList": list_id,
            "name": name,
            "pos": "bottom",
            "idLabels": ",".join(labels),
            "desc": description,
        }
        resp = TrelloAPI.send_request(
            method="POST", url=url, params=query_string
        )
        if resp:
            card = self.get_card_by_id(resp['id'])
            print(f"Card Added: {card}")
            return card
        else:
            raise Exception("Unable to add card")
Exemplo n.º 2
0
 def get_cards_by_list_id(self, id=""):
     url = f"/1/lists/{id}/cards"
     resp = TrelloAPI.send_request(url)
     cards = []
     if resp:
         cards = [Card(c) for c in resp]
     return cards
Exemplo n.º 3
0
 def get_board_by_id(self, id=""):
     url = f"/1/boards/{id}"
     query_string = {"actions": "all", "cards": "all", "lists": "all"}
     resp = TrelloAPI.send_request(url, params=query_string)
     board = Board()
     if resp:
         board = Board(resp)
     return board
Exemplo n.º 4
0
 def get_board_ids(self, title=""):
     url = "/1/members/me/boards"
     query_string = {"filter": "all", "fields": ""}
     resp = TrelloAPI.send_request(url, params=query_string)
     boards = []
     if resp:
         boards = [b["id"] for b in resp if b.get("id")]
     return boards
Exemplo n.º 5
0
 def get_card_comments_by_id(self, id=""):
     url = f"/1/cards/{id}/actions"
     query_string = {"filter": "commentCard"}
     resp = TrelloAPI.send_request(url, params=query_string)
     comments = []
     if resp:
         comments = [Comment(c) for c in resp]
     return comments
Exemplo n.º 6
0
 def get_list_by_id(self, id=""):
     url = f"/1/lists/{id}"
     query_string = {"fields": "all"}
     resp = TrelloAPI.send_request(url, params=query_string)
     _list = List()
     if resp:
         _list = List(resp)
         _list.cards = self.get_cards_by_list_id(id)
     return _list
Exemplo n.º 7
0
 def get_lists_by_board_id(self, id=""):
     url = f"/1/boards/{id}/lists"
     query_string = {"cards": "all", "card_fields": "all"}
     resp = TrelloAPI.send_request(url, params=query_string)
     lists = []
     if resp:
         for l in resp:
             _list = List(l)
             lists.append(_list)
     return lists
Exemplo n.º 8
0
 def get_board_labels(self, id=""):
     url = f"/1/boards/{id}/labels"
     query_string = {"fields": "all"}
     resp = TrelloAPI.send_request(url, params=query_string)
     labels = []
     if resp:
         for l in resp:
             label = Label(l)
             labels.append(label)
     return labels
Exemplo n.º 9
0
 def get_card_by_id(self, id=""):
     url = f"/1/cards/{id}"
     query_string = {"fields": "all", "card_fields": "all"}
     resp = TrelloAPI.send_request(url, params=query_string)
     card = Card()
     if resp:
         card = Card(resp)
         if card.has_comments:
             card.comments = self.get_card_comments_by_id(id)
     return card
Exemplo n.º 10
0
    def delete_board(self, id):
        url = f"/1/boards/{id}"
        board = self.get_board_by_id(id)
        if not board.id:
            raise Exception(f"Unable to find board with ID: {id}")

        resp = TrelloAPI.send_request(method="DELETE", url=url)
        if resp:
            print(f"Board {id} deleted")
        else:
            raise Exception("Unable to delete board")
Exemplo n.º 11
0
    def delete_card_comment(self, id, comment_id):
        url = f"/1/cards/{id}/actions/{comment_id}/comments"
        card = self.get_card_by_id(id)
        if not card.id:
            raise Exception(f"Unable to find card with ID: {id}")

        resp = TrelloAPI.send_request(method="DELETE", url=url)
        if resp:
            print("Comment Deleted")
        else:
            raise Exception("Unable to delete comment")
Exemplo n.º 12
0
 def add_board(self, name):
     url = "/1/boards/"
     query_string = {"name": name}
     resp = TrelloAPI.send_request(
         method="POST", url=url, params=query_string
     )
     if resp:
         print("Board Added:")
         board = self.get_board_by_id(resp["id"])
         print(board)
         return board
     else:
         raise Exception("Unable to create board")
Exemplo n.º 13
0
    def add_card_comment(self, id, comment):
        url = f"/1/cards/{id}/actions/comments"
        card = self.get_card_by_id(id)
        if not card.id:
            raise Exception(f"Unable to find card with ID: {id}")

        query_string = {"text": comment}
        resp = TrelloAPI.send_request(
            method="POST", url=url, params=query_string
        )
        if resp:
            card = self.get_card_by_id(id)
            card.show_details = True
            card.comments = self.get_card_comments_by_id(id)
            print(f"Comment Added: {card}")
        else:
            raise Exception("Unable to add comment")
Exemplo n.º 14
0
 def delete_card_by_id(self, id=""):
     url = f"/1/cards/{id}"
     resp = TrelloAPI.send_request(method="DELETE", url=url)
     if resp:
         print(f"Card {id} deleted")
Exemplo n.º 15
0
 def auth(self, key="", token=""):
     TrelloAPI(key, token)
     self.initialized = TrelloAPI.initialized