Skip to content

Commit 19d4b83

Browse files
authored
Merge pull request #57 from bugout-dev/find-user-extend
Find user by id, email, username and application id
2 parents 0262a33 + d3c75ea commit 19d4b83

5 files changed

Lines changed: 41 additions & 13 deletions

File tree

bugout/__init__.py

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

99
__email__ = "engineering@bugout.dev"
1010
__license__ = "MIT"
11-
__version__ = "0.2.15"
11+
__version__ = "0.2.16"
1212

1313
__all__ = (
1414
"__author__",

bugout/app.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,23 @@ def get_user_by_id(
9090

9191
def find_user(
9292
self,
93-
username: str,
93+
user_id: Optional[Union[str, uuid.UUID]] = None,
94+
email: Optional[str] = None,
95+
username: Optional[str] = None,
96+
application_id: Optional[Union[str, uuid.UUID]] = None,
9497
token: Optional[Union[str, uuid.UUID]] = None,
9598
timeout: float = REQUESTS_TIMEOUT,
9699
**kwargs: Dict[str, Any],
97100
) -> data.BugoutUser:
98101
self.user.timeout = timeout
99-
return self.user.find_user(username=username, token=token, **kwargs)
102+
return self.user.find_user(
103+
user_id=user_id,
104+
email=email,
105+
username=username,
106+
application_id=application_id,
107+
token=token,
108+
**kwargs,
109+
)
100110

101111
def confirm_email(
102112
self,

bugout/calls.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ def make_request(method: Method, url: str, **kwargs) -> Any:
1717
raise BugoutResponseException(
1818
"Network error", status_code=599, detail=str(err)
1919
)
20-
if r.headers.get("Content-Type") == "application/json":
21-
exception_detail = r.json()["detail"]
20+
if r.headers.get("Content-Type") == "application/json": # type: ignore
21+
exception_detail = r.json()["detail"] # type: ignore
2222
else:
23-
exception_detail = r.text
23+
exception_detail = r.text # type: ignore
2424
raise BugoutResponseException(
2525
"An exception occurred at Bugout API side",
26-
status_code=r.status_code,
26+
status_code=r.status_code, # type: ignore
2727
detail=exception_detail,
2828
)
2929
except Exception as e:

bugout/jobs.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,11 @@ def list_jobs(
181181
results = [
182182
BugoutSearchResultWithEntryID(
183183
**dict(raw_result),
184-
id=raw_result.entry_url.split("/")[-1]
185-
if isinstance(raw_result, BugoutSearchResult)
186-
else raw_result.entity_url.split("/")[-1],
184+
id=(
185+
raw_result.entry_url.split("/")[-1]
186+
if isinstance(raw_result, BugoutSearchResult)
187+
else raw_result.entity_url.split("/")[-1]
188+
),
187189
)
188190
for raw_result in job_results.results
189191
]

bugout/user.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,33 @@ def get_user_by_id(
8686

8787
def find_user(
8888
self,
89-
username: str,
89+
user_id: Optional[Union[str, uuid.UUID]] = None,
90+
email: Optional[str] = None,
91+
username: Optional[str] = None,
92+
application_id: Optional[Union[str, uuid.UUID]] = None,
9093
token: Optional[Union[str, uuid.UUID]] = None,
9194
**kwargs: Dict[str, Any],
9295
) -> BugoutUser:
93-
find_user_path = f"user/find?username={username}"
96+
find_user_path = f"user/find"
97+
98+
query_params = {}
99+
if user_id is not None:
100+
query_params.update({"user_id": str(user_id)})
101+
if email is not None:
102+
query_params.update({"email": email})
103+
if username is not None:
104+
query_params.update({"username": username})
105+
if application_id is not None:
106+
query_params.update({"application_id": str(application_id)})
107+
94108
headers = {}
95109
if token is not None:
96110
headers.update({"Authorization": f"Bearer {token}"})
97111
if "headers" in kwargs.keys():
98112
headers.update(kwargs["headers"])
99-
result = self._call(method=Method.get, path=find_user_path, headers=headers)
113+
result = self._call(
114+
method=Method.get, path=find_user_path, params=query_params, headers=headers
115+
)
100116
return BugoutUser(**result)
101117

102118
def confirm_email(

0 commit comments

Comments
 (0)