-
Notifications
You must be signed in to change notification settings - Fork 44
/
__init__.py
168 lines (143 loc) · 5.61 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
"""
People - Access friendlist from own profiles and others
"""
from typing import List
from xbox.webapi.api.provider.baseprovider import BaseProvider
from xbox.webapi.api.provider.people.models import (
PeopleDecoration,
PeopleResponse,
PeopleSummaryResponse,
)
class PeopleProvider(BaseProvider):
SOCIAL_URL = "https://social.xboxlive.com"
HEADERS_SOCIAL = {"x-xbl-contract-version": "2"}
PEOPLE_URL = "https://peoplehub.xboxlive.com"
HEADERS_PEOPLE = {
"x-xbl-contract-version": "3",
"Accept-Language": "overwrite in __init__",
}
SEPERATOR = ","
def __init__(self, client):
"""
Initialize Baseclass, set 'Accept-Language' header from client instance
Args:
client (:class:`XboxLiveClient`): Instance of client
"""
super().__init__(client)
self._headers = {**self.HEADERS_PEOPLE}
self._headers.update({"Accept-Language": self.client.language.locale})
async def get_friends_own(
self, decoration_fields: List[PeopleDecoration] = None, **kwargs
) -> PeopleResponse:
"""
Get friendlist of own profile
Returns:
:class:`PeopleResponse`: People Response
"""
if not decoration_fields:
decoration_fields = [
PeopleDecoration.PREFERRED_COLOR,
PeopleDecoration.DETAIL,
PeopleDecoration.MULTIPLAYER_SUMMARY,
PeopleDecoration.PRESENCE_DETAIL,
]
decoration = self.SEPERATOR.join(decoration_fields)
url = f"{self.PEOPLE_URL}/users/me/people/social/decoration/{decoration}"
resp = await self.client.session.get(url, headers=self._headers, **kwargs)
resp.raise_for_status()
return PeopleResponse(**resp.json())
async def get_friends_by_xuid(
self, xuid: str, decoration_fields: List[PeopleDecoration] = None, **kwargs
) -> PeopleResponse:
"""
Get friendlist of own profile
Returns:
:class:`PeopleResponse`: People Response
"""
if not decoration_fields:
decoration_fields = [
PeopleDecoration.PREFERRED_COLOR,
PeopleDecoration.DETAIL,
PeopleDecoration.MULTIPLAYER_SUMMARY,
PeopleDecoration.PRESENCE_DETAIL,
]
decoration = self.SEPERATOR.join(decoration_fields)
url = f"{self.PEOPLE_URL}/users/xuid({xuid})/people/social/decoration/{decoration}"
resp = await self.client.session.get(url, headers=self._headers, **kwargs)
resp.raise_for_status()
return PeopleResponse(**resp.json())
async def get_friends_own_batch(
self,
xuids: List[str],
decoration_fields: List[PeopleDecoration] = None,
**kwargs,
) -> PeopleResponse:
"""
Get friends metadata by providing a list of XUIDs
Args:
xuids: List of XUIDs
Returns:
:class:`PeopleResponse`: People Response
"""
if not decoration_fields:
decoration_fields = [
PeopleDecoration.PREFERRED_COLOR,
PeopleDecoration.DETAIL,
PeopleDecoration.MULTIPLAYER_SUMMARY,
PeopleDecoration.PRESENCE_DETAIL,
]
decoration = self.SEPERATOR.join(decoration_fields)
url = f"{self.PEOPLE_URL}/users/me/people/batch/decoration/{decoration}"
resp = await self.client.session.post(
url, json={"xuids": xuids}, headers=self._headers, **kwargs
)
resp.raise_for_status()
return PeopleResponse(**resp.json())
async def get_friend_recommendations(self, **kwargs) -> PeopleResponse:
"""
Get recommended friends
Returns:
:class:`PeopleResponse`: People Response
"""
url = f"{self.PEOPLE_URL}/users/me/people/recommendations"
resp = await self.client.session.get(url, headers=self._headers, **kwargs)
resp.raise_for_status()
return PeopleResponse(**resp.json())
async def get_friends_summary_own(self, **kwargs) -> PeopleSummaryResponse:
"""
Get friendlist summary of own profile
Returns:
:class:`PeopleSummaryResponse`: People Summary Response
"""
url = self.SOCIAL_URL + "/users/me/summary"
resp = await self.client.session.get(url, headers=self.HEADERS_SOCIAL, **kwargs)
resp.raise_for_status()
return PeopleSummaryResponse(**resp.json())
async def get_friends_summary_by_xuid(
self, xuid: str, **kwargs
) -> PeopleSummaryResponse:
"""
Get friendlist summary of user by xuid
Args:
xuid: XUID to request summary from
Returns:
:class:`PeopleSummaryResponse`: People Summary Response
"""
url = self.SOCIAL_URL + f"/users/xuid({xuid})/summary"
resp = await self.client.session.get(url, headers=self.HEADERS_SOCIAL, **kwargs)
resp.raise_for_status()
return PeopleSummaryResponse(**resp.json())
async def get_friends_summary_by_gamertag(
self, gamertag: str, **kwargs
) -> PeopleSummaryResponse:
"""
Get friendlist summary of user by gamertag
Args:
gamertag: Gamertag to request friendlist from
Returns:
:class:`PeopleSummaryResponse`: People Summary Response
"""
url = self.SOCIAL_URL + f"/users/gt({gamertag})/summary"
resp = await self.client.session.get(url, headers=self.HEADERS_SOCIAL, **kwargs)
resp.raise_for_status()
return PeopleSummaryResponse(**resp.json())