Skip to content
This repository was archived by the owner on Dec 28, 2021. It is now read-only.

Commit dea6b5b

Browse files
Ethan ChrispEthan Chrisp
Ethan Chrisp
authored and
Ethan Chrisp
committed
Add Friend Feed Favoriting functionality (#8)
1 parent 8cf6ddc commit dea6b5b

File tree

4 files changed

+141
-3
lines changed

4 files changed

+141
-3
lines changed

callofduty/client.py

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ async def SetFeedReaction(
189189
"category": category,
190190
}
191191

192-
return await self.http.SetFeedReaction(reaction.value, json)
192+
await self.http.SetFeedReaction(reaction.value, json)
193193

194194
async def RemoveFeedReaction(
195195
self,
@@ -231,7 +231,91 @@ async def RemoveFeedReaction(
231231
"category": category,
232232
}
233233

234-
return await self.http.SetFeedReaction(Reaction.Remove.value, json)
234+
await self.http.SetFeedReaction(Reaction.Remove.value, json)
235+
236+
async def SetFeedFavorite(
237+
self,
238+
platform: Platform,
239+
username: str,
240+
title: Title,
241+
date: int,
242+
category: str,
243+
) -> None:
244+
"""
245+
Set a Call of Duty Friend Feed item as a favorite.
246+
247+
Parameters
248+
----------
249+
platform : callofduty.Platform
250+
Platform to get the player from.
251+
username : str
252+
Player's username for the designated platform.
253+
title : callofduty.Title
254+
Title of the feed item.
255+
date : int
256+
Timstamp of the feed item.
257+
category : str
258+
Category of the feed item.
259+
260+
Returns
261+
-------
262+
None
263+
"""
264+
265+
VerifyPlatform(platform)
266+
VerifyTitle(title)
267+
268+
json: dict = {
269+
"username": username,
270+
"platform": platform.value,
271+
"title": title.value,
272+
"date": date,
273+
"category": category,
274+
}
275+
276+
await self.http.SetFeedFavorite(1, json)
277+
278+
async def RemoveFeedFavorite(
279+
self,
280+
platform: Platform,
281+
username: str,
282+
title: Title,
283+
date: int,
284+
category: str,
285+
) -> None:
286+
"""
287+
Unset a Call of Duty Friend Feed item as a favorite.
288+
289+
Parameters
290+
----------
291+
platform : callofduty.Platform
292+
Platform to get the player from.
293+
username : str
294+
Player's username for the designated platform.
295+
title : callofduty.Title
296+
Title of the feed item.
297+
date : int
298+
Timstamp of the feed item.
299+
category : str
300+
Category of the feed item.
301+
302+
Returns
303+
-------
304+
None
305+
"""
306+
307+
VerifyPlatform(platform)
308+
VerifyTitle(title)
309+
310+
json: dict = {
311+
"username": username,
312+
"platform": platform.value,
313+
"title": title.value,
314+
"date": date,
315+
"category": category,
316+
}
317+
318+
await self.http.SetFeedFavorite(0, json)
235319

236320
async def GetMyIdentities(self) -> list:
237321
"""

callofduty/feed.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,41 @@ async def unreact(self) -> None:
8989
None
9090
"""
9191

92-
return await self._client.RemoveFeedReaction(
92+
await self._client.RemoveFeedReaction(
93+
self.player.platform,
94+
self.player.username,
95+
self.title,
96+
(self.date.timestamp() * 1000),
97+
self.category,
98+
)
99+
100+
async def favorite(self) -> None:
101+
"""
102+
Set the Call of Duty Friend Feed item as a favorite.
103+
104+
Returns
105+
-------
106+
None
107+
"""
108+
109+
await self._client.SetFeedFavorite(
110+
self.player.platform,
111+
self.player.username,
112+
self.title,
113+
(self.date.timestamp() * 1000),
114+
self.category,
115+
)
116+
117+
async def unfavorite(self) -> None:
118+
"""
119+
Unset the Call of Duty Friend Feed item as a favorite.
120+
121+
Returns
122+
-------
123+
None
124+
"""
125+
126+
await self._client.RemoveFeedFavorite(
93127
self.player.platform,
94128
self.player.username,
95129
self.title,

callofduty/http.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ async def SetFeedReaction(self, reaction: str, json: dict) -> Union[dict, str]:
175175
)
176176
)
177177

178+
async def SetFeedFavorite(self, set: int, json: dict) -> Union[dict, str]:
179+
return await self.Send(
180+
Request(
181+
"POST",
182+
f"api/papi-client/userfeed/v1/favorite/set/{set}/en",
183+
baseUrl=Request.myBaseUrl,
184+
json=json,
185+
)
186+
)
187+
178188
async def GetMyIdentities(self) -> Union[dict, str]:
179189
return await self.Send(Request("GET", "api/papi-client/crm/cod/v2/identities/"))
180190

test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ async def main():
9696
# print(item.text)
9797
# await item.unreact()
9898

99+
# feed = await client.GetFriendFeed(limit=1)
100+
# for item in feed:
101+
# print(item.text)
102+
# test = await item.favorite()
103+
104+
# feed = await client.GetFriendFeed(limit=1)
105+
# for item in feed:
106+
# print(item.text)
107+
# await item.unfavorite()
108+
99109
# maps = await client.GetAvailableMaps(Title.ModernWarfare)
100110
# for mapName in maps:
101111
# print(mapName)

0 commit comments

Comments
 (0)