Created
May 24, 2016 21:55
-
-
Save joetemp/b183f64501a4edd4427ba792aa84d959 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); | |
| }); | |
| Promise.all([junk, junk]).then(function(){ | |
| dealsArr.forEach(function(deal){ | |
| var url = 'https://api.pipedrive.com/v1/deals/' + deal + '/participants?start=0&api_token=' + API_KEY; | |
| 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); | |
| }); | |
| }); | |
| }); | |
| }).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