-
-
Save mkhoeini/51efa949029be35868b3 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
import fetch from 'node-fetch'; | |
import btoa from 'btoa'; | |
function serverCallMaker(user, pass, baseUrl) { | |
const hash = btoa(`${user}:${pass}`); | |
const Authorization = `Basic ${hash}`; | |
const Accept = 'application/json; odata=verbose'; | |
const params = { | |
method: 'get', | |
headers: {Authorization, Accept} | |
}; | |
return (url) => fetch(baseUrl + url, params).then(r => r.json()); | |
} | |
const USERNAME = 'nikpour'; | |
const PASSWORD = '123QWE!@#'; | |
const baseUrl = 'http://78.111.2.149:8030/nikpour/_api/Web'; | |
export const getData = serverCallMaker(USERNAME, PASSWORD, baseUrl); | |
const TaskListURL = "/Lists(guid'E37AAEB7-AAAD-422A-9566-15F3DC07CC94')/items"; | |
const ProjectListURL = "/Lists(guid'DEBF6BEF-A3CF-4272-80CC-46287AE98E32')/items"; | |
export const getAllTasks = getData.bind(null, TaskListURL); | |
export const getAllProjects = getData.bind(null, ProjectListURL); |
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
import {getAllTasks, getAllProjects} from './request.js'; | |
const log = console::console.log; | |
const err = console::console.error; | |
async function test() { | |
try { | |
const tasks = await getAllTasks(); | |
log(tasks.d.results); | |
const projs = await getAllProjects(); | |
log(projs.d.results); | |
} | |
catch(e) { | |
err(e.stack); | |
} | |
} | |
test(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fun with ES2015
First do:
Then you can run it like this: