def likes(self, type=None, **kwargs): if type and type not in ['comments', 'lists']: raise ValueError('Unknown type specified: %r' % type) if kwargs.get('parse') is False: raise ValueError('Parse can\'t be disabled on this method') # Send request response = self.http.get( 'likes', params=[type], **popitems(kwargs, ['authenticated', 'validate_token'])) # Parse response items = self.get_data(response, **kwargs) if not items: return # Map items to comment/list objects for item in items: item_type = item.get('type') if item_type == 'comment': yield CommentMapper.comment(self.client, item) elif item_type == 'list': yield ListMapper.custom_list(self.client, item) else: log.warn('Unknown item returned, type: %r', item_type)
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 likes(self, type=None, **kwargs): if type and type not in ['comments', 'lists']: raise ValueError('Unknown type specified: %r' % type) # Send request response = self.http.get('likes', params=[ type ]) if response.status_code < 200 or response.status_code >= 300: return # Parse response items = self.get_data(response, **kwargs) # Map items to comment/list objects for item in items: item_type = item.get('type') if item_type == 'comment': yield CommentMapper.comment( self.client, item ) elif item_type == 'list': yield ListMapper.custom_list( self.client, item ) else: log.warn('Unknown item returned, type: %r', item_type)
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' % username, data=data) 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 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' % username, data=data ) 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 likes(self, type=None): if type and type not in ['comments', 'lists']: raise ValueError('Unknown type specified: %r', type) # Send request response = self.http.get('likes', params=[ type ]) if response.status_code < 200 or response.status_code >= 300: return # Parse response items = self.get_data(response) # Map items to comment/list objects for item in items: item_type = item.get('type') if item_type == 'comment': yield CommentMapper.comment( self.client, item ) elif item_type == 'list': yield ListMapper.custom_list( self.client, item ) else: log.warn('Unknown item returned, type: %r', item_type)
def _map(self, item): item_type = item.get('type') if item_type == 'comment': return CommentMapper.comment(self.client, item) if item_type == 'list': return ListMapper.custom_list(self.client, item) log.warning('Unknown item returned, type: %r', item_type) return None
def get(self, username, id): response = self.http.get('/users/%s/lists/%s' % (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 trending(self, page=None, per_page=None, **kwargs): response = self.http.get('trending', query={ 'page': page, 'limit': per_page }, **dictfilter(kwargs, get=['exceptions'], pop=['pagination'])) # Parse response items = self.get_data(response, **kwargs) if isinstance(items, PaginationIterator): return items.with_mapper( lambda items: ListMapper.public_lists(self.client, items)) if isinstance(items, requests.Response): return items return ListMapper.public_lists(self.client, items)
def get(self, username, **kwargs): # Send request response = self.http.get('/users/%s/lists' % username, ) if response.status_code < 200 or response.status_code >= 300: return # Parse response items = self.get_data(response) # 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, id): response = self.http.get( '/users/%s/lists/%s' % (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): 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 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, **kwargs): # Send request response = self.http.get( '/users/%s/lists' % username, ) if response.status_code < 200 or response.status_code >= 300: return # Parse response items = self.get_data(response) # Map items to list objects for item in items: yield ListMapper.custom_list( self.client, item, username=username )
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 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' % (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, **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 likes(self, type=None, **kwargs): if type and type not in ['comments', 'lists']: raise ValueError('Unknown type specified: %r' % type) if kwargs.get('parse') is False: raise ValueError('Parse can\'t be disabled on this method') # Send request response = self.http.get( 'likes', params=[type], **popitems(kwargs, [ 'authenticated', 'validate_token' ]) ) # Parse response items = self.get_data(response, **kwargs) if not items: return # Map items to comment/list objects for item in items: item_type = item.get('type') if item_type == 'comment': yield CommentMapper.comment( self.client, item ) elif item_type == 'list': yield ListMapper.custom_list( self.client, item ) else: log.warn('Unknown item returned, type: %r', item_type)
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)