Skip to content

Commit

Permalink
Merge branch 'proxy-option'
Browse files Browse the repository at this point in the history
  • Loading branch information
drizzef committed Sep 25, 2017
2 parents 42a403c + 69bba03 commit 9105f28
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
14 changes: 13 additions & 1 deletion examples.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

// var googleTrends = require('./lib/google-trends-api.min.js');
// var googleTrends = require('./lib/google-trends-api.js');

/* ******************* Autocomplete **************************/

Expand All @@ -14,6 +14,18 @@
// console.log('request body', err.requestBody);
// });

/* ******************* Autocomplete + PROXY **************************/

// googleTrends.autoComplete({keyword: 'Back to school', proxy: 'http://178.60.28.98:9999'})
// .then((res) => {
// console.log('this is res', res);
// })
// .catch((err) => {
// console.log('got the error', err);
// console.log('error message', err.message);
// console.log('request body', err.requestBody);
// });

/* ******************* Interest over time **************************/

// googleTrends.interestOverTime({keyword: 'Valentines Day'})
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"url": "https://github.com/pat310/google-trends-api/issues"
},
"homepage": "https://github.com/pat310/google-trends-api#readme",
"dependencies": {},
"dependencies": {
"https-proxy-agent": "^2.1.0"
},
"devDependencies": {
"babel": "6.3.13",
"babel-core": "6.1.18",
Expand Down
9 changes: 8 additions & 1 deletion src/request.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
'use strict';
import https from 'https';
import querystring from 'querystring';
import HttpsProxyAgent from 'https-proxy-agent';

export default function request({method, host, proxy, path, qs}) {
const agent = proxy ? new HttpsProxyAgent(proxy) : undefined;

export default function request({method, host, path, qs}) {
const options = {
host,
method,
path: `${path}?${querystring.stringify(qs)}`,
agent,
timeout: 10000,
followRedirect: true,
maxRedirects: 10
};

return new Promise((resolve, reject) => {
Expand Down
2 changes: 2 additions & 0 deletions src/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export function getResults(request) {
}),
tz: 300,
},
proxy: obj.proxy,
};

const { path, resolution, _id } = map[searchType];
Expand Down Expand Up @@ -210,6 +211,7 @@ export function getResults(request) {
token,
tz: 300,
},
proxy: obj.proxy,
};

return request(nextOptions);
Expand Down

0 comments on commit 9105f28

Please sign in to comment.