def delete(self, username, id): # Send request response = self.http.delete( '/users/%s/lists/%s' % (clean_username(username), id) ) return 200 <= response.status_code < 300
def unlike(self, username, id, **kwargs): # Send request response = self.http.delete( '/users/%s/lists/%s/like' % (clean_username(username), id), **dictfilter(kwargs, pop=['authenticated', 'validate_token'])) return 200 <= response.status_code < 300
def items(self, username, id, media=None, extended=None, page=None, per_page=None, **kwargs): response = self.http.get( '/users/%s/lists/%s/items' % (clean_username(username), id), query={ 'type': media, 'extended': extended, 'page': page, 'limit': per_page }, **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: ListItemMapper.process_many(self.client, items)) if isinstance(items, requests.Response): return items return ListItemMapper.process_many(self.client, items)
def get(self, username, **kwargs): """Retrieve lists for user. :param username: Username (or :code:`me`) :type username: :class:`~python:str` :return: List :rtype: trakt.objects.CustomList """ if kwargs.get('parse') is False: raise ValueError("Parse can't be disabled on this method") # Send request response = self.http.get('/users/%s/lists' % clean_username(username), ) # Parse response items = self.get_data(response, **kwargs) if not items: return # Map items to list objects for item in items: yield ListMapper.custom_list(self.client, item, username=username)
def delete(self, username, id, **kwargs): # Send request response = self.http.delete( '/users/%s/lists/%s' % (clean_username(username), id), **popitems(kwargs, ['authenticated', 'validate_token'])) return 200 <= response.status_code < 300
def like(self, username, id, **kwargs): # Send request response = self.http.post( '/users/%s/lists/%s/like' % (clean_username(username), id) ) return 200 <= response.status_code < 300
def add(self, username, id, items, **kwargs): # Send request response = self.http.post( '/users/%s/lists/%s/items' % (clean_username(username), id), data=items, **popitems(kwargs, ['authenticated', 'validate_token'])) # Parse response return self.get_data(response, **kwargs)
def remove(self, username, id, items, **kwargs): # Send request response = self.http.post( '/users/%s/lists/%s/items/remove' % (clean_username(username), id), data=items, **dictfilter(kwargs, pop=['authenticated', 'validate_token'])) # Parse response return self.get_data(response, **kwargs)
def get(self, username, media=None, sort=None, store=None, extended=None, page=None, per_page=None, **kwargs): # Build parameters params = [] if media: params.append(media) if sort: params.append(sort) # Build query query = { 'extended': extended, 'page': page, 'limit': per_page } # Send request response = self.http.get( '/users/%s/watchlist' % (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 # Map items return SyncMapper.process( self.client, store, items, media=media, flat=True, **self.flags )
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)
def delete(self, username, id, **kwargs): # Send request response = self.http.delete( '/users/%s/lists/%s' % (clean_username(username), id), **popitems(kwargs, [ 'authenticated', 'validate_token' ]) ) return 200 <= response.status_code < 300
def add(self, username, id, items, **kwargs): # Send request response = self.http.post('/users/%s/lists/%s/items' % (clean_username(username), id), data=items) if response.status_code < 200 or response.status_code >= 300: return None # Parse response return self.get_data(response, **kwargs)
def add(self, username, id, items, **kwargs): # Send request response = self.http.post( '/users/%s/lists/%s/items' % (clean_username(username), id), data=items ) if response.status_code < 200 or response.status_code >= 300: return None # Parse response return self.get_data(response, **kwargs)
def add(self, username, id, items, **kwargs): # Send request response = self.http.post( '/users/%s/lists/%s/items' % (clean_username(username), id), data=items, **popitems(kwargs, [ 'authenticated', 'validate_token' ]) ) # Parse response return self.get_data(response, **kwargs)
def get(self, username, id): # Send request response = self.http.get( '/users/%s/lists/%s' % (clean_username(username), id), ) if response.status_code < 200 or response.status_code >= 300: return None # Parse response item = self.get_data(response) # Map item to list object return ListMapper.custom_list(self.client, item, username=username)
def get(self, username, **kwargs): # Send request response = self.http.get('/users/%s/lists' % clean_username(username), ) if response.status_code < 200 or response.status_code >= 300: return # Parse response items = self.get_data(response, **kwargs) # Map items to list objects for item in items: yield ListMapper.custom_list(self.client, item, username=username)
def update(self, username, id, name=None, description=None, privacy=None, display_numbers=None, allow_comments=None, return_type='object', **kwargs): data = { 'name': name, 'description': description, 'privacy': privacy, 'allow_comments': allow_comments, 'display_numbers': display_numbers } # Remove attributes with `None` values for key in list(data.keys()): if data[key] is not None: continue del data[key] # Send request response = self.http.put( '/users/%s/lists/%s' % (clean_username(username), id), data=data, **popitems(kwargs, ['authenticated', 'validate_token'])) # Parse response item = self.get_data(response, **kwargs) if isinstance(item, requests.Response): return item if not item: return None if return_type == 'data': return item if return_type == 'object': # Map item to list object return ListMapper.custom_list(self.client, item, username=username) raise ValueError('Unsupported value for "return_type": %r', return_type)
def update(self, username, id, name=None, description=None, privacy=None, display_numbers=None, allow_comments=None, return_type='object', **kwargs): data = { 'name': name, 'description': description, 'privacy': privacy, 'allow_comments': allow_comments, 'display_numbers': display_numbers } # Remove attributes with `None` values for key in list(data.keys()): if data[key] is not None: continue del data[key] # Send request response = self.http.put( '/users/%s/lists/%s' % (clean_username(username), id), data=data, **popitems(kwargs, [ 'authenticated', 'validate_token' ]) ) # Parse response item = self.get_data(response, **kwargs) if isinstance(item, requests.Response): return item if not item: return None if return_type == 'data': return item if return_type == 'object': # Map item to list object return ListMapper.custom_list( self.client, item, username=username ) raise ValueError("Unsupported value for \"return_type\": %r", return_type)
def get(self, username, id, **kwargs): # Send request response = self.http.get( '/users/%s/lists/%s' % (clean_username(username), id), ) # Parse response item = self.get_data(response, **kwargs) if isinstance(item, requests.Response): return item if not item: return None # Map item to list object return ListMapper.custom_list(self.client, item, username=username)
def get(self, username, **kwargs): if kwargs.get('parse') is False: raise ValueError('Parse can\'t be disabled on this method') # Send request response = self.http.get('/users/%s/lists' % clean_username(username), ) # Parse response items = self.get_data(response, **kwargs) if not items: return # Map items to list objects for item in items: yield ListMapper.custom_list(self.client, item, username=username)
def get(self, username, id): # Send request response = self.http.get( '/users/%s/lists/%s' % (clean_username(username), id), ) if response.status_code < 200 or response.status_code >= 300: return None # Parse response item = self.get_data(response) # Map item to list object return ListMapper.custom_list( self.client, item, username=username )
def update(self, username, id, name=None, description=None, privacy=None, display_numbers=None, allow_comments=None, return_type='object', **kwargs): data = { 'name': name, 'description': description, 'privacy': privacy, 'allow_comments': allow_comments, 'display_numbers': display_numbers } # Remove attributes with `None` values for key in list(data.keys()): if data[key] is not None: continue del data[key] # Send request response = self.http.put('/users/%s/lists/%s' % (clean_username(username), id), data=data) if response.status_code < 200 or response.status_code >= 300: return None # Parse response item = self.get_data(response) if return_type == 'data': return item if return_type == 'object': # Map item to list object return ListMapper.custom_list(self.client, item, username=username) raise ValueError("Unsupported value for \"return_type\": %r", return_type)
def get(self, username, extended=None, **kwargs): response = self.http.get( '/users/%s/following' % (clean_username(username)), query={'extended': extended}, **dictfilter(kwargs, get=['exceptions'], pop=['authenticated', 'validate_token'])) # Parse response items = self.get_data(response, **kwargs) if isinstance(items, requests.Response): return items if type(items) is not list: return None return UserMapper.users(self.client, items)
def items(self, username, id, **kwargs): # Send request response = self.http.get( '/users/%s/lists/%s/items' % (clean_username(username), id), ) if response.status_code < 200 or response.status_code >= 300: return None # Parse response items = self.get_data(response, **kwargs) if type(items) is not list: return None return [ ListItemMapper.process(self.client, item, index=x + 1) for x, item in enumerate(items) ]
def get(self, username, **kwargs): # Send request response = self.http.get( '/users/%s/lists' % clean_username(username), ) if response.status_code < 200 or response.status_code >= 300: return # Parse response items = self.get_data(response, **kwargs) # Map items to list objects for item in items: yield ListMapper.custom_list( self.client, item, username=username )
def items(self, username, id, **kwargs): # Send request response = self.http.get( '/users/%s/lists/%s/items' % (clean_username(username), id), ) # Parse response items = self.get_data(response, **kwargs) if isinstance(items, requests.Response): return items if not items or type(items) is not list: return None return [ ListItemMapper.process(self.client, item, index=x + 1) for x, item in enumerate(items) ]
def get(self, username, id, **kwargs): # Send request response = self.http.get( '/users/%s/lists/%s' % (clean_username(username), id), ) # Parse response item = self.get_data(response, **kwargs) if isinstance(item, requests.Response): return item if not item: return None # Map item to list object return ListMapper.custom_list( self.client, item, username=username )
def get(self, username, **kwargs): if kwargs.get('parse') is False: raise ValueError('Parse can\'t be disabled on this method') # Send request response = self.http.get( '/users/%s/lists' % clean_username(username), ) # Parse response items = self.get_data(response, **kwargs) if not items: return # Map items to list objects for item in items: yield ListMapper.custom_list( self.client, item, username=username )
def create(self, username, name, description=None, privacy='private', display_numbers=False, allow_comments=True, **kwargs): data = { 'name': name, 'description': description, 'privacy': privacy, 'allow_comments': allow_comments, 'display_numbers': display_numbers } # Remove attributes with `None` values for key in list(data.keys()): if data[key] is not None: continue del data[key] # Send request response = self.http.post('/users/%s/lists' % clean_username(username), data=data) # Parse response item = self.get_data(response, **kwargs) if isinstance(item, requests.Response): return item if not item: return None # Map item to list object return ListMapper.custom_list(self.client, item, username=username)
def like(self, username, id, **kwargs): # Send request response = self.http.post('/users/%s/lists/%s/like' % (clean_username(username), id)) return 200 <= response.status_code < 300
def create(self, username, name, description=None, privacy='private', display_numbers=False, allow_comments=True, sort_by='rank', sort_how='asc', **kwargs): """Create a new list. :param username: Username (or :code:`me`) :type username: :class:`~python:str` :param name: Name :type name: :class:`~python:str` :param description: Description :type description: :class:`~python:str` :param privacy: Privacy (:code:`private`, :code:`friends`, or :code:`public`) :type description: :class:`~python:str` :param display_numbers: Flag indicating this list displays numbers :type description: :class:`~python:bool` :param allow_comments: Flag indicating this list allows comments :type description: :class:`~python:bool` :param sort_by: Sort By (:code:`rank`, :code:`added`, :code:`title`, :code:`released`, :code:`runtime`, :code:`popularity`, :code:`percentage`, :code:`votes`, :code:`my_rating`, :code:`random`, :code:`watched`, :code:`collected`) :type sort_by: :class:`~python:str` :param sort_how: Sort Direction (:code:`asc`, or :code:`desc`) :type sort_how: :class:`~python:str` :return: List :rtype: trakt.objects.CustomList """ data = { 'name': name, 'description': description, 'privacy': privacy, 'allow_comments': allow_comments, 'display_numbers': display_numbers, 'sort_by': sort_by, 'sort_how': sort_how } # Remove attributes with `None` values for key in list(data.keys()): if data[key] is not None: continue del data[key] # Send request response = self.http.post('/users/%s/lists' % clean_username(username), data=data) # Parse response item = self.get_data(response, **kwargs) if isinstance(item, requests.Response): return item if not item: return None # Map item to list object return ListMapper.custom_list(self.client, item, username=username)
def unfollow(self, username, **kwargs): response = self.http.delete('/users/%s/follow' % (clean_username(username))) return 200 <= response.status_code < 300
def delete(self, username, id): # Send request response = self.http.delete('/users/%s/lists/%s' % (clean_username(username), id)) return 200 <= response.status_code < 300