Skip to content

Commit b0fd9b3

Browse files
committed
Changed to work with request params find_group, get_user_token
1 parent 53b8bf0 commit b0fd9b3

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

bugout/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ def get_group(
192192

193193
def find_group(
194194
self,
195+
token: Union[str, uuid.UUID],
195196
group_id: Optional[Union[str, uuid.UUID]] = None,
196197
name: Optional[str] = None,
197-
token: Union[str, uuid.UUID] = None,
198198
timeout: float = REQUESTS_TIMEOUT,
199199
) -> data.BugoutGroup:
200200
self.user.timeout = timeout
201-
return self.group.find_group(group_id=group_id, name=name, token=token)
201+
return self.group.find_group(token=token, group_id=group_id, name=name)
202202

203203
def get_user_groups(
204204
self, token: Union[str, uuid.UUID], timeout: float = REQUESTS_TIMEOUT

bugout/group.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,29 @@ def get_group(
4949

5050
def find_group(
5151
self,
52+
token: Union[str, uuid.UUID],
5253
group_id: Optional[Union[str, uuid.UUID]] = None,
5354
name: Optional[str] = None,
54-
token: Union[str, uuid.UUID] = None,
5555
) -> BugoutGroup:
5656
find_group_path = f"group/find"
57-
if group_id is not None and name is None:
58-
find_group_path += f"?group_id={group_id}"
59-
elif group_id is None and name is not None:
60-
find_group_path += f"?name={name}"
61-
elif group_id is not None and name is not None:
62-
find_group_path += f"?group_id={group_id}&name={name}"
57+
if group_id is None and name is None:
58+
raise GroupInvalidParameters(
59+
"In order to find group, at least one of name, or id must be specified"
60+
)
61+
query_params = {}
62+
if group_id is not None:
63+
query_params.update({"group_id": group_id})
64+
if name is not None:
65+
query_params.update({"name": name})
6366
headers = {
6467
"Authorization": f"Bearer {token}",
6568
}
66-
result = self._call(method=Method.get, path=find_group_path, headers=headers)
69+
result = self._call(
70+
method=Method.get,
71+
path=find_group_path,
72+
params=query_params,
73+
headers=headers,
74+
)
6775
return BugoutGroup(**result)
6876

6977
def get_user_groups(self, token: Union[str, uuid.UUID]) -> BugoutUserGroups:

bugout/user.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,15 @@ def get_user_tokens(
222222
headers = {
223223
"Authorization": f"Bearer {token}",
224224
}
225-
if active is not None and token_type is None:
226-
get_user_tokens_path += f"?active={active}"
227-
elif active is None and token_type is not None:
228-
get_user_tokens_path += f"?token_type={token_type.value}"
229-
elif active is not None and token_type is not None:
230-
get_user_tokens_path += f"?active={active}&token_type={token_type.value}"
225+
query_params = {}
226+
if active is not None:
227+
query_params.update({"active": active})
228+
if token_type is not None:
229+
query_params.update({"token_type": token_type.value})
231230
result = self._call(
232-
method=Method.get, path=get_user_tokens_path, headers=headers
231+
method=Method.get,
232+
path=get_user_tokens_path,
233+
params=query_params,
234+
headers=headers,
233235
)
234236
return BugoutUserTokens(**result)

0 commit comments

Comments
 (0)