From c5928fce1f39095b52adbc9514f22bf2d3ad6136 Mon Sep 17 00:00:00 2001 From: Lisa Huang Date: Mon, 6 Nov 2017 13:44:37 -1000 Subject: [PATCH] Done. --- index.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 1084ed8..521d2c8 100644 --- a/index.js +++ b/index.js @@ -1,22 +1,69 @@ function getIssues() { + const repo = 'lisaychuang/javascript-fetch-lab'; + + fetch(`${baseApi}/repos/${repo}/issues`, { + method: 'GET', + headers: { + Authorization: `token ${getToken()}` + } + }).then(resp => resp.json()). + then(json => showIssues(json)) } function showIssues(json) { + const str = json.map(x=>{ + return `
  • Title: ${x.title}
    + Issue: ${x.body} +
  • + ` + }) + $('#issues').append(`

    Issues

    `); } function createIssue() { + const issueTitle = document.getElementById('title').value; + const issueBody = document.getElementById('body').value; + + // POST /repos/:owner/:repo/issues + const repo = 'lisaychuang/javascript-fetch-lab'; + const requestBody = { + title: issueTitle, + body: issueBody + } + fetch(`${baseApi}/repos/${repo}/issues`, { + method: 'post', + body: JSON.stringify(requestBody), + headers: { + Authorization: `token ${getToken()}` + } + }).then(resp => getIssues()) } function showResults(json) { + const url = json.url + $('#results').append(`Forked repo: ${url}`); + console.log('Added json'); } +const baseApi = 'https://api.github.com'; + function forkRepo() { const repo = 'learn-co-curriculum/javascript-fetch-lab' //use fetch to fork it! + + fetch(`${baseApi}/repos/${repo}/forks`, { + method: 'post', + headers: { + Authorization: `token ${getToken()}` + } + }).then(resp => resp.json()). + then(json => showResults(json)) } function getToken() { //change to your token to run in browser, but set //back to '' before committing so all tests pass - return '' -} + // return '' + + return ''; +} \ No newline at end of file