Skip to content

Commit

Permalink
1.3.3 (#96)
Browse files Browse the repository at this point in the history
* Add in limits and pages to items query

* Add in unit test

* Add in no params test

* Update surface level api

* Split up test

* Split out gather func

* Update README

* CORRECTLY update README

* bump version number

Co-authored-by: Taylor Cochran <[email protected]>
  • Loading branch information
chdastolfo and t-a-y-l-o-r authored Dec 8, 2022
1 parent 834aa4a commit e1e6ecd
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand All @@ -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)
Expand Down Expand Up @@ -148,4 +150,4 @@ monday.items.create_item(board_id='12345678', group_id='today', item_name='Do a
<!-- ALL-CONTRIBUTORS-LIST:END -->

### Bug Reports
TBD
TBD
4 changes: 2 additions & 2 deletions monday/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '1.3.2'
__version__ = '1.3.3'
__author__ = 'Christina D\'Astolfo'
__email__ = '[email protected], pevner@prodperfect.com, lemi@prodperfect.com'
__email__ = '[email protected], lemi@prodperfect.com', 'pevner@prodperfect.com'
19 changes: 12 additions & 7 deletions monday/query_joins.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -235,7 +235,7 @@ def get_updates_for_item_query(board, item, limit):
name,
url,
file_extension,
file_size
file_size
},
replies {
id,
Expand Down Expand Up @@ -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
Expand All @@ -309,7 +314,7 @@ def get_board_items_query(board_id):
}
}
}
}''' % board_id
}''' % (board_id, joined_params)

return query

Expand Down
8 changes: 4 additions & 4 deletions monday/resources/boards.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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):
Expand All @@ -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)
return self.client.execute(query)
9 changes: 9 additions & 0 deletions monday/tests/test_board_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions monday/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
from typing import List
from enum import Enum


def monday_json_stringify(value):
Expand All @@ -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

0 comments on commit e1e6ecd

Please sign in to comment.