-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from pat310/addTrendData
Add trend data
- Loading branch information
Showing
11 changed files
with
173 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
var rp = require('request-promise'); | ||
var createObj = require(__dirname + '/../resources/callbacks.js'); | ||
var checkErrors = require(__dirname + '/../resources/errorHandling.js'); | ||
var parseJSON = require(__dirname + '/../resources/htmlParser.js').parseJSON; | ||
|
||
module.exports = function request(keywords, cbFunc){ | ||
var obj = createObj(arguments, request); | ||
|
||
var error = checkErrors(obj); | ||
if(error instanceof Error) return Promise.reject(obj.cbFunc(error)); | ||
|
||
return Promise.all(promiseArr(obj.keywords)) | ||
.then(function(results){ | ||
return obj.cbFunc(null, results); | ||
}) | ||
.catch(function(err){ | ||
return Promise.reject(obj.cbFunc(err)); | ||
}); | ||
}; | ||
|
||
function promiseArr(keywords){ | ||
return keywords.map(function(keyword){ | ||
return rp(`http://www.google.com/trends/fetchComponent?q="${keyword}"&cid=TIMESERIES_GRAPH_0&export=3`) | ||
.then(function(htmlString){ | ||
return parseJSON(htmlString); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
var chai = require('chai'); | ||
var chaiAsPromised = require('chai-as-promised'); | ||
chai.use(chaiAsPromised); | ||
var expect = chai.expect; | ||
var assert = chai.assert; | ||
|
||
var htmlParser = require(__dirname + '/../../lib/resources/htmlParser.js'); | ||
|
||
module.exports = | ||
describe('htmlParser.test.js', function(){ | ||
|
||
describe('htmlParser.parseHtml', function(){ | ||
it('has method', function(){ | ||
assert.isFunction(htmlParser.parseHtml); | ||
}); | ||
}); | ||
|
||
describe('htmlParse.parseJSON', function(){ | ||
it('has method', function(){ | ||
assert.isFunction(htmlParser.parseJSON); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
dateValidate: require(__dirname + '/dateValidate.test.js'), | ||
countryCodes: require(__dirname + '/countryCodes.test.js'), | ||
callbacks: require(__dirname + '/callbacks.test.js'), | ||
errorHandling: require(__dirname + '/errorHandling.test.js') | ||
countryCodes: require(__dirname + '/countryCodes.test.js'), | ||
dateValidate: require(__dirname + '/dateValidate.test.js'), | ||
errorHandling: require(__dirname + '/errorHandling.test.js'), | ||
htmlParser: require(__dirname + '/htmlParser.test.js') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
var chai = require('chai'); | ||
var chaiAsPromised = require('chai-as-promised'); | ||
chai.use(chaiAsPromised); | ||
var should = chai.should(); | ||
|
||
var trendData = require(__dirname + '/../../lib/utils/trendData.js'); | ||
|
||
module.exports = | ||
describe('trendData.js', function(){ | ||
it('should reject if no keyword is provided', function(){ | ||
return trendData().should.be.rejectedWith('Keywords must be provided'); | ||
}); | ||
}); |