Last active
July 23, 2019 23:04
-
-
Save ahmic/833bf4ad69a07c1474e422e2db3cadb8 to your computer and use it in GitHub Desktop.
Revisions
-
ahmic revised this gist
Feb 6, 2019 . No changes.There are no files selected for viewing
-
ahmic revised this gist
Feb 6, 2019 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ <?php public function calculateScore($username) { // Fetch user info from Github API $url = 'https://api.github.com/users/'.$username.'/events/public'; $ch = curl_init(); @@ -33,4 +33,4 @@ public function calculateScore($username) $totalScore = $otherEventsCount + $selectedScore; return $totalScore; } -
ahmic created this gist
Feb 6, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ <?php public function calculateScore($username) { // Fetch user info from Github API $url = 'https://api.github.com/users/'.$username.'/events/public'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $data = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); // Simple validation if($httpcode != 200) { throw new \Exception('User not found'); } // Create Laravel collection from API response $userData = collect(json_decode($data)); // Filter collection to easily get all items by object key and value $pushEventCount = $userData->where('type', 'PushEvent')->count(); $pullRequestEventCount = $userData->where('type', 'PullRequestEvent')->count(); $issueCommentEventCount = $userData->where('type', 'IssueCommentEvent')->count(); // Calculations $otherEventsCount = $userData->count() - $pushEventCount - $pullRequestEventCount - $issueCommentEventCount; $selectedScore = $pushEventCount * 10 + $pullRequestEventCount * 5 + $issueCommentEventCount * 4; $totalScore = $otherEventsCount + $selectedScore; return $totalScore; }