giphypop.py
def search(self, term=None, phrase=None, limit=DEFAULT_SEARCH_LIMIT,
               rating=None):
        """
        Search for gifs with a given word or phrase. Punctuation is ignored.
        By default, this will perform a `term` search. If you want to search
        by phrase, use the `phrase` keyword argument. What's the difference
        between `term` and `phrase` searches? Simple: a term search will
        return results matching any words given, whereas a phrase search will
        match all words.

        Note that this method is a GiphyImage generator that
        automatically handles api paging. Optionally accepts a limit that will
        terminate the generation after a specified number of results have been
        yielded. This defaults to 25 results; a None implies no limit

        :param term: Search term or terms
        :type term: string
        :param phrase: Search phrase
        :type phrase: string
        :param limit: Maximum number of results to yield
        :type limit: int
        :param rating: limit results to those rated (y,g, pg, pg-13 or r).
        :type rating: string
        """
        assert any((term, phrase)), 'You must supply a term or phrase to search'

        # Phrases should have dashes and not spaces
        if phrase:
            phrase = phrase.replace(' ', '-')

        results_yielded = 0  # Count how many things we yield
        page, per_page = 0, 25
        params = {'q': (term or phrase)}
        if rating:
            params.update({'rating': rating})
        fetch = partial(self._fetch, 'search', **params)

        # Generate results until we 1) run out of pages 2) reach a limit
        while True:
            data = fetch(offset=page, limit=per_page)
            page += per_page

            # Guard for empty results
            if not data['data']:
                raise StopIteration

            for item in data['data']:
                results_yielded += 1
                yield GiphyImage(item)

                if limit is not None and results_yielded >= limit:
                    raise StopIteration

            # Check yieled limit and whether or not there are more items
            if (page >= data['pagination']['total_count'] or
                    (limit is not None and results_yielded >= limit)):
                raise StopIteration
def search(self, term=None, phrase=None, limit=DEFAULT_SEARCH_LIMIT,
               rating=None):
        """
        Search for gifs with a given word or phrase. Punctuation is ignored.
        By default, this will perform a `term` search. If you want to search
        by phrase, use the `phrase` keyword argument. What's the difference
        between `term` and `phrase` searches? Simple: a term search will
        return results matching any words given, whereas a phrase search will
        match all words.

        Note that this method is a GiphyImage generator that
        automatically handles api paging. Optionally accepts a limit that will
        terminate the generation after a specified number of results have been
        yielded. This defaults to 25 results; a None implies no limit

        :param term: Search term or terms
        :type term: string
        :param phrase: Search phrase
        :type phrase: string
        :param limit: Maximum number of results to yield
        :type limit: int
        :param rating: limit results to those rated (y,g, pg, pg-13 or r).
        :type rating: string
        """
        assert any((term, phrase)), 'You must supply a term or phrase to search'

        # Phrases should have dashes and not spaces
        if phrase:
            phrase = phrase.replace(' ', '-')

        results_yielded = 0  # Count how many things we yield
        page, per_page = 0, 25
        params = {'q': (term or phrase)}
        if rating:
            params.update({'rating': rating})
        fetch = partial(self._fetch, 'search', **params)

        # Generate results until we 1) run out of pages 2) reach a limit
        while True:
            data = fetch(offset=page, limit=per_page)
            page += per_page

            # Guard for empty results
            if not data['data']:
                raise StopIteration

            for item in data['data']:
                results_yielded += 1
                yield GiphyImage(item)

                if limit is not None and results_yielded >= limit:
                    raise StopIteration

            # Check yieled limit and whether or not there are more items
            if (page >= data['pagination']['total_count'] or
                    (limit is not None and results_yielded >= limit)):
                raise StopIteration
Search for gifs with a given word or phrase. Punctuation is ignored.
        By default, this will perform a `term` search. If you want to search
        by phrase, use the `phrase` keyword argument. What's the difference
        between `term` and `phrase` searches? Simple: a term search will
        return results matching any words given, whereas a phrase search will
        match all words.

        Note that this method is a GiphyImage generator that
        automatically handles api paging. Optionally accepts a limit that will
        terminate the generation after a specified number of results have been
        yielded. This defaults to 25 results; a None implies no limit

        :param term: Search term or terms
        :type term: string
        :param phrase: Search phrase
        :type phrase: string
        :param limit: Maximum number of results to yield
        :type limit: int
        :param rating: limit results to those rated (y,g, pg, pg-13 or r).
        :type rating: string