Advertisement
Guest User

Untitled

a guest
May 15th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const axios = require('axios');
  2. const config = require('../config.json');
  3.  
  4. const TIMEOUT = 1000 * 60 * 60 * 24; // 24 hours
  5. const BASE_URL = 'https://api.lever.co/v1';
  6.  
  7. async function getCandidates(options) {
  8.   const url = `${BASE_URL}/candidates`;
  9.   const elements = [];
  10.  
  11.   const updatedAtStart = new Date();
  12.   updatedAtStart.setTime(updatedAtStart.getTime() - TIMEOUT); // 24 h ago
  13.  
  14.   let next;
  15.  
  16.   while (true) {
  17.     const response = await axios.get(url, {
  18.       auth: { username: config.lever.apiToken, password: '' },
  19.       params: {
  20.         updatedAtStart: updatedAtStart.getTime(),
  21.         archived: false
  22.         offset: next,
  23.         limit: 100
  24.       }
  25.     });
  26.    
  27.     next = response.next;
  28.     elements.push(...response.data);
  29.  
  30.     if (!response.hasNext) break;
  31.   }
  32.  
  33.   return elements;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement