Skip to content

Commit

Permalink
Merge pull request #82 from milokmet/user_profile1
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzeman committed Jun 9, 2020
2 parents 86eb0b2 + 464c178 commit d6beee6
Show file tree
Hide file tree
Showing 4 changed files with 67 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.watched import UsersWatchedInterface
Expand All @@ -25,6 +26,7 @@
'UsersHistoryInterface',
'UsersListsInterface',
'UsersListInterface',
'UsersProfileInterface',
'UsersRatingsInterface',
'UsersSettingsInterface',
'UsersWatchedInterface',
Expand Down
52 changes: 52 additions & 0 deletions trakt/interfaces/users/profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from __future__ import absolute_import, division, print_function

from trakt.core.helpers import clean_username, dictfilter
from trakt.interfaces.base import Interface, authenticated
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 d6beee6

Please sign in to comment.