Skip to content

Commit 799a5d7

Browse files
committed
Added handler group_find
1 parent 7ced36f commit 799a5d7

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

bugout/app.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ def get_user_by_id(
7878

7979
def find_user(
8080
self,
81-
token: Union[str, uuid.UUID],
8281
username: str,
82+
token: Union[str, uuid.UUID] = None,
83+
installation_token: str = None,
8384
timeout: float = REQUESTS_TIMEOUT,
8485
) -> data.BugoutUser:
8586
self.user.timeout = timeout
8687
return self.user.find_user(
87-
token=token,
88-
username=username,
88+
username=username, token=token, installation_token=installation_token
8989
)
9090

9191
def confirm_email(
@@ -197,6 +197,16 @@ def get_group(
197197
self.group.timeout = timeout
198198
return self.group.get_group(token=token, group_id=group_id)
199199

200+
def find_group(
201+
self,
202+
group_id: Optional[Union[str, uuid.UUID]] = None,
203+
name: Optional[str] = None,
204+
token: Union[str, uuid.UUID] = None,
205+
timeout: float = REQUESTS_TIMEOUT,
206+
) -> data.BugoutGroup:
207+
self.user.timeout = timeout
208+
return self.group.find_group(group_id=group_id, name=name, token=token)
209+
200210
def get_user_groups(
201211
self, token: Union[str, uuid.UUID], timeout: float = REQUESTS_TIMEOUT
202212
) -> data.BugoutUserGroups:

bugout/group.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ def get_group(
4747
result = self._call(method=Method.get, path=get_group_path, headers=headers)
4848
return BugoutGroup(**result)
4949

50+
def find_group(
51+
self,
52+
group_id: Optional[Union[str, uuid.UUID]] = None,
53+
name: Optional[str] = None,
54+
token: Union[str, uuid.UUID] = None,
55+
) -> BugoutGroup:
56+
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}"
63+
headers = {
64+
"Authorization": f"Bearer {token}",
65+
}
66+
result = self._call(method=Method.get, path=find_group_path, headers=headers)
67+
return BugoutGroup(**result)
68+
5069
def get_user_groups(self, token: Union[str, uuid.UUID]) -> BugoutUserGroups:
5170
get_user_groups_path = "groups"
5271
headers = {

bugout/user.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,16 @@ def get_user_by_id(
7777

7878
def find_user(
7979
self,
80-
token: Union[str, uuid.UUID],
8180
username: str,
81+
token: Union[str, uuid.UUID] = None,
82+
installation_token: str = None,
8283
) -> BugoutUser:
8384
find_user_path = f"user/find?username={username}"
84-
headers = {
85-
"Authorization": f"Bearer {token}",
86-
}
85+
headers = {}
86+
if token is not None:
87+
headers.update({"Authorization": f"Bearer {token}"})
88+
if installation_token is not None:
89+
headers.update({"x-bugout-installation-token": installation_token})
8790
result = self._call(method=Method.get, path=find_user_path, headers=headers)
8891
return BugoutUser(**result)
8992

0 commit comments

Comments
 (0)