Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into setup-tests
  • Loading branch information
MaryCBaylis committed Apr 18, 2015
2 parents 98b4120 + f0d2269 commit 81f45e1
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 84 deletions.
127 changes: 127 additions & 0 deletions app/assets/javascripts/githubAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
$(document).ready(function() {

$('#ghsubmitbtn').on('click', function(e){
e.preventDefault();
var username = $('#ghusername').val();
getGitHubData(username);
debugger;
});



});

var getGitHubData = function(username){
var githubResults = {test: "test"}
var user_uri = 'https://api.github.com/users/'+username;
var events_uri = 'https://api.github.com/users/'+username+'/events';

var test;
requestJSON(user_uri, function(json){
if(json.message == "Not Found" || username == '') {
$('#ghapidata').html("<h2>No User Info Found</h2>");
}

else {
// else we have a user and we display their info
githubResults.username = json.login;
githubResults.fullName = json.name || githubResults.username;
githubResults.aviurl = json.avatar_url;
githubResults.profileurl = json.html_url;
githubResults.location = json.location;
githubResults.followersnum = json.followers;
githubResults.followingnum = json.following;
githubResults.reposnum = json.public_repos;

var events;
var pushEvents = 0;
var pullEvents = 0;
var gistEvents = 0;
var forkEvents = 0;
var mostRecentEventDate;
var oldestEventDate;
var eventDates = [];
var languages = {};
var commits = 0;
var additions = 0;
var deletions = 0;
var commitMessages = [];

$.getJSON(events_uri, function(json){
console.log("Checking inside JSON")
console.log(githubResults);
events = json;
for (var i = 0; i < events.length; i++) {
if (events[i].type === "PushEvent") {
var commitsCollection = events[i].payload.commits
for (var j = 0; j < commitsCollection.length; j++){
commitMessages.push({message: commitsCollection[j].message, url: events[i].repo.url});
}
pushEvents += 1;
}
else if (events[i].type === "PullRequestEvent") {
var language = events[i].payload.pull_request.head.repo.language;
if (language in languages) {
languages[language]++;
}
else {
languages[language] = 1;
}
pullEvents += 1;
commits += events[i].payload.pull_request.commits;
additions += events[i].payload.pull_request.additions;
deletions += events[i].payload.pull_request.deletions;
}
else if (events[i].type === "GistEvent") {
gistEvents++;
}
else if (events[i].type === "ForkEvent") {
forkEvents++;
}
eventDates.push({date: events[i].created_at, eventType: events[i].type});
}
mostRecentEventDate = events[0].created_at;
oldestEventDate = events[events.length-1].created_at;

githubResults.pushEvents = pushEvents;
githubResults.pullEvents = pullEvents;
githubResults.gistEvents = gistEvents;
githubResults.forkEvents = forkEvents;
githubResults.mostRecentEventDate = mostRecentEventDate;
githubResults.oldestEventDate = oldestEventDate;
githubResults.commits = commits;
githubResults.lineAdditions = additions;
githubResults.lineDeletions = deletions;
githubResults.commitMessages = commitMessages;
githubResults.languages = languages;
console.log(githubResults);
saveGithubResults(githubResults);
})
} // end else statement
}); // end requestJSON Ajax call
}; // end click event handler

function requestJSON(url, callback) {
var otherTest = $.getJSON(url, {
format: "json",
}).error(function(error) {
$('#ghapidata').html("<h2>"+ error +"</h2>");
}).done(function(data) {
callback.call(null, data);
// return data;
});
debugger;
return otherTest;
}

function saveGithubResults(githubResults) {
console.log("inside save");
console.log(githubResults);
$.ajax({
url: '/store_github',
type: 'POST',
data: githubResults
}).done(function(data){
//DO SOMETHING!
})
}
69 changes: 0 additions & 69 deletions app/assets/javascripts/init.js
Original file line number Diff line number Diff line change
@@ -1,69 +0,0 @@
$(document).ready(function() {
$(function(){
$('#ghsubmitbtn').on('click', function(e){
e.preventDefault();
$('#ghapidata').html('Loading...');

var username = $('#ghusername').val();
var user_uri = 'https://api.github.com/users/'+username;
var repo_uri = 'https://api.github.com/users/'+username+'/repos';

requestJSON(user_uri, function(json) {
console.log("My json")
console.log(json)
if(json.message == "Not Found" || username == '') {
$('#ghapidata').html("<h2>No User Info Found</h2>");
}

else {
// else we have a user and we display their info
var fullname = json.name;
var username = json.login;
var aviurl = json.avatar_url;
var profileurl = json.html_url;
var location = json.location;
var followersnum = json.followers;
var followingnum = json.following;
var reposnum = json.public_repos;

if(fullname == undefined) { fullname = username; }

var outhtml = '<h2>'+fullname+' <span class="smallname">(@<a href="'+profileurl+'" target="_blank">'+username+'</a>)</span></h2>';
outhtml = outhtml + '<div class="ghcontent"><div class="avi"><a href="'+profileurl+'" target="_blank"><img src="'+aviurl+'" width="80" height="80" alt="'+username+'"></a></div>';
outhtml = outhtml + '<p>Followers: '+followersnum+' - Following: '+followingnum+'<br>Repos: '+reposnum+'</p></div>';
outhtml = outhtml + '<div class="repolist clearfix">';

var repositories;
$.getJSON(repo_uri, function(json){
repositories = json;
outputPageContent();
});

function outputPageContent() {
if(repositories.length == 0) { outhtml = outhtml + '<p>No repos!</p></div>'; }
else {
outhtml = outhtml + '<p><strong>Repos List:</strong></p> <ul>';
$.each(repositories, function(index) {
outhtml = outhtml + '<li><a href="'+repositories[index].html_url+'" target="_blank">'+repositories[index].name + '</a></li>';
});
outhtml = outhtml + '</ul></div>';
}
$('#ghapidata').html(outhtml);
} // end outputPageContent()
} // end else statement
}); // end requestJSON Ajax call
}); // end click event handler

function requestJSON(url, callback) {
$.getJSON(url, {
format: "json",
}).error(function(error) {
$('#ghapidata').html("<h2>"+ error +"</h2>");
}).done(function(data) {
console.log("my xhr")
console.log(data)
callback.call(null, data);
});
}
});
});
5 changes: 3 additions & 2 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ class RegistrationsController < Devise::RegistrationsController
private

def sign_up_params
params.require(:user).permit(:username, :first_name, :last_name, :email, :password, :password_confirmation, :twitter_handle, :name, :description, :interests, :skills)
<<<<<<< HEAD
params.require(:user).permit(:name, :email, :password, :password_confirmation, :twitter_handle, :name, :description, :interests, :skills)
end

def account_update_params
params.require(:user).permit(:username, :first_name, :last_name, :email, :password, :password_confirmation, :current_password, :twitter_handle)
params.require(:user).permit(:name, :email, :password, :password_confirmation, :current_password, :twitter_handle)
end
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
get '/:username', to: 'user#show'
get 'run_api', to: 'api#run'


post 'store_github', to: 'api#github'

root to: 'static#index'
end
5 changes: 0 additions & 5 deletions coverage/.last_run.json

This file was deleted.

7 changes: 0 additions & 7 deletions coverage/.resultset.json

This file was deleted.

Empty file removed coverage/.resultset.json.lock
Empty file.

0 comments on commit 81f45e1

Please sign in to comment.