Created
May 24, 2016 22:04
-
-
Save joetemp/db1fd17ef36deaa256fb7b2f7366dcce to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module.exports = function (API_KEY, deals) { | |
const request = require('request-promise'); | |
var junk = 'nothing'; | |
var dealsObj = {}; | |
function getIt (url) { | |
return request(url).then(function (body) { | |
return JSON.parse(body).data; | |
}); | |
} | |
deals.forEach(function(deal) { | |
dealsObj[deal.id] = deal; | |
}); | |
var dealsArr = Object.keys(dealsObj).map(function(deal){ | |
return Number(deal); | |
}); | |
return Promise.all([junk, junk]).then(function(){ | |
var promises = dealsArr.map(function(deal){ | |
var url = 'https://api.pipedrive.com/v1/deals/' + deal + '/participants?start=0&api_token=' + API_KEY; | |
return Promise.all([getIt(url), junk]).then(function(results) { | |
var people = results[0]; | |
console.log('Participants of deal ' + deal); | |
people.forEach(function(person){ | |
console.log(person.person_id.value); | |
}); | |
}); | |
}); | |
return Promise.all(promises); | |
}).then(function(){ | |
console.log('Why am I not logged last?'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment