fixing communication with xeno-canto api

This commit is contained in:
Camilo Corea Piedra 2018-02-06 19:59:07 -06:00
parent 451528fb35
commit 15e80e2a38
1 changed files with 18 additions and 7 deletions

View File

@ -9,7 +9,7 @@
'use strict'; 'use strict';
/** @dependencies */ /** @dependencies */
var rest = require('rest'); var request = require('request');
/** @constructor */ /** @constructor */
function XenoCanto(){ function XenoCanto(){
@ -93,12 +93,23 @@ XenoCanto.prototype.search = function(query, success){
}; };
function get(that, url, success){ function get(that, url, success){
rest(url).then(function(response) {
// store response in instance var var opts = {
that.entity = JSON.parse(response.entity); url: url,
success(that); method: 'GET',
} timeout: (10*1000),
); headers:
{
'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163 Safari/537.36'
}
};
request(opts, function (err, res, url) {
// store response in instance var
that.entity = JSON.parse(res.body);
success(that);
});
} }