From 90f7006b67be203102c3d763353cdd486e8d4215 Mon Sep 17 00:00:00 2001 From: nulldomain Date: Wed, 26 Oct 2022 14:16:14 +0100 Subject: [PATCH 1/8] change fetch_invite request to use function parameters --- hikari/impl/rest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hikari/impl/rest.py b/hikari/impl/rest.py index f22ae9f7c5..8c0a9e8d9c 100644 --- a/hikari/impl/rest.py +++ b/hikari/impl/rest.py @@ -1960,11 +1960,11 @@ 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) From 70fe15036aec6ad74957da45fcabd5ad1ece38a6 Mon Sep 17 00:00:00 2001 From: nulldomain Date: Wed, 26 Oct 2022 14:16:23 +0100 Subject: [PATCH 2/8] document new fetch_invite parameters --- hikari/api/rest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hikari/api/rest.py b/hikari/api/rest.py index f6a4bc3591..438a0621b1 100644 --- a/hikari/api/rest.py +++ b/hikari/api/rest.py @@ -2762,7 +2762,7 @@ 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 @@ -2770,6 +2770,10 @@ async def fetch_invite(self, invite: typing.Union[invites.InviteCode, str]) -> i 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 approximate member counts. + with_expiration: builtins.bool + Whether the invite should contain the expiration date. Returns ------- From 1c88897a14773a4ed07e40e09d0e0824380d3eb1 Mon Sep 17 00:00:00 2001 From: nulldomain Date: Fri, 28 Oct 2022 10:36:51 +0100 Subject: [PATCH 3/8] Formatting changes --- hikari/api/rest.py | 4 +++- hikari/impl/rest.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/hikari/api/rest.py b/hikari/api/rest.py index 438a0621b1..1da23e2004 100644 --- a/hikari/api/rest.py +++ b/hikari/api/rest.py @@ -2762,7 +2762,9 @@ async def fetch_gateway_bot_info(self) -> sessions.GatewayBotInfo: """ @abc.abstractmethod - async def fetch_invite(self, invite: typing.Union[invites.InviteCode, str], with_counts: bool = True, with_expiration: bool = True) -> 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 diff --git a/hikari/impl/rest.py b/hikari/impl/rest.py index 8c0a9e8d9c..14e6c77704 100644 --- a/hikari/impl/rest.py +++ b/hikari/impl/rest.py @@ -1960,7 +1960,9 @@ 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], with_counts: bool = True, with_expiration: bool = True) -> 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", with_counts) From 87b4122569b91eb4fc34f77a27efef7aa2b43c02 Mon Sep 17 00:00:00 2001 From: nulldomain Date: Fri, 28 Oct 2022 10:39:55 +0100 Subject: [PATCH 4/8] Add changelog file --- changes/1330.doc.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/1330.doc.md diff --git a/changes/1330.doc.md b/changes/1330.doc.md new file mode 100644 index 0000000000..6877571edb --- /dev/null +++ b/changes/1330.doc.md @@ -0,0 +1 @@ +Improve RESTClientImpl.fetch_invite() to more closely match DAPI docs From ffda2540c54f6d447a065c24b3583ed77ba352be Mon Sep 17 00:00:00 2001 From: nulldomain Date: Sat, 29 Oct 2022 11:36:55 +0100 Subject: [PATCH 5/8] Make changelog more verbose/descriptive --- changes/1330.doc.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changes/1330.doc.md b/changes/1330.doc.md index 6877571edb..2a6313d56d 100644 --- a/changes/1330.doc.md +++ b/changes/1330.doc.md @@ -1 +1 @@ -Improve RESTClientImpl.fetch_invite() to more closely match DAPI docs +Support specifying `with_counts` and `with_expiration` in `RESTClient.fetch_invite` From 0613d277ae2243bfedac0bb966de007fe24b851a Mon Sep 17 00:00:00 2001 From: nulldomain Date: Sat, 29 Oct 2022 12:58:31 +0100 Subject: [PATCH 6/8] Modify test_fetch_invite to check that new params return intended values --- tests/hikari/impl/test_rest.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/hikari/impl/test_rest.py b/tests/hikari/impl/test_rest.py index ea94ca0fbe..c04e9964ed 100644 --- a/tests/hikari/impl/test_rest.py +++ b/tests/hikari/impl/test_rest.py @@ -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"}) From 1a32dc3da8c48fb6053bf0036da75e63531ca539 Mon Sep 17 00:00:00 2001 From: davfsa Date: Sun, 6 Nov 2022 00:07:05 +0100 Subject: [PATCH 7/8] Update hikari/api/rest.py Signed-off-by: davfsa --- hikari/api/rest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hikari/api/rest.py b/hikari/api/rest.py index 8b3b15d5de..f85d5cad01 100644 --- a/hikari/api/rest.py +++ b/hikari/api/rest.py @@ -2776,9 +2776,13 @@ async def fetch_invite( 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 approximate member counts. + 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 ------- From baa2253e0c0d00fb182d80eb3d84accf4524f712 Mon Sep 17 00:00:00 2001 From: davfsa Date: Sun, 6 Nov 2022 02:35:04 +0100 Subject: [PATCH 8/8] Remove whitespaces Signed-off-by: davfsa --- hikari/api/rest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hikari/api/rest.py b/hikari/api/rest.py index f85d5cad01..fea1d4fbcb 100644 --- a/hikari/api/rest.py +++ b/hikari/api/rest.py @@ -2777,11 +2777,11 @@ async def fetch_invite( 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