Skip to content

Commit

Permalink
Merge pull request #51 from shaurya-blip/master
Browse files Browse the repository at this point in the history
Added Notification Resource to the package.
  • Loading branch information
chdastolfo authored Mar 14, 2022
2 parents 715e67a + 86fb617 commit 0a07551
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 6 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ monday.items.create_item(board_id='12345678', group_id='today', item_name='Do a
#### Users Resource (monday.users)
- `fetch_users(**kwargs)` - Fetch user information associated with an account. See Monday API docs for a list of accepted keyword arguments.

### Workspaces Resource (monday.workspaces)
#### Workspaces Resource (monday.workspaces)
- `get_workspaces()` - Get all workspaces.

- `create_workspace(name, kind, description)` - Create workspace with the given name, kind and description.
Expand All @@ -78,7 +78,7 @@ monday.items.create_item(board_id='12345678', group_id='today', item_name='Do a

- `delete_teams_from_workspace(workspace_id, [team_ids])` - Delete given teams from the given workspace.

### Groups Resource (monday.groups)
#### Groups Resource (monday.groups)
- `get_groups_by_board([board_ids])` - Get all groups associated with a certain board or boards. Accepts a single id or a comma separated list of ids.

- `get_items_by_group(board_id, group_id)` - Get all items that are members of a given group.
Expand All @@ -91,12 +91,14 @@ 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).
### 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)

#### Contributions
### Contributions
TBD

#### Bug Reports
### Bug Reports
TBD
3 changes: 2 additions & 1 deletion monday/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

from .__version__ import __version__
from .resources import ItemResource, UpdateResource, TagResource, BoardResource, UserResource, GroupResource, ComplexityResource, WorkspaceResource
from .resources import ItemResource, UpdateResource, TagResource, BoardResource, UserResource, GroupResource, ComplexityResource, WorkspaceResource, NotificationResource


class MondayClient:
Expand All @@ -23,6 +23,7 @@ def __init__(self, token):
self.groups = GroupResource(token=token)
self.complexity = ComplexityResource(token=token)
self.workspaces = WorkspaceResource(token=token)
self.notifications = NotificationResource(token=token)

def __str__(self):
return f'MondayClient {__version__}'
Expand Down
15 changes: 15 additions & 0 deletions monday/query_joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,18 @@ def delete_teams_from_workspace_query(id, team_ids):
}
''' % (id, team_ids)
return query


def create_notification_query(user_id, target_id, text, target_type):
query = '''
mutation {
create_notification (user_id: %s, target_id: %s, text: "%s", target_type: %s) {
text
user_id
target_id
target_type
}
}
''' % (user_id, target_id, text, target_type)
# Target type may be: Project/Post
return query
3 changes: 2 additions & 1 deletion monday/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
from .groups import GroupResource
from .complexity import ComplexityResource
from .workspaces import WorkspaceResource
from .notification import NotificationResource

__all__ = ['ItemResource', 'UpdateResource', 'TagResource', 'BoardResource', 'UserResource', 'GroupResource', 'ComplexityResource', 'WorkspaceResource']
__all__ = ['ItemResource', 'UpdateResource', 'TagResource', 'BoardResource', 'UserResource', 'GroupResource', 'ComplexityResource', 'WorkspaceResource', 'NotificationResource']
14 changes: 14 additions & 0 deletions monday/resources/notification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from monday.resources.base import BaseResource
from monday.query_joins import create_notification_query


class NotificationResource(BaseResource):
def __init__(self, token):
super().__init__(token)

def create_notification(self, user_id, target_id, text, target_type):
"""
Refer to here for more information -> https://api.developer.monday.com/docs/notification-queries
"""
query = create_notification_query(user_id, target_id, text, target_type)
return self.client.execute(query)
2 changes: 2 additions & 0 deletions monday/tests/test_case_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ def setUp(self):
self.workspace_id = "123456"
self.workspace_user_kind = "subscriber"
self.team_ids = [105939, 105940, 105941]
self.notification_text = "This is an awesome notification."
self.notification_target_type = "Project"

15 changes: 15 additions & 0 deletions monday/tests/test_notification_resource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from monday.tests.test_case_resource import BaseTestCase
from monday.query_joins import create_notification_query


class NotificationsTestCase(BaseTestCase):
def setUp(self):
super(NotificationsTestCase, self).setUp()

def test_create_notification_query(self):
query = create_notification_query(self.user_ids[0], self.item_id, self.notification_text, self.notification_target_type)
self.assertIn(str(self.user_ids[0]), query)
self.assertIn(str(self.item_id), query)
self.assertIn(str(self.notification_text), query)
self.assertIn(str(self.notification_target_type), query)

0 comments on commit 0a07551

Please sign in to comment.