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

Commit c42cb6c

Browse files
committed
favorite() and remove_favorite()
1 parent 4557eea commit c42cb6c

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

vrcpy/aobjects.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ async def author(self):
88
resp = await self.client.api.call("/users/"+self.authorId)
99
return User(self.client, resp["data"])
1010

11+
async def favorite(self):
12+
'''
13+
Returns favorite object
14+
'''
15+
16+
resp = await self.client.api.call("/favorites", "POST", params={"type": types.FavoriteType.Avatar,\
17+
"favoriteId": self.id})
18+
return Favorite(resp["data"])
19+
1120
## User
1221

1322
class LimitedUser(o.LimitedUser):
@@ -44,6 +53,15 @@ async def friend(self):
4453
resp = await self.client.api.call("/user/"+self.id+"/friendRequest", "POST")
4554
return o.Notification(self.client, resp["data"])
4655

56+
async def favorite(self):
57+
'''
58+
Returns favorite object
59+
'''
60+
61+
resp = await self.client.api.call("/favorites", "POST", params={"type": types.FavoriteType.Friend,\
62+
"favoriteId": self.id})
63+
return Favorite(resp["data"])
64+
4765
class User(o.User, LimitedUser):
4866
async def fetch_full(self):
4967
user = await LimitedUser.fetch_full(self)
@@ -60,6 +78,10 @@ async def friend(self):
6078
notif = await LimitedUser.friend()
6179
return notif
6280

81+
async def favorite(self):
82+
resp = await LimitedUser.favorite(self)
83+
return resp
84+
6385
class CurrentUser(o.CurrentUser, User):
6486
obj = "CurrentUser"
6587

@@ -77,6 +99,12 @@ async def unfriend(self):
7799
async def friend(self):
78100
raise AttributeError("'CurrentUser' object has no attribute 'friend'")
79101

102+
async def favorite(self):
103+
raise AttributeError("'CurrentUser' object has no attribute 'favorite'")
104+
105+
async def remove_favorite(self, id):
106+
resp = await self.client.api.call("/favorites/"+id, "DELETE")
107+
80108
async def update_info(self, email=None, status=None,\
81109
statusDescription=None, bio=None, bioLinks=None):
82110

@@ -153,6 +181,15 @@ async def author(self):
153181
resp = await self.client.api.call("/users/"+self.authorId)
154182
return User(self.client, resp["data"])
155183

184+
async def favorite(self):
185+
'''
186+
Returns favorite object
187+
'''
188+
189+
resp = await self.client.api.call("/favorites", "POST", params={"type": types.FavoriteType.World,\
190+
"favoriteId": self.id})
191+
return Favorite(resp["data"])
192+
156193
class World(o.World, LimitedWorld):
157194
async def author(self):
158195
resp = await super(LimitedWorld, self).author()
@@ -169,6 +206,10 @@ async def fetch_instance(self, id):
169206
resp = await self.client.api.call("/instances/"+self.id+":"+id)
170207
return Instance(self.client, resp["data"])
171208

209+
async def favorite(self):
210+
resp = await LimitedWorld.favorite(self)
211+
return resp
212+
172213
async def __cinit__(self):
173214
instances = []
174215
for instance in self.instances:

vrcpy/objects.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ def author(self):
5959
resp = self.client.api.call("/users/"+self.authorId)
6060
return User(self.client, resp["data"])
6161

62+
def favorite(self):
63+
'''
64+
Returns favorite object
65+
'''
66+
67+
resp = self.client.api.call("/favorites", "POST", params={"type": types.FavoriteType.Avatar,\
68+
"favoriteId": self.id})
69+
return Favorite(resp["data"])
70+
6271
def __init__(self, client, obj):
6372
super().__init__(client)
6473
self.unique += [
@@ -98,7 +107,7 @@ def public_avatars(self):
98107

99108
def unfriend(self):
100109
'''
101-
Returns void
110+
Unfriends user
102111
'''
103112

104113
resp = self.client.api.call("/auth/user/friends/"+self.id, "DELETE")
@@ -111,6 +120,15 @@ def friend(self):
111120
resp = self.client.api.call("/user/"+self.id+"/friendRequest", "POST")
112121
return Notification(self.client, resp["data"])
113122

123+
def favorite(self):
124+
'''
125+
Returns favorite object
126+
'''
127+
128+
resp = self.client.api.call("/favorites", "POST", params={"type": types.FavoriteType.Friend,\
129+
"favoriteId": self.id})
130+
return Favorite(resp["data"])
131+
114132
def __init__(self, client, obj=None):
115133
super().__init__(client)
116134
self.unique += [
@@ -186,6 +204,12 @@ def fetch_favorites(self, t):
186204

187205
return f
188206

207+
def remove_favorite(self, id):
208+
resp = self.client.api.call("/favorites/"+id, "DELETE")
209+
210+
def favorite(self):
211+
raise AttributeError("'CurrentUser' object has no attribute 'favorite'")
212+
189213
def __cinit__(self):
190214
if hasattr(self, "currentAvatar"):
191215
self.currentAvatar = self.client.fetch_avatar(self.currentAvatar)
@@ -253,6 +277,15 @@ def author(self):
253277
resp = self.client.api.call("/users/"+self.authorId)
254278
return User(self.client, resp["data"])
255279

280+
def favorite(self):
281+
'''
282+
Returns favorite object
283+
'''
284+
285+
resp = self.client.api.call("/favorites", "POST", params={"type": types.FavoriteType.World,\
286+
"favoriteId": self.id})
287+
return Favorite(resp["data"])
288+
256289
def __init__(self, client, obj=None):
257290
super().__init__(client)
258291
self.unique += [

0 commit comments

Comments
 (0)