Last active
February 6, 2019 15:52
-
-
Save aliuwahab/c82b948f4db4f932b0b5736a56157148 to your computer and use it in GitHub Desktop.
A function that accepts a GitHub username, and returns that users "Score" based on the below rules. PushEvent = 10 points. PullRequestEvent = 5 points. IssueCommentEvent = 4 points. Any other event = 1 point
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
/** | |
*@Param String username | |
*/ | |
public function getUserGithubScores($username) | |
{ | |
//initialise guzzle http client; | |
$client = new Client(); | |
try { | |
//make a get request to github | |
$res = $client->get('https://api.github.com/users/'.$username.'/events/public'); | |
//create a Laravel collection from the response return from github and apply map and sum. | |
return collect(json_decode($res->getBody()))->map(function ($item) { | |
switch ($item->type) { | |
case 'PushEvent': | |
return 10; | |
break; | |
case 'PullRequestEvent': | |
return 5; | |
break; | |
case 'IssueCommentEvent': | |
return 4; | |
default: | |
return 1; | |
break; | |
} | |
})->sum(); | |
} catch (\Exception $e) { | |
return $e->getMessage(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment