<commit_before>(function () {
  'use strict';

  angular.module('ng-giphy', [])

    .directive('giphyFind',  findGiphy)
    .directive('giphyId',    findGiphyById)
    .directive('giphyRand',  findRandGiphy)

    .factory('giphy',        giphyService)
    .provider('giphyConfig', giphyConfig)

    .config(ngGiphyConfig)
    .run(templateCache);

  // configure the provider to use the beta key
  ngGiphyConfig.$inject = ['giphyConfigProvider'];
  /* @ngInject */
  function ngGiphyConfig(giphyConfigProvider) {
    giphyConfigProvider.setKey('<KEY>');
  }

  /**
   * Directive: find gif by tag
   */
  function findGiphy() {
    return {
      scope: {
        q     : '=giphyTag',
        rating: '='
      },
      controller: findGiphyController,
      controllerAs: 'vm',
      bindToController: true,
      templateUrl: 'imgTemplate.html'
    };
  }

  findGiphyController.$inject = ['giphy'];
  /* @ngInject */
  function findGiphyController(giphy) {
    /* jshint validthis: true */
    var vm = this;

    giphy.find(vm.q, true).then(function (res) {
      vm.giphysrc = res;
    });
  }


  /**
   * Directive: find gif by id
   */
  function findGiphyById() {
    return {
      scope: {
        id    : '=giphyId',
        rating: '='
      },
      controller: findGiphyByIdController,
      controllerAs: 'vm',
      bindToController: true,
      templateUrl: 'imgTemplate.html'
    };
  }

  findGiphyByIdController.$inject = ['giphy'];
  /* @ngInject */
  function findGiphyByIdController(giphy) {
    /* jshint validthis: true */
    var vm = this;

    giphy.findById(vm.id, true).then(function (res) {
      vm.giphysrc = res;
    });
  }

  /**
   * Directive: find random gif by tag
   */
  function findRandGiphy() {
    return {
      scope: {
        q     : '=giphyTag',
        rating: '='
      },
      controller: findRandGiphyController,
      controllerAs: 'vm',
      bindToController: true,
      templateUrl: 'imgTemplate.html'
    };
  }

  findRandGiphyController.$inject = ['giphy'];
  /* @ngInject */
  function findRandGiphyController(giphy) {
    /* jshint validthis: true */
    var vm = this;

    giphy.random(vm.q, true).then(function (res) {
      vm.giphysrc = res;
    });
  }

  // services to interact with Giphy API endpoints
  giphyService.$inject = ['$http', 'giphyConfig'];
  /* @ngInject */
  function giphyService($http, giphyConfig) {

    var baseUrl = 'http://api.giphy.com/v1/gifs';

    var url = {
      random   : baseUrl + '/random?api_key=' + giphyConfig.key,
      find     : baseUrl + '/search?api_key=' + giphyConfig.key,
      findById : baseUrl + '/%s?api_key='     + giphyConfig.key
    };

    // expose the service API
    return {
      find        : find,
      findById    : findById,
      random      : random,
    };

    /**
     * Gets a gif url searching by tag
     *
     * @param {string} query
     * @param {Boolean} returnUrl
     * @return {string} gif url
     */
    function find(q, returnUrl){
      var query = q.constructor === Array ? q.join('+') : q;
      return $http.get(url.find + '&q=' + query).then(function (res) {
        return returnUrl ? res.data.data[0].images.original.url : res.data.data[0];
      });
    }

   /**
    * Gets a gif url searching by id
    *
    * @param {string} gif id
    * @param {Boolean} returnUrl
    * @return {string} gif url
    */
    function findById(id, returnUrl){
      return $http.get(url.findById.replace('%s', id)).then(function (res) {
        return returnUrl ? res.data.data.images.original.url : res.data.data;
      });
    }

    /**
     * Gets a random gif url searching by tag
     *
     * @param {string} query
     * @param {Boolean} returnUrl
     * @return {string} gif url
     */
    function random(q, returnUrl){
      var query = q.constructor === Array ? q.join('+') : q;
      return $http.get(url.random + '&tag=' + query).then(function (res) {
        return returnUrl ? res.data.data.image_url : res.data.data;
      });
    }<commit_msg>Added trending method to giphy api<commit_after>(function () {
  'use strict';

  angular.module('ng-giphy', [])

    .directive('giphyFind',  findGiphy)
    .directive('giphyId',    findGiphyById)
    .directive('giphyRand',  findRandGiphy)

    .factory('giphy',        giphyService)
    .provider('giphyConfig', giphyConfig)

    .config(ngGiphyConfig)
    .run(templateCache);

  // configure the provider to use the beta key
  ngGiphyConfig.$inject = ['giphyConfigProvider'];
  /* @ngInject */
  function ngGiphyConfig(giphyConfigProvider) {
    giphyConfigProvider.setKey('<KEY>');
  }

  /**
   * Directive: find gif by tag
   */
  function findGiphy() {
    return {
      scope: {
        q     : '=giphyTag',
        rating: '='
      },
      controller: findGiphyController,
      controllerAs: 'vm',
      bindToController: true,
      templateUrl: 'imgTemplate.html'
    };
  }

  findGiphyController.$inject = ['giphy'];
  /* @ngInject */
  function findGiphyController(giphy) {
    /* jshint validthis: true */
    var vm = this;

    giphy.find(vm.q, true).then(function (res) {
      vm.giphysrc = res;
    });
  }


  /**
   * Directive: find gif by id
   */
  function findGiphyById() {
    return {
      scope: {
        id    : '=giphyId',
        rating: '='
      },
      controller: findGiphyByIdController,
      controllerAs: 'vm',
      bindToController: true,
      templateUrl: 'imgTemplate.html'
    };
  }

  findGiphyByIdController.$inject = ['giphy'];
  /* @ngInject */
  function findGiphyByIdController(giphy) {
    /* jshint validthis: true */
    var vm = this;

    giphy.findById(vm.id, true).then(function (res) {
      vm.giphysrc = res;
    });
  }

  /**
   * Directive: find random gif by tag
   */
  function findRandGiphy() {
    return {
      scope: {
        q     : '=giphyTag',
        rating: '='
      },
      controller: findRandGiphyController,
      controllerAs: 'vm',
      bindToController: true,
      templateUrl: 'imgTemplate.html'
    };
  }

  findRandGiphyController.$inject = ['giphy'];
  /* @ngInject */
  function findRandGiphyController(giphy) {
    /* jshint validthis: true */
    var vm = this;

    giphy.random(vm.q, true).then(function (res) {
      vm.giphysrc = res;
    });
  }

  // services to interact with Giphy API endpoints
  giphyService.$inject = ['$http', 'giphyConfig'];
  /* @ngInject */
  function giphyService($http, giphyConfig) {

    var baseUrl = 'http://api.giphy.com/v1/gifs';

    var url = {
      random   : baseUrl + '/random?api_key='   + giphyConfig.key,
      find     : baseUrl + '/search?api_key='   + giphyConfig.key,
      findById : baseUrl + '/%s?api_key='       + giphyConfig.key,
      trending : baseUrl + '/trending?api_key=' + giphyConfig.key,
    };

    // expose the service API
    return {
      find        : find,
      findById    : findById,
      random      : random,
      trending    : trending
    };

    /**
     * Gets a gif url searching by tag
     *
     * @param {string} query
     * @param {Boolean} returnUrl
     * @return {string} gif url
     */
    function find(q, returnUrl){
      var query = q.constructor === Array ? q.join('+') : q;
      return $http.get(url.find + '&q=' + query).then(function (res) {
        return returnUrl ? res.data.data[0].images.original.url : res.data.data[0];
      });
    }

   /**
    * Gets a gif url searching by id
    *
    * @param {string} gif id
    * @param {Boolean} returnUrl
    * @return {string} gif url
    */
    function findById(id, returnUrl){
      return $http.get(url.findById.replace('%s', id)).then(function (res) {
        return returnUrl ? res.data.data.images.original.url : res.data.data;
      });
    }

    /**
     * Gets a random gif url searching by tag
     *
     * @param {string} query
     * @param {Boolean} returnUrl
     * @return {string} gif url
     */
    function random(q, returnUrl){
      var query = q.constructor === Array ? q.join('+') : q;
      return $http.get(url.random + '&tag=' + query).then(function (res) {
        return returnUrl ? res.data.data.image_url : res.data.data;
      });
    }

    /**
     * Fetch GIFs currently trending online. Hand curated by the Giphy editorial team.
     * The data returned mirrors the GIFs showcased on the Giphy homepage. Returns 25 results by default.
     *
     * @param {Number} limit
     * @param {Boolean} rating
     * @return {string} gif url
     */
    function trending(limit, rating) {
      return $http.get(url.trending + '&limit=' + limit).then(function (res) {
        return res.data.data;
      });
    }
{'fraction_non_alphanumeric': 0.1441828094188609, 'fraction_numerical': 0.0009279665932026447, 'mean_word_length': 2.2983932670237186, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2526218', 'n_tokens_mistral': 2995, 'n_tokens_neox': 2947, 'n_words': 621}