Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert API response JSON to Python dict #26

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion monday/graphqlclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def _send(self, query, variables):

try:
response = requests.request("POST", self.endpoint, headers=headers, data=payload, files=files)
return response.text
response.raise_for_status()
return response.json()
except requests.HTTPError as e:
print(e)
raise e
4 changes: 1 addition & 3 deletions monday/resources/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import json

from monday.graphqlclient.client import GraphQLClient

_URLS = {
Expand All @@ -20,7 +18,7 @@ def _query(self, query):
result = self.client.execute(query)

if result:
return json.loads(result)
return result

def __str__(self):
return self.__class__.__name__
Expand Down
10 changes: 4 additions & 6 deletions monday/resources/boards.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import json

from monday.resources.base import BaseResource
from monday.query_joins import get_boards_query, get_boards_by_id_query, get_board_items_query, \
get_columns_by_board_query
Expand All @@ -11,16 +9,16 @@ def __init__(self, token):

def fetch_boards(self, **kwargs):
query = get_boards_query(**kwargs)
return json.loads(self.client.execute(query))
return self.client.execute(query)

def fetch_boards_by_id(self, board_ids):
query = get_boards_by_id_query(board_ids)
return json.loads(self.client.execute(query))
return self.client.execute(query)

def fetch_items_by_board_id(self, board_ids):
query = get_board_items_query(board_ids)
return json.loads(self.client.execute(query))
return self.client.execute(query)

def fetch_columns_by_board_id(self, board_ids):
query = get_columns_by_board_query(board_ids)
return json.loads(self.client.execute(query))
return self.client.execute(query)
14 changes: 6 additions & 8 deletions monday/resources/groups.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import json

from monday.resources.base import BaseResource
from monday.query_joins import get_groups_by_board_query, get_items_by_group_query, create_group_query, \
duplicate_group_query, archive_group_query, delete_group_query
Expand All @@ -11,24 +9,24 @@ def __init__(self, token):

def get_groups_by_board(self, board_ids):
query = get_groups_by_board_query(board_ids=board_ids)
return json.loads(self.client.execute(query))
return self.client.execute(query)

def get_items_by_group(self, board_id, group_id):
query = get_items_by_group_query(board_id=board_id, group_id=group_id)
return json.loads(self.client.execute(query))
return self.client.execute(query)

def create_group(self, board_id, group_name):
query = create_group_query(board_id=board_id, group_name=group_name)
return json.loads(self.client.execute(query))
return self.client.execute(query)

def duplicate_group(self, board_id, group_id):
query = duplicate_group_query(board_id=board_id, group_id=group_id)
return json.loads(self.client.execute(query))
return self.client.execute(query)

def archive_group(self, board_id, group_id):
query = archive_group_query(board_id=board_id, group_id=group_id)
return json.loads(self.client.execute(query))
return self.client.execute(query)

def delete_group(self, board_id, group_id):
query = delete_group_query(board_id=board_id, group_id=group_id)
return json.loads(self.client.execute(query))
return self.client.execute(query)
16 changes: 7 additions & 9 deletions monday/resources/items.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import json

from monday.resources.base import BaseResource
from monday.query_joins import mutate_item_query, get_item_query, update_item_query, get_item_by_id_query, \
update_multiple_column_values_query, mutate_subitem_query, add_file_to_column_query
Expand All @@ -11,28 +9,28 @@ def __init__(self, token):

def create_item(self, board_id, group_id, item_name, column_values=None):
query = mutate_item_query(board_id, group_id, item_name, column_values)
return json.loads(self.client.execute(query))
return self.client.execute(query)

def create_subitem(self, parent_item_id, subitem_name, column_values=None):
query = mutate_subitem_query(parent_item_id, subitem_name, column_values)
return json.loads(self.client.execute(query))
return self.client.execute(query)

def fetch_items_by_column_value(self, board_id, column_id, value):
query = get_item_query(board_id, column_id, value)
return json.loads(self.client.execute(query))
return self.client.execute(query)

def fetch_items_by_id(self, ids):
query = get_item_by_id_query(ids)
return json.loads(self.client.execute(query))
return self.client.execute(query)

def change_item_value(self, board_id, item_id, column_id, value):
query = update_item_query(board_id, item_id, column_id, value)
return json.loads(self.client.execute(query))
return self.client.execute(query)

def change_multiple_column_values(self, board_id, item_id, column_values):
query = update_multiple_column_values_query(board_id, item_id, column_values)
return json.loads(self.client.execute(query))
return self.client.execute(query)

def add_file_to_column(self, item_id, column_id, file):
query = add_file_to_column_query(item_id, column_id)
return json.loads(self.file_upload_client.execute(query, variables={'file': file}))
return self.file_upload_client.execute(query, variables={'file': file})