Skip to content

Instantly share code, notes, and snippets.

@OlabodeAbesin
Created February 7, 2019 12:13
Show Gist options
  • Save OlabodeAbesin/71abfda2071032f29ef3544540f4ec0b to your computer and use it in GitHub Desktop.
Save OlabodeAbesin/71abfda2071032f29ef3544540f4ec0b to your computer and use it in GitHub Desktop.
Require guzzle to make the call to github endpoint.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
class CollectorController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index($username)
{
$client = new Client(); //GuzzleHttp\Client
$result = $client->get('https://api.github.com/users/'.$username.'/events/public');
$collection = collect(json_decode($result->getBody()),true)->pluck('type');
$total = 0;
foreach($collection as $item){
if($item == 'PushEvent'){
$total += 10;}
elseif ($item == 'PullRequestEvent') {
$total += 5;}
elseif ($item == 'IssueCommentEvent') {
$total += 4;}
else {
$total += 1;}
}
return $total;
}
}
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::get('collect/{username}', 'CollectorController@index');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment