diff --git a/README.md b/README.md index cae9c52..b6959e6 100644 --- a/README.md +++ b/README.md @@ -67,13 +67,15 @@ monday.items.create_item(board_id='12345678', group_id='today', item_name='Do a - `board_kind` - The board's kind (*BoardKind*. public / private / share). - `state` - The state of the board (*BoardState*. all / active / archived / deleted. Default is active). - `order_by` - The order in which to retrieve your boards (*BoardsOrderBy*. created_at / used_at). - + - `fetch_boards_by_id([board_ids])` - Since Monday does not allow querying boards by name, you can use `fetch_boards` to get a list of boards, and then `fetch_boards_by_id` to get more detailed info about the groups and columns on that board. Accepts a comma separated list of board ids. - `fetch_columns_by_board_id([board_ids])` - Get all columns, as well as their ids, types, and settings. Accepts a comma separated list of board ids. -- `fetch_items_by_board_id([board_ids])` - Get all items on a board(s). Accepts a comma separated list of board ids. +- `fetch_items_by_board_id([board_ids], **kwargs)` - Get all items on a board(s). Accepts a comma separated list of board ids. + - `limit` - The number of rows returned (*int*. no default). + - `page` - The page number returned, should you implement pagination(*int*. no default). - `create_board(board_name, board_kind, workspace_id)` - Create board with the given name and kind by (and optional) workspace id. @@ -84,7 +86,7 @@ monday.items.create_item(board_id='12345678', group_id='today', item_name='Do a #### Workspaces Resource (monday.workspaces) - `get_workspaces()` - Get all workspaces. -- `create_workspace(name, kind, description)` - Create workspace with the given name, kind and description. +- `create_workspace(name, kind, description)` - Create workspace with the given name, kind and description. - `add_users_to_workspace(workspace_id, [user_ids], kind)` - Add given users of the given kind to the given workspace. @@ -108,7 +110,7 @@ monday.items.create_item(board_id='12345678', group_id='today', item_name='Do a - `delete_group(board_id, group_id)` - Delete a group on a given board. #### Notifications Resource (monday.notifications) -- `create_notification(user_id, target_id, text, target_type)` - The create_notification mutation allows to trigger a notification within the platform (will also send out an email if the recipient's email preferences are set up accordingly). +- `create_notification(user_id, target_id, text, target_type)` - The create_notification mutation allows to trigger a notification within the platform (will also send out an email if the recipient's email preferences are set up accordingly). ### Additional Resources and Code Samples - [Read and format all of the items on a board](https://github.com/ProdPerfect/monday/wiki/Code-Examples#whole-board-formatting-example) @@ -148,4 +150,4 @@ monday.items.create_item(board_id='12345678', group_id='today', item_name='Do a ### Bug Reports -TBD +TBD diff --git a/monday/__version__.py b/monday/__version__.py index 4b3bf26..7bb30fb 100644 --- a/monday/__version__.py +++ b/monday/__version__.py @@ -1,3 +1,3 @@ -__version__ = '1.3.2' +__version__ = '1.3.3' __author__ = 'Christina D\'Astolfo' -__email__ = 'chdastolfo@gmail.com, pevner@prodperfect.com, lemi@prodperfect.com' +__email__ = 'chdastolfo@gmail.com, lemi@prodperfect.com', 'pevner@prodperfect.com' diff --git a/monday/query_joins.py b/monday/query_joins.py index 072faca..d075643 100644 --- a/monday/query_joins.py +++ b/monday/query_joins.py @@ -1,9 +1,9 @@ from enum import Enum import json -from typing import List +from typing import List, Union, Optional from monday.resources.types import BoardKind, BoardState, BoardsOrderBy -from monday.utils import monday_json_stringify +from monday.utils import monday_json_stringify, gather_params # Eventually I will organize this file better but you know what today is not that day. @@ -218,7 +218,7 @@ def create_update_query(item_id, update_value): def get_updates_for_item_query(board, item, limit): query = '''query - {boards (ids: %s) + {boards (ids: %s) {items (ids: %s) { updates (limit: %s) { id, @@ -235,7 +235,7 @@ def get_updates_for_item_query(board, item, limit): name, url, file_extension, - file_size + file_size }, replies { id, @@ -289,12 +289,17 @@ def get_tags_query(tags): # BOARD RESOURCE QUERIES -def get_board_items_query(board_id): +def get_board_items_query(board_id: Union[str, int], limit: Optional[int] = None, page: Optional[int] = None) -> str: + + raw_params = locals().items() + item_params = gather_params(raw_params, exclusion_list=["board_id"]) + joined_params = ', '.join(item_params) + query = '''query { boards(ids: %s) { name - items { + items(%s) { group { id title @@ -309,7 +314,7 @@ def get_board_items_query(board_id): } } } - }''' % board_id + }''' % (board_id, joined_params) return query diff --git a/monday/resources/boards.py b/monday/resources/boards.py index d3a98f2..ce506a6 100644 --- a/monday/resources/boards.py +++ b/monday/resources/boards.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Optional from monday.resources.base import BaseResource from monday.query_joins import ( get_boards_query, @@ -22,8 +22,8 @@ def fetch_boards_by_id(self, board_ids): query = get_boards_by_id_query(board_ids) return self.client.execute(query) - def fetch_items_by_board_id(self, board_ids): - query = get_board_items_query(board_ids) + def fetch_items_by_board_id(self, board_ids, limit: Optional[int]=None, page: Optional[int]=None): + query = get_board_items_query(board_ids, limit=limit, page=page) return self.client.execute(query) def fetch_columns_by_board_id(self, board_ids): @@ -32,4 +32,4 @@ def fetch_columns_by_board_id(self, board_ids): def create_board(self, board_name: str, board_kind: BoardKind, workspace_id: int = None): query = create_board_by_workspace_query(board_name, board_kind, workspace_id) - return self.client.execute(query) \ No newline at end of file + return self.client.execute(query) diff --git a/monday/tests/test_board_resource.py b/monday/tests/test_board_resource.py index b549937..f8dfd85 100644 --- a/monday/tests/test_board_resource.py +++ b/monday/tests/test_board_resource.py @@ -39,6 +39,15 @@ def test_get_boards_by_id_query(self): def test_get_board_items_query(self): query = get_board_items_query(board_id=self.board_id) self.assertIn(str(self.board_id), query) + items_line = 'items()' + self.assertIn(items_line, query) + + def test_get_board_items_query_with_limit_and_pages(self): + limit = 100 + page = 1 + query = get_board_items_query(board_id=self.board_id, limit=limit, page=page) + items_line = f'items(limit: {limit}, page: {page})' + self.assertIn(items_line, query) def test_get_columns_by_board_query(self): query = get_columns_by_board_query(board_ids=self.board_id) diff --git a/monday/utils.py b/monday/utils.py index f9fd33a..fe50f1b 100644 --- a/monday/utils.py +++ b/monday/utils.py @@ -1,4 +1,6 @@ import json +from typing import List +from enum import Enum def monday_json_stringify(value): @@ -9,3 +11,15 @@ def monday_json_stringify(value): # "{\"label\":\"Done\"}" return json.dumps(json.dumps(value)) + + +def gather_params(params, exclusion_list: List[str]) -> List[str]: + valid_params: List[str] = [] + for param, value in params: + if value is None or param in exclusion_list: + continue + if isinstance(value, Enum): + valid_params.append(f"{param}: {value.value}") + continue + valid_params.append(f"{param}: {value}") + return valid_params