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

  angular.module('app.resources')
    .factory('CollectionsApi', CollectionsApiFactory);

  /** @ngInject */
  function CollectionsApiFactory($http, API_BASE) {
    var service = {
      query: query,
      get: get,
      post: post,
      delete: remove,
    };

    return service;

    function query(collection, options) {
      var url = API_BASE + '/api/' + collection;

      // $log.debug("query = " + url + buildQuery(options));

      return $http.get(url + buildQuery(options), buildConfig(options))
        .then(handleSuccess);

      function handleSuccess(response) {
        return response.data;
      }
    }

    function get(collection, id, options) {
      var url = API_BASE + '/api/' + collection + '/' + id;

      // $log.debug("get = " + url + buildQuery(options));

      return $http.get(url + buildQuery(options), buildConfig(options))
        .then(handleSuccess);

      function handleSuccess(response) {
        return response.data;
      }
    }

    function post(collection, id, options, data) {
      var url = API_BASE + '/api/' + collection + '/' + (id || "") + buildQuery(options);

      // $log.debug("post = " + url + buildQuery(options));

      return $http.post(url, data, buildConfig(options))
        .then(handleSuccess);

      function handleSuccess(response) {
        return response.data;
      }
    }

    // delete is a reserved word in JS
    function remove(collection, id, options) {
      var url = API_BASE + '/api/' + collection + '/' + (id || "") + buildQuery(options);

      // $log.debug("post = " + url + buildQuery(options));

      return $http.delete(url, buildConfig(options))
        .then(handleSuccess);

      function handleSuccess(response) {
        return response.data;
      }
    }

    // Private

    function buildQuery(options) {
      var params = [];
      options = options || {};

      if (options.expand) {
        if (angular.isArray(options.expand)) {
          options.expand = options.expand.join(',');
        }
        params.push('expand=' + encodeURIComponent(options.expand));
      }

      if (options.attributes) {
        if (angular.isArray(options.attributes)) {
          options.attributes = options.attributes.join(',');
        }
        params.push('attributes=' + encodeURIComponent(options.attributes));
      }

      if (options.decorators) {
        if (angular.isArray(options.decorators)) {
          options.decorators = options.decorators.join(',');
        }
        params.push('decorators=' + encodeURIComponent(options.decorators));
      }

      if (options.filter) {
        angular.forEach(options.filter, function(filter) {
          params.push('filter[]=' + encodeURIComponent(filter));
        });
      }

      if (options.limit) {
        params.push('limit=' + encodeURIComponent(options.limit));
      }

      if (options.offset) {
        params.push('offset=' + encodeURIComponent(options.offset));
      }

      if (options.hide) {
        params.push('hide=' + encodeURIComponent(options.hide));
      }

      if (options.sort_by) {
        params.push('sort_by=' + encodeURIComponent(options.sort_by));
      }

      if (options.sort_order) {
        params.push('sort_order=' + encodeURIComponent(options.sort_order));
      }

      if (options.sort_options) {
        params.push('sort_options=' + encodeURIComponent(options.sort_options));
      }

      if (params.length) {
        return '?' + params.join('&');
      }
    }
<commit_msg>Resolves issue of malformed requests when options are absent<commit_after>(function() {
  'use strict';

  angular.module('app.resources')
    .factory('CollectionsApi', CollectionsApiFactory);

  /** @ngInject */
  function CollectionsApiFactory($http, API_BASE) {
    var service = {
      query: query,
      get: get,
      post: post,
      delete: remove,
    };

    return service;

    function query(collection, options) {
      var url = API_BASE + '/api/' + collection;

      // $log.debug("query = " + url + buildQuery(options));

      return $http.get(url + buildQuery(options), buildConfig(options))
        .then(handleSuccess);

      function handleSuccess(response) {
        return response.data;
      }
    }

    function get(collection, id, options) {
      var url = API_BASE + '/api/' + collection + '/' + id;

      // $log.debug("get = " + url + buildQuery(options));

      return $http.get(url + buildQuery(options), buildConfig(options))
        .then(handleSuccess);

      function handleSuccess(response) {
        return response.data;
      }
    }

    function post(collection, id, options, data) {
      var url = API_BASE + '/api/' + collection + '/' + (id || "") + buildQuery(options);

      // $log.debug("post = " + url + buildQuery(options));

      return $http.post(url, data, buildConfig(options))
        .then(handleSuccess);

      function handleSuccess(response) {
        return response.data;
      }
    }

    // delete is a reserved word in JS
    function remove(collection, id, options) {
      var url = API_BASE + '/api/' + collection + '/' + (id || "") + buildQuery(options);

      // $log.debug("post = " + url + buildQuery(options));

      return $http.delete(url, buildConfig(options))
        .then(handleSuccess);

      function handleSuccess(response) {
        return response.data;
      }
    }

    // Private

    function buildQuery(options) {
      var params = [];
      options = options || {};

      if (options.expand) {
        if (angular.isArray(options.expand)) {
          options.expand = options.expand.join(',');
        }
        params.push('expand=' + encodeURIComponent(options.expand));
      }

      if (options.attributes) {
        if (angular.isArray(options.attributes)) {
          options.attributes = options.attributes.join(',');
        }
        params.push('attributes=' + encodeURIComponent(options.attributes));
      }

      if (options.decorators) {
        if (angular.isArray(options.decorators)) {
          options.decorators = options.decorators.join(',');
        }
        params.push('decorators=' + encodeURIComponent(options.decorators));
      }

      if (options.filter) {
        angular.forEach(options.filter, function(filter) {
          params.push('filter[]=' + encodeURIComponent(filter));
        });
      }

      if (options.limit) {
        params.push('limit=' + encodeURIComponent(options.limit));
      }

      if (options.offset) {
        params.push('offset=' + encodeURIComponent(options.offset));
      }

      if (options.hide) {
        params.push('hide=' + encodeURIComponent(options.hide));
      }

      if (options.sort_by) {
        params.push('sort_by=' + encodeURIComponent(options.sort_by));
      }

      if (options.sort_order) {
        params.push('sort_order=' + encodeURIComponent(options.sort_order));
      }

      if (options.sort_options) {
        params.push('sort_options=' + encodeURIComponent(options.sort_options));
      }

      return params.length ? '?' + params.join('&') : '';
    }

{'fraction_non_alphanumeric': 0.14789821453676366, 'fraction_numerical': 0.0, 'mean_word_length': 2.428433734939759, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3512977', 'n_tokens_mistral': 2049, 'n_tokens_neox': 2032, 'n_words': 371}