define([
  'lodash',
  'backbone',
  'moment'
],
function (_, Backbone, moment) {
  var Response = function () {
    this.initialize.apply(this, arguments);
  };
  
  _.extend(Response.prototype, {
    
    initialize: function () {},
    
    dataType: 'json',
    
    urlParams: ['query'],
    
    dateParams: ['start_at', 'end_at'],
    dateFormat: 'YYYY-MM-DDTHH:mm:ssTZ',
    
    getData: function () {
      throw('Not implemented.');
    },
    
    getDefinition: function () {
      return {
        dataType: this.dataType,
        url: this.url,
        urlParams: this.urlParams,
        response: this.getResponse()
      };
    },
    
    getResponse: function () {
      
      // use closure as the response function needs to be executed with
      // mockjax as context and cannot be bound to the response object
      var that = this;
      
      return function(settings) {
        // extract query parameters, convert to moment dates
        var query = {};
        settings.urlParams.query.replace(
            /([^?=&]+)(?:=([^&]*))?/g,
            function (all, key, value) {
              value = decodeURIComponent(value);
              if (_.contains(that.dateParams, key)) {
                value = moment(value, that.dateFormat);
              }
              query[key] = value;
            }
        );

        // generate response
        this.responseText = {
          data: that.getData(query)
        };
      }
    }
  });
  
  Response.extend = Backbone.Model.extend;
  
  return Response;
});

@@ -642,24 +642,1052 @@
     %7D,%0A    %0A
+    getQueryForResponse: function (query) %7B%0A      var responseQuery = %7B%7D;%0A      _.each(query, function (value, key) %7B%0A        if (key == 'filter_by') %7B%0A          if (responseQuery.filter_by == null) %7B%0A            // first filter param, assign as single value%0A            responseQuery.filter_by = value;%0A          %7D else if (_.isArray(responseQuery.filter_by)) %7B%0A            // filter already is an array, add another filter%0A            responseQuery.filter_by.push(value);%0A          %7D else %7B%0A            // second filter param, convert to array%0A            responseQuery.filter_by = %5BresponseQuery.filter_by, value%5D;%0A          %7D%0A        %7D else if (moment.isMoment(value) && value.originalValue) %7B%0A          // for date params, use original query string, not moment object%0A          responseQuery%5Bkey%5D = value.originalValue;%0A        %7D else if (key == 'collect') %7B%0A          responseQuery%5Bkey%5D = value.split(',');%0A        %7D else %7B%0A          responseQuery%5Bkey%5D = value;%0A        %7D%0A      %7D);%0A      return responseQuery;%0A    %7D,%0A    %0A
     getRespo
@@ -1701,24 +1701,24 @@
 nction () %7B%0A
-
       %0A     
@@ -2225,24 +2225,67 @@
 ms, key)) %7B%0A
+                var originalValue = value;%0A
             
@@ -2328,16 +2328,69 @@
 ormat);%0A
+                value.originalValue = originalValue;%0A
         
@@ -2486,16 +2486,16 @@
 esponse%0A
-
         
@@ -2516,16 +2516,66 @@
 ext = %7B%0A
+          query: that.getQueryForResponse(query),%0A
         

add query to fakeapi responses