Commit ca2949f9 by Vitalik Ovcharenko

Add proxy-agent

parent 3d49ea39
...@@ -24,8 +24,9 @@ ...@@ -24,8 +24,9 @@
"dependencies": { "dependencies": {
"bluebird": "2", "bluebird": "2",
"create-error": "0.3", "create-error": "0.3",
"lodash": "2",
"needle": "1.6.0", "needle": "1.6.0",
"lodash": "2" "proxy-agent": "2.0.0"
}, },
"devDependencies": { "devDependencies": {
"chai": "1", "chai": "1",
......
...@@ -7,6 +7,7 @@ var Promise = require('bluebird'); ...@@ -7,6 +7,7 @@ var Promise = require('bluebird');
var createError = require('create-error'); var createError = require('create-error');
var http = require('http'); var http = require('http');
var needle = Promise.promisifyAll(require('needle')); var needle = Promise.promisifyAll(require('needle'));
var ProxyAgent = require('proxy-agent');
var pkg = require('../package.json'); var pkg = require('../package.json');
function ClearbitClient (config) { function ClearbitClient (config) {
...@@ -18,6 +19,11 @@ function ClearbitClient (config) { ...@@ -18,6 +19,11 @@ function ClearbitClient (config) {
this.proxy = config.proxy || null; this.proxy = config.proxy || null;
this.agent = null;
if (this.proxy) {
this.agent = new ProxyAgent(this.proxy);
}
this.Company = require('./enrichment/company').Company(this); this.Company = require('./enrichment/company').Company(this);
this.Person = require('./enrichment/person').Person(this); this.Person = require('./enrichment/person').Person(this);
this.Enrichment = require('./enrichment').Enrichment(this); this.Enrichment = require('./enrichment').Enrichment(this);
...@@ -63,19 +69,24 @@ ClearbitClient.prototype.request = function (options) { ...@@ -63,19 +69,24 @@ ClearbitClient.prototype.request = function (options) {
var timeout = options.timeout || options.stream && 60000 || 10000; var timeout = options.timeout || options.stream && 60000 || 10000;
var needleOptions = {
json: options.json,
headers: options.headers,
timeout: timeout,
username: this.key,
password: '',
user_agent: 'ClearbitNode/v' + pkg.version,
};
if (this.agent) {
needleOptions.agent = this.agent;
}
return needle.requestAsync( return needle.requestAsync(
options.method, options.method,
this.url(options), this.url(options),
options.body || options.query, options.body || options.query,
{ needleOptions
json: options.json,
headers: options.headers,
timeout: timeout,
username: this.key,
password: '',
user_agent: 'ClearbitNode/v' + pkg.version,
proxy: this.proxy
}
) )
.bind(this) .bind(this)
.spread(function (response, body) { .spread(function (response, body) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment