var request = require('superagent'),
  _ = require('lodash');

module.exports = Gnipper;

function Gnipper (options) {
  if (!options) throw new Error('No options supplied to Gnipper constructor');
  if (!options.account || !options.username || !options.password) {
    throw new Error('Missing required option. Required: account, username, password');
  }

  this.account = options.account;
  this.username = options.username;
  this.password = options.password;
  this.API = 'https://search.gnip.com/accounts/' + options.account;
}

Gnipper.prototype.searchUrl = function (options) {
  var label = options.label || 'prod';
  var url = this.API + '/search/' + label + '.json?';
  delete options.label;

  _.each(options, function (value, key) {
    url = url + key + '=' + encodeURIComponent(value) + '&';
  });

  // Drop the final & and return the URL
  return url.slice(0, -1);
};

Gnipper.prototype.search = function (options, callback) {
  if (!options.publisher) return callback(new Error('publisher is a required param for Gnipper.search()'));

  request.get(this.searchUrl(options))
    .auth(this.username, this.password)
    .end(function (response) {
      if (response.error) {
        // Include the error details returned by the Gnip API
        var err = _.merge(response.error, response.body.error);
        return callback(err);
      }
      callback(null, response);
  });
};

@@ -1052,43 +1052,92 @@
 %0A%0A  
-request.get(this.searchUrl(options)
+var that = this;%0A  var searchUrl = this.searchUrl(options);%0A%0A  request.get(searchUrl
 )%0A  
@@ -1295,16 +1295,16 @@
 nip API%0A
-
         
@@ -1355,24 +1355,259 @@
 ody.error);%0A
+        // Include Gnipper details with the error as well%0A        err.gnipper = %7B%0A          searchUrl: searchUrl,%0A          username: that.username,%0A          passwordIsDefined: (_.isUndefined(that.password)) ? false : true%0A        %7D;%0A
         retu

Include Gnipper details when returning an error