SignalAPI: return Err() instead of None for all methods
This commit is contained in:
parent
fb994d1a5e
commit
37a8fb6f9c
27
main.py
27
main.py
@ -37,8 +37,7 @@ class SignalAPI:
|
||||
if r.status_code == 201:
|
||||
return parse_response(UsernameSetResponse, r.text)
|
||||
else:
|
||||
print("Failed to set username")
|
||||
print(r.json())
|
||||
return Err("Failed to set username.")
|
||||
|
||||
def get_groups(self) -> Result[List[GroupEntry], str]:
|
||||
# get request to get groups
|
||||
@ -48,8 +47,7 @@ class SignalAPI:
|
||||
if r.status_code == 200:
|
||||
return parse_response(List[GroupEntry], r.text)
|
||||
else:
|
||||
print("Failed to get groups")
|
||||
print(r.json())
|
||||
return Err("Failed to get groups.")
|
||||
|
||||
def get_group(self, group_id: str) -> Result[GroupEntry, str]:
|
||||
# get request to get group
|
||||
@ -59,8 +57,7 @@ class SignalAPI:
|
||||
if r.status_code == 200:
|
||||
return parse_response(GroupEntry, r.text)
|
||||
else:
|
||||
print("Failed to get group")
|
||||
print(r.json())
|
||||
return Err("Failed to get group.")
|
||||
|
||||
def create_group(self, group_request: CreateGroupRequest) -> Result[CreateGroupResponse, str]:
|
||||
r = requests.post(f"{self.apiurl}/v1/groups/{self.number}", json=group_request.model_dump())
|
||||
@ -68,8 +65,7 @@ class SignalAPI:
|
||||
if r.status_code == 201:
|
||||
return parse_response(CreateGroupResponse, r.text)
|
||||
else:
|
||||
print("Failed to create group")
|
||||
print(r.json())
|
||||
return Err("Failed to create group.")
|
||||
|
||||
def add_group_members(self, group_id: str, numbers_to_add: List[str]) -> Result[None, str]:
|
||||
# put request to add group members
|
||||
@ -82,8 +78,7 @@ class SignalAPI:
|
||||
if r.status_code == 204:
|
||||
return Ok(None)
|
||||
else:
|
||||
print("Failed to add group members")
|
||||
print(r.json())
|
||||
return Err("Failed to add group members.")
|
||||
|
||||
def remove_group_members(self, group_id: str, numbers_to_remove: List[str]) -> Result[None, str]:
|
||||
# delete request to remove group members
|
||||
@ -96,8 +91,7 @@ class SignalAPI:
|
||||
if r.status_code == 204:
|
||||
return Ok(None)
|
||||
else:
|
||||
print("Failed to remove group members")
|
||||
print(r.json())
|
||||
return Err("Failed to remove group members.")
|
||||
|
||||
def update_group_members(self, group_id: str, other_members: List[str]) -> Result[UpdateGroupResult, str]:
|
||||
group = self.get_group(group_id)
|
||||
@ -138,8 +132,7 @@ class SignalAPI:
|
||||
if r.status_code == 200:
|
||||
return parse_response(List[IdentityEntry], r.text)
|
||||
else:
|
||||
print("Failed to get identities")
|
||||
print(r.json())
|
||||
return Err("Failed to get identities.")
|
||||
|
||||
# /v1/identities/{number}/trust/{numberToTrust}
|
||||
def trust_identity(self, number_to_trust: str, trust_identity_request: TrustIdentityRequest) -> Result[None, str]:
|
||||
@ -148,8 +141,7 @@ class SignalAPI:
|
||||
if r.status_code == 204:
|
||||
return Ok(None)
|
||||
else:
|
||||
print("Failed to trust identity")
|
||||
print(r.text)
|
||||
return Err("Failed to trust identity.")
|
||||
|
||||
async def websocket_connect_receive(self):
|
||||
ws_url = self.apiurl.replace("http", "ws")
|
||||
@ -167,8 +159,7 @@ class SignalAPI:
|
||||
if r.status_code == 201:
|
||||
return parse_response(SendMessageResponse, r.text)
|
||||
else:
|
||||
print("Failed to send message")
|
||||
print(r.text)
|
||||
return Err("Failed to send message")
|
||||
|
||||
|
||||
class LabCleaningBot:
|
||||
|
Loading…
Reference in New Issue
Block a user