Skip to content

Commit

Permalink
Merge a7a9359 into 4808727
Browse files Browse the repository at this point in the history
  • Loading branch information
milokmet committed Jun 7, 2020
2 parents 4808727 + a7a9359 commit ecb7bd4
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions trakt/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

# /users/
users.UsersInterface,
users.UsersProfileInterface,
users.UsersSettingsInterface,

# /users/following
Expand Down
2 changes: 2 additions & 0 deletions trakt/interfaces/users/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from trakt.interfaces.users.friends import UsersFriendsInterface
from trakt.interfaces.users.history import UsersHistoryInterface
from trakt.interfaces.users.lists import UsersListInterface, UsersListsInterface
from trakt.interfaces.users.profile import UsersProfileInterface
from trakt.interfaces.users.ratings import UsersRatingsInterface
from trakt.interfaces.users.settings import UsersSettingsInterface
from trakt.interfaces.users.watchlist import UsersWatchlistInterface
Expand All @@ -24,6 +25,7 @@
'UsersHistoryInterface',
'UsersListsInterface',
'UsersListInterface',
'UsersProfileInterface',
'UsersRatingsInterface',
'UsersSettingsInterface',
'UsersWatchlistInterface'
Expand Down
55 changes: 55 additions & 0 deletions trakt/interfaces/users/profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from __future__ import absolute_import, division, print_function

from trakt.core.helpers import clean_username, dictfilter
from trakt.interfaces.base import authenticated, Interface
from trakt.mapper import UserMapper

import requests


class UsersProfileInterface(Interface):
path = 'users/*'

def get(self, username, extended=None, **kwargs):
response = self.http.get(
'/users/%s' % (clean_username(username)),
query={
'extended': extended
},
**dictfilter(kwargs, get=[
'exceptions'
], pop=[
'authenticated',
'validate_token'
])
)

# Parse response
item = self.get_data(response, **kwargs)

if isinstance(item, requests.Response):
return item

if type(item) is not dict:
return None

return UserMapper.user(self.client, item)


@authenticated
def follow(self, username, **kwargs):
response = self.http.post(
'/users/%s/follow' % (clean_username(username))
)

return 200 <= response.status_code < 300



@authenticated
def unfollow(self, username, **kwargs):
response = self.http.delete(
'/users/%s/follow' % (clean_username(username))
)

return 200 <= response.status_code < 300
12 changes: 12 additions & 0 deletions trakt/objects/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ def pk(self):

return self.keys[0]

def follow(self, **kwargs):
return self._client['users/*'].follow(
self.id,
**kwargs
)

def following(self, **kwargs):
return self._client['users/*/following'].get(
self.id,
Expand All @@ -122,6 +128,12 @@ def ratings(self, **kwargs):
**kwargs
)

def unfollow(self, **kwargs):
return self._client['users/*'].unfollow(
self.id,
**kwargs
)

def watchlist(self, **kwargs):
return self._client['users/*/watchlist'].get(
self.id,
Expand Down

0 comments on commit ecb7bd4

Please sign in to comment.