Skip to content

Commit

Permalink
Merge pull request #48 from shaurya-blip/master
Browse files Browse the repository at this point in the history
Added Workspace Resource to the package. [UPDATED]
  • Loading branch information
chdastolfo authored Feb 7, 2022
2 parents 9aa7a8b + fb274cb commit 937f714
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ 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)
- `get_workspaces()` - Get all workspaces.

- `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.

- `delete_users_from_workspace(workspace_id, [user_ids])` - Delete given users from the given workspace.

- `add_teams_to_workspace(workspace_id, [team_ids])` - Add given teams to the given workspace.

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

### 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.
Expand Down
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
from .resources import ItemResource, UpdateResource, TagResource, BoardResource, UserResource, GroupResource, ComplexityResource, WorkspaceResource


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

def __str__(self):
return f'MondayClient {__version__}'
Expand Down
66 changes: 66 additions & 0 deletions monday/query_joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,69 @@ def get_complexity_query():
}'''

return query

def get_workspaces_query():
query = '''
query {
boards {
workspace {
id
name
kind
description
}
}
}
'''
return query

def create_workspace_query(name, kind, description=""):
query = '''
mutation {
create_workspace (name:"%s", kind: %s, description: "%s") {
id
description
}
}
''' % (name, kind, description)
return query

def add_users_to_workspace_query(id, user_ids, kind):
query = '''
mutation {
add_users_to_workspace (workspace_id: %s, user_ids: %s, kind: %s) {
id
}
}
''' % (id, user_ids, kind)
return query

def delete_users_from_workspace_query(id, user_ids):
query = '''
mutation {
add_users_to_workspace (workspace_id: %s, user_ids: %s) {
id
}
}
''' % (id, user_ids)
return query

def add_teams_to_workspace_query(id, team_ids):
query = '''
mutation {
add_teams_to_workspace (workspace_id: %s, team_ids: %s) {
id
}
}
''' % (id, team_ids)
return query

def delete_teams_from_workspace_query(id, team_ids):
query = '''
mutation {
delete_teams_from_workspace (workspace_id: %s, team_ids: %s) {
id
}
}
''' % (id, team_ids)
return query
3 changes: 2 additions & 1 deletion monday/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
from .users import UserResource
from .groups import GroupResource
from .complexity import ComplexityResource
from .workspaces import WorkspaceResource

__all__ = ['ItemResource', 'UpdateResource', 'TagResource', 'BoardResource', 'UserResource', 'GroupResource', 'ComplexityResource']
__all__ = ['ItemResource', 'UpdateResource', 'TagResource', 'BoardResource', 'UserResource', 'GroupResource', 'ComplexityResource', 'WorkspaceResource']
34 changes: 34 additions & 0 deletions monday/resources/workspaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from monday.resources.base import BaseResource
from monday.query_joins import (get_workspaces_query, create_workspace_query,
add_users_to_workspace_query, delete_users_from_workspace_query,
add_teams_to_workspace_query, delete_teams_from_workspace_query)


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

def get_workspaces(self):
query = get_workspaces_query()
return self.client.execute(query)

def create_workspace(self, name, kind, description=""):
query = create_workspace_query(name, kind, description)
return self.client.execute(query)

def add_users_to_workspace(self, workspace_id, user_ids, kind):
query = add_users_to_workspace_query(workspace_id, user_ids, kind)
return self.client.execute(query)

def delete_users_from_workspace(self, workspace_id, user_ids):
query = delete_users_from_workspace_query(workspace_id, user_ids)
return self.client.execute(query)

def add_teams_to_workspace(self, workspace_id, team_ids):
query = add_teams_to_workspace_query(workspace_id, team_ids)
return self.client.execute(query)

def delete_teams_from_workspace(self, workspace_id, team_ids):
query = delete_teams_from_workspace_query(workspace_id, team_ids)
return self.client.execute(query)

6 changes: 6 additions & 0 deletions monday/tests/test_case_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ def setUp(self):
self.tags = [123, 456, 789]
self.subitem_name = "A subitem"
self.column_values = {"foo": "bar", "bar": 12}
self.workspace_name = "my_group_workspace"
self.workspace_kind = "open"
self.workspace_id = "123456"
self.workspace_user_kind = "subscriber"
self.team_ids = [105939, 105940, 105941]

42 changes: 42 additions & 0 deletions monday/tests/test_workspace_resource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from monday.tests.test_case_resource import BaseTestCase
from monday.query_joins import (get_workspaces_query, create_workspace_query,
add_users_to_workspace_query, delete_users_from_workspace_query,
add_teams_to_workspace_query, delete_teams_from_workspace_query)


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

def test_get_workspaces_query(self):
query = get_workspaces_query()
self.assertIn(query)

def test_create_workspace_query(self):
query = create_workspace_query(self.workspace_name, self.workspace_kind)
self.assertIn(str(self.workspace_name), query)
self.assertIn(str(self.workspace_kind), query)

def test_add_users_to_workspace_query(self):
query = add_users_to_workspace_query(self.workspace_id, self.user_ids, self.workspace_user_kind)
self.assertIn(str(self.workspace_id), query)
self.assertIn(str(self.user_ids), query)
self.assertIn(str(self.workspace_user_kind), query)

def test_delete_users_from_workspace_query(self):
query = delete_users_from_workspace_query(self.workspace_id, self.user_ids)
self.assertIn(str(self.workspace_id), query)
self.assertIn(str(self.user_ids), query)

def test_add_teams_to_workspace_query(self):
query = add_teams_to_workspace_query(self.workspace_id, self.team_ids)
self.assertIn(str(self.workspace_id), query)
self.assertIn(str(self.team_ids), query)

def test_delete_teams_from_workspace_query(self):
query = delete_teams_from_workspace_query(self.workspace_id, self.team_ids)
self.assertIn(str(self.workspace_id), query)
self.assertIn(str(self.team_ids), query)



0 comments on commit 937f714

Please sign in to comment.