Skip to content

Commit 74adc45

Browse files
committed
Rate limits are only known for social.xboxlive.com
This commit removes the rate_limits passing from get_friends_own (peoplehub.xboxlive.com) as it is not explicitly known what rate limits apply to this domain. This commit adds rate_limits passing all to functions that call social.xboxlive.com: - get_friends_summary_own - get_friends_summary_by_xuid - get_friends_summary_by_gamertag This commit also updates the test 'test_ratelimits_exceeded_burst_only' to use a function calling social.xboxlive.com (Test would otherwise break as previous function no longer passes rate_limits)
1 parent c2ee539 commit 74adc45

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

tests/test_ratelimits.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,11 @@ class child_class(RateLimitedProvider):
107107
@pytest.mark.asyncio
108108
async def test_ratelimits_exceeded_burst_only(respx_mock, xbl_client):
109109
async def make_request():
110-
route = respx_mock.get("https://peoplehub.xboxlive.com").mock(
111-
return_value=Response(200, json=get_response_json("people_friends_own"))
110+
route = respx_mock.get("https://social.xboxlive.com").mock(
111+
return_value=Response(200, json=get_response_json("people_summary_own"))
112112
)
113-
ret = await xbl_client.people.get_friends_own()
113+
ret = await xbl_client.people.get_friends_summary_own()
114114

115-
assert len(ret.people) == 2
116115
assert route.called
117116

118117
# Record the start time to ensure that the timeouts are the correct length

xbox/webapi/api/provider/people/__init__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class PeopleProvider(RateLimitedProvider):
2121
}
2222
SEPERATOR = ","
2323

24+
# NOTE: Rate Limits are noted for social.xboxlive.com ONLY
2425
RATE_LIMITS = {"burst": 10, "sustain": 30}
2526

2627
def __init__(self, client):
@@ -53,9 +54,7 @@ async def get_friends_own(
5354
decoration = self.SEPERATOR.join(decoration_fields)
5455

5556
url = f"{self.PEOPLE_URL}/users/me/people/social/decoration/{decoration}"
56-
resp = await self.client.session.get(
57-
url, headers=self._headers, rate_limits=self.rate_limit_read, **kwargs
58-
)
57+
resp = await self.client.session.get(url, headers=self._headers, **kwargs)
5958
resp.raise_for_status()
6059
return PeopleResponse(**resp.json())
6160

@@ -133,7 +132,9 @@ async def get_friends_summary_own(self, **kwargs) -> PeopleSummaryResponse:
133132
:class:`PeopleSummaryResponse`: People Summary Response
134133
"""
135134
url = self.SOCIAL_URL + "/users/me/summary"
136-
resp = await self.client.session.get(url, headers=self.HEADERS_SOCIAL, **kwargs)
135+
resp = await self.client.session.get(
136+
url, headers=self.HEADERS_SOCIAL, rate_limits=self.rate_limit_read, **kwargs
137+
)
137138
resp.raise_for_status()
138139
return PeopleSummaryResponse(**resp.json())
139140

@@ -150,7 +151,9 @@ async def get_friends_summary_by_xuid(
150151
:class:`PeopleSummaryResponse`: People Summary Response
151152
"""
152153
url = self.SOCIAL_URL + f"/users/xuid({xuid})/summary"
153-
resp = await self.client.session.get(url, headers=self.HEADERS_SOCIAL, **kwargs)
154+
resp = await self.client.session.get(
155+
url, headers=self.HEADERS_SOCIAL, rate_limits=self.rate_limit_read, **kwargs
156+
)
154157
resp.raise_for_status()
155158
return PeopleSummaryResponse(**resp.json())
156159

@@ -167,6 +170,8 @@ async def get_friends_summary_by_gamertag(
167170
:class:`PeopleSummaryResponse`: People Summary Response
168171
"""
169172
url = self.SOCIAL_URL + f"/users/gt({gamertag})/summary"
170-
resp = await self.client.session.get(url, headers=self.HEADERS_SOCIAL, **kwargs)
173+
resp = await self.client.session.get(
174+
url, headers=self.HEADERS_SOCIAL, rate_limits=self.rate_limit_read, **kwargs
175+
)
171176
resp.raise_for_status()
172177
return PeopleSummaryResponse(**resp.json())

0 commit comments

Comments
 (0)