Skip to content

Commit 4422329

Browse files
authored
Merge pull request #12 from bugout-dev/user_integrations
Handlers for user integrations
2 parents ce224bd + 799a5d7 commit 4422329

File tree

5 files changed

+63
-7
lines changed

5 files changed

+63
-7
lines changed

bugout/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
__email__ = "engineering@bugout.dev"
99
__license__ = "MIT"
10-
__version__ = "0.1.1"
10+
__version__ = "0.1.2"
1111

1212
__all__ = (
1313
"__author__",

bugout/app.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ def get_user_by_id(
7676
self.user.timeout = timeout
7777
return self.user.get_user_by_id(token=token, user_id=user_id)
7878

79+
def find_user(
80+
self,
81+
username: str,
82+
token: Union[str, uuid.UUID] = None,
83+
installation_token: str = None,
84+
timeout: float = REQUESTS_TIMEOUT,
85+
) -> data.BugoutUser:
86+
self.user.timeout = timeout
87+
return self.user.find_user(
88+
username=username, token=token, installation_token=installation_token
89+
)
90+
7991
def confirm_email(
8092
self,
8193
token: Union[str, uuid.UUID],
@@ -185,6 +197,16 @@ def get_group(
185197
self.group.timeout = timeout
186198
return self.group.get_group(token=token, group_id=group_id)
187199

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+
188210
def get_user_groups(
189211
self, token: Union[str, uuid.UUID], timeout: float = REQUESTS_TIMEOUT
190212
) -> data.BugoutUserGroups:

bugout/data.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ class HolderType(Enum):
3636
class BugoutUser(BaseModel):
3737
id: uuid.UUID = Field(alias="user_id")
3838
username: str
39-
email: str
40-
normalized_email: str
41-
verified: bool
42-
autogenerated: bool
43-
created_at: datetime
44-
updated_at: datetime
39+
email: Optional[str]
40+
normalized_email: Optional[str]
41+
verified: Optional[bool]
42+
autogenerated: Optional[bool]
43+
created_at: Optional[datetime]
44+
updated_at: Optional[datetime]
4545

4646

4747
class BugoutUserShort(BaseModel):

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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ def get_user_by_id(
7575
)
7676
return BugoutUser(**result)
7777

78+
def find_user(
79+
self,
80+
username: str,
81+
token: Union[str, uuid.UUID] = None,
82+
installation_token: str = None,
83+
) -> BugoutUser:
84+
find_user_path = f"user/find?username={username}"
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})
90+
result = self._call(method=Method.get, path=find_user_path, headers=headers)
91+
return BugoutUser(**result)
92+
7893
def confirm_email(
7994
self, token: Union[str, uuid.UUID], verification_code: str
8095
) -> BugoutUser:

0 commit comments

Comments
 (0)