-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from milokmet/develop
- Loading branch information
Showing
7 changed files
with
302 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[ | ||
{ | ||
"plays": 4, | ||
"last_watched_at": "2014-10-11T17:00:54.000Z", | ||
"last_updated_at": "2014-10-11T17:00:54.000Z", | ||
"movie": { | ||
"title": "Batman Begins", | ||
"year": 2005, | ||
"ids": { | ||
"trakt": 6, | ||
"slug": "batman-begins-2005", | ||
"imdb": "tt0372784", | ||
"tmdb": 272 | ||
} | ||
} | ||
}, | ||
{ | ||
"plays": 2, | ||
"last_watched_at": "2014-10-12T17:00:54.000Z", | ||
"last_updated_at": "2014-10-12T17:00:54.000Z", | ||
"movie": { | ||
"title": "The Dark Knight", | ||
"year": 2008, | ||
"ids": { | ||
"trakt": 4, | ||
"slug": "the-dark-knight-2008", | ||
"imdb": "tt0468569", | ||
"tmdb": 155 | ||
} | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
[ | ||
{ | ||
"plays": 56, | ||
"last_watched_at": "2014-10-11T17:00:54.000Z", | ||
"last_updated_at": "2014-10-11T17:00:54.000Z", | ||
"reset_at": null, | ||
"show": { | ||
"title": "Breaking Bad", | ||
"year": 2008, | ||
"ids": { | ||
"trakt": 1, | ||
"slug": "breaking-bad", | ||
"tvdb": 81189, | ||
"imdb": "tt0903747", | ||
"tmdb": 1396 | ||
} | ||
}, | ||
"seasons": [ | ||
{ | ||
"number": 1, | ||
"episodes": [ | ||
{ | ||
"number": 1, | ||
"plays": 1, | ||
"last_watched_at": "2014-10-11T17:00:54.000Z" | ||
}, | ||
{ | ||
"number": 2, | ||
"plays": 1, | ||
"last_watched_at": "2014-10-11T17:00:54.000Z" | ||
} | ||
] | ||
}, | ||
{ | ||
"number": 2, | ||
"episodes": [ | ||
{ | ||
"number": 1, | ||
"plays": 1, | ||
"last_watched_at": "2014-10-11T17:00:54.000Z" | ||
}, | ||
{ | ||
"number": 2, | ||
"plays": 1, | ||
"last_watched_at": "2014-10-11T17:00:54.000Z" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"plays": 23, | ||
"last_watched_at": "2014-10-12T17:00:54.000Z", | ||
"last_updated_at": "2014-10-12T17:00:54.000Z", | ||
"show": { | ||
"title": "Parks and Recreation", | ||
"year": 2009, | ||
"ids": { | ||
"trakt": 4, | ||
"slug": "parks-and-recreation", | ||
"tvdb": 84912, | ||
"imdb": "tt1266020", | ||
"tmdb": 8592 | ||
} | ||
}, | ||
"seasons": [ | ||
{ | ||
"number": 1, | ||
"episodes": [ | ||
{ | ||
"number": 1, | ||
"plays": 1, | ||
"last_watched_at": "2014-10-11T17:00:54.000Z" | ||
}, | ||
{ | ||
"number": 2, | ||
"plays": 1, | ||
"last_watched_at": "2014-10-11T17:00:54.000Z" | ||
} | ||
] | ||
}, | ||
{ | ||
"number": 2, | ||
"episodes": [ | ||
{ | ||
"number": 1, | ||
"plays": 1, | ||
"last_watched_at": "2014-10-11T17:00:54.000Z" | ||
}, | ||
{ | ||
"number": 2, | ||
"plays": 1, | ||
"last_watched_at": "2014-10-11T17:00:54.000Z" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
from tests.core import mock | ||
from trakt import Trakt | ||
|
||
from httmock import HTTMock | ||
import pytest | ||
|
||
|
||
def test_get(): | ||
with HTTMock(mock.fixtures, mock.unknown): | ||
with Trakt.configuration.auth('mock', 'mock'): | ||
|
||
with pytest.raises(ValueError): | ||
items = Trakt['users/*/watched'].get('me') | ||
|
||
with pytest.raises(ValueError): | ||
items = Trakt['users/*/watched'].get('me', 'episodes') | ||
|
||
items = Trakt['users/*/watched'].get('me', 'shows') | ||
|
||
assert items is not None | ||
|
||
items = list(items) | ||
|
||
assert len(items) == 2 | ||
|
||
assert items[0] is not None | ||
|
||
assert items[1] is not None | ||
|
||
assert items[0].title == 'Breaking Bad' | ||
|
||
assert items[0].keys == [ | ||
('tvdb', '81189'), | ||
('tmdb', '1396'), | ||
('imdb', 'tt0903747'), | ||
('slug', 'breaking-bad'), | ||
('trakt', '1') | ||
] | ||
|
||
assert items[1].title == 'Parks and Recreation' | ||
|
||
items = Trakt['users/*/watched'].get('me', 'movies') | ||
|
||
assert items is not None | ||
|
||
items = list(items) | ||
|
||
assert len(items) == 2 | ||
|
||
assert items[0] is not None | ||
|
||
assert items[1] is not None | ||
|
||
assert items[0].title == 'Batman Begins' | ||
|
||
assert items[1].title == 'The Dark Knight' | ||
|
||
assert items[1].keys == [ | ||
('imdb', 'tt0468569'), | ||
('tmdb', '155'), | ||
('slug', 'the-dark-knight-2008'), | ||
('trakt', '4') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
from trakt.core.helpers import clean_username, dictfilter | ||
from trakt.core.pagination import PaginationIterator | ||
from trakt.interfaces.base import Interface, authenticated | ||
from trakt.mapper import SyncMapper | ||
|
||
import requests | ||
|
||
|
||
class UsersWatchedInterface(Interface): | ||
path = 'users/*/watched' | ||
flags = {'is_watched': True} | ||
|
||
def get(self, username, media=None, store=None, extended=None, page=None, per_page=None, **kwargs): | ||
|
||
if not media or media not in ['shows', 'movies']: | ||
raise ValueError('The "media" have to be one of ["shows", "media"]') | ||
|
||
# Build parameters | ||
params = [] | ||
|
||
if media: | ||
params.append(media) | ||
|
||
# Build query | ||
query = { | ||
'extended': extended, | ||
'page': page, | ||
'limit': per_page | ||
} | ||
|
||
# Send request | ||
response = self.http.get( | ||
'/users/%s/watched' % (clean_username(username)), | ||
params=params, | ||
query=query, | ||
**dictfilter(kwargs, get=[ | ||
'exceptions' | ||
], pop=[ | ||
'authenticated', | ||
'pagination', | ||
'validate_token' | ||
]) | ||
) | ||
|
||
# Parse response | ||
items = self.get_data(response, **kwargs) | ||
|
||
if isinstance(items, PaginationIterator): | ||
return items.with_mapper(lambda items: SyncMapper.process( | ||
self.client, store, items, | ||
media=media, | ||
flat=True, | ||
**self.flags | ||
)) | ||
|
||
if isinstance(items, requests.Response): | ||
return items | ||
|
||
if type(items) is not list: | ||
return None | ||
|
||
return SyncMapper.process( | ||
self.client, store, items, | ||
media=media, | ||
flat=True, | ||
**self.flags | ||
) | ||
|
||
# | ||
# Shortcut methods | ||
# | ||
|
||
def movies(self, username, store=None, **kwargs): | ||
return self.get( | ||
username, 'movies', | ||
store=store, | ||
**kwargs | ||
) | ||
|
||
@authenticated | ||
def shows(self, username, store=None, **kwargs): | ||
return self.get( | ||
username, 'shows', | ||
store=store, | ||
**kwargs | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters