-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodeexercise_v1.js
More file actions
28 lines (25 loc) · 937 Bytes
/
nodeexercise_v1.js
File metadata and controls
28 lines (25 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const http = require('q-io/http')
const GitHubDir = 'https://api.github.com/users/jcondina'
const userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36'
function connect () {
try {
var req = http.read({
url: GitHubDir,
method: 'GET',
headers: {
'User-Agent': userAgent
}
}).then(function (json) {
var receivedData = (JSON.parse(json))
if (receivedData.public_repos == 0)
console.log("No repositories")
if (receivedData.public_repos == 3)
console.log("There are three repositories")
if (receivedData.public_repos == 0)
console.log("No repositories")
})
} catch (e) {
console.log("I cannot connect to the server")
}
}
connect()