Skip to content

Commit

Permalink
Support specifying with_counts and with_expiration in `RESTClient…
Browse files Browse the repository at this point in the history
….fetch_invite` (#1330)
  • Loading branch information
null-domain authored Nov 6, 2022
1 parent 9b1150e commit 167d796
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions changes/1330.doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support specifying `with_counts` and `with_expiration` in `RESTClient.fetch_invite`
12 changes: 11 additions & 1 deletion hikari/api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2765,14 +2765,24 @@ async def fetch_gateway_bot_info(self) -> sessions.GatewayBotInfo:
"""

@abc.abstractmethod
async def fetch_invite(self, invite: typing.Union[invites.InviteCode, str]) -> invites.Invite:
async def fetch_invite(
self, invite: typing.Union[invites.InviteCode, str], with_counts: bool = True, with_expiration: bool = True
) -> invites.Invite:
"""Fetch an existing invite.
Parameters
----------
invite : typing.Union[hikari.invites.InviteCode, builtins.str]
The invite to fetch. This may be an invite object or
the code of an existing invite.
with_counts : builtins.bool
Whether the invite should contain the approximate member counts.
Defaults to `builtins.True`.
with_expiration: builtins.bool
Whether the invite should contain the expiration date.
Defaults to `builtins.True`.
Returns
-------
Expand Down
8 changes: 5 additions & 3 deletions hikari/impl/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1982,11 +1982,13 @@ async def fetch_gateway_bot_info(self) -> sessions.GatewayBotInfo:
assert isinstance(response, dict)
return self._entity_factory.deserialize_gateway_bot_info(response)

async def fetch_invite(self, invite: typing.Union[invites.InviteCode, str]) -> invites.Invite:
async def fetch_invite(
self, invite: typing.Union[invites.InviteCode, str], with_counts: bool = True, with_expiration: bool = True
) -> invites.Invite:
route = routes.GET_INVITE.compile(invite_code=invite if isinstance(invite, str) else invite.code)
query = data_binding.StringMapBuilder()
query.put("with_counts", True)
query.put("with_expiration", True)
query.put("with_counts", with_counts)
query.put("with_expiration", with_expiration)
response = await self._request(route, query=query)
assert isinstance(response, dict)
return self._entity_factory.deserialize_invite(response)
Expand Down
5 changes: 2 additions & 3 deletions tests/hikari/impl/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3442,10 +3442,9 @@ async def test_fetch_invite(self, rest_client):
rest_client._request = mock.AsyncMock(return_value={"code": "Jx4cNGG"})
rest_client._entity_factory.deserialize_invite = mock.Mock(return_value=return_invite)

assert await rest_client.fetch_invite(input_invite) == return_invite

assert await rest_client.fetch_invite(input_invite, with_counts=True, with_expiration=False) == return_invite
rest_client._request.assert_awaited_once_with(
expected_route, query={"with_counts": "true", "with_expiration": "true"}
expected_route, query={"with_counts": "true", "with_expiration": "false"}
)
rest_client._entity_factory.deserialize_invite.assert_called_once_with({"code": "Jx4cNGG"})

Expand Down

0 comments on commit 167d796

Please sign in to comment.