Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
    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)
Пример #4
0
    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)
Пример #5
0
    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
Пример #6
0
    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
Пример #7
0
    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)
Пример #8
0
    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)
Пример #9
0
    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
        )
Пример #10
0
    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)
Пример #11
0
    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
Пример #12
0
    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)
Пример #13
0
    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)
Пример #14
0
    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)
Пример #15
0
    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)
Пример #16
0
    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)
Пример #17
0
    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)
Пример #18
0
    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)
Пример #19
0
    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)
Пример #20
0
    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)
Пример #21
0
    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
        )
Пример #22
0
    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)
Пример #23
0
    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)
Пример #24
0
    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)
        ]
Пример #25
0
    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
            )
Пример #26
0
    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)
        ]
Пример #27
0
    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)
        ]
Пример #28
0
    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)
        ]
Пример #29
0
    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
        )
Пример #30
0
    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
            )
Пример #31
0
    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)
Пример #32
0
    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
Пример #33
0
    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)
Пример #34
0
    def unfollow(self, username, **kwargs):
        response = self.http.delete('/users/%s/follow' %
                                    (clean_username(username)))

        return 200 <= response.status_code < 300
Пример #35
0
    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