Created
November 9, 2015 19:01
-
-
Save alperg/f479d06d34fbdaaa1494 to your computer and use it in GitHub Desktop.
Github Repo Search API
This file contains 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
<h2>Github Search API: Quantify Frameworks</h2><input type="text" placeholder="Username" id="username"> | |
<h4><button onclick="get()">GET</button></h4> | |
<p>Response:</p> | |
<pre id="a"></pre> |
This file contains 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
function get(){ | |
$.getJSON('https://api.github.com/users/' + $('#username').val() + '/repos?sort=updated', function(data) { | |
getFrameworks( $('#username').val(), data); | |
}).error(function(err){ | |
$('#a').html(err.responseText); | |
}); | |
} | |
function getFrameworks(username, repos_array) { | |
var frameworks = ['Node', 'Express', 'Angular']; | |
var count = 0; | |
for (var i = 0; i < repos_array.length; i++){ | |
repos_array[i].frameworks = []; | |
} | |
for (var i = 0; i < frameworks.length; i++) (function(i){ | |
switch (frameworks[i]){ | |
case 'Node': | |
$.getJSON('https://api.github.com/search/code?q=filename:package.json+user:' + username, function(response){ | |
updateRepo(response.items, repos_array, frameworks[i]); | |
}).then(function(){ | |
count++; | |
checkFinished(count, frameworks.length); | |
}); | |
break; | |
case 'Express': | |
$.getJSON('https://api.github.com/search/code?q=require+express+user:' + username, function(response){ | |
updateRepo(response.items, repos_array, frameworks[i]); | |
}).then(function(){ | |
count++; | |
checkFinished(count, frameworks.length); | |
}); | |
break; | |
case 'Angular': | |
$.getJSON('https://api.github.com/search/code?q=ng-app+user:' + username, function(response){ | |
console.log(response.items, frameworks[i]); | |
updateRepo(response.items, repos_array, frameworks[i]); | |
}).then(function(){ | |
count++; | |
checkFinished(count, frameworks.length); | |
}); | |
break; | |
default: | |
break; | |
} | |
})(i); | |
function updateRepo(response, repos_array, framework){ | |
for (var j = 0; j < response.length; j++) { | |
for (var k = j+1; k < response.length; k++) { | |
if(response[j].repository.id == response[k].repository.id) { response.splice(--k, 1); } | |
} | |
} | |
for (var j = 0; j < response.length; j++){ | |
for (var k = 0; k < repos_array.length; k++){ | |
if (response[j].repository.id == repos_array[k].id) { | |
repos_array[k].frameworks.push(framework); | |
break; | |
} | |
} | |
} | |
} | |
function checkFinished(count, length){ | |
if (count == length){ | |
var str = ""; | |
for (var i = 0; i < repos_array.length; i++) { | |
str += repos_array[i].name + " : " + repos_array[i].frameworks + '\n'; | |
} | |
$('#a').html(str); | |
} | |
} | |
} |
This file contains 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
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
This file contains 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
*{ | |
font-family: helvetica; | |
box-sizing: border-box; | |
} | |
button{ | |
background-color: #3081B7; | |
color: white; | |
border: none; | |
border-radius: 5px; | |
font-size: 12pt; | |
padding: 10px; | |
} | |
button:hover{ | |
cursor: pointer; | |
background-color: RGBA(48, 129, 183, 0.8) | |
} | |
pre{ | |
font-family: 'courier new'; | |
overflow: scroll; | |
background-color: whitesmoke; | |
box-sizing: border-box; | |
min-height: 50px; | |
border: 1px solid #e0e0e0; | |
border-radius: 5px; | |
transition: all 0.6s; | |
} | |
input{ | |
font-size: 16pt; | |
border: 1px solid gray; | |
border-radius: 3px; | |
padding: 4px; | |
margin: 5px 2px; | |
} | |
hr{ | |
border: none; | |
height: 1px; | |
margin: 30px 5px;/* Set the hr color */ | |
background-color: #e0e0e0; /* Modern Browsers */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment