Created
February 7, 2019 12:13
-
-
Save OlabodeAbesin/71abfda2071032f29ef3544540f4ec0b to your computer and use it in GitHub Desktop.
Require guzzle to make the call to github endpoint.
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 characters
<?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; | |
} | |
} |
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 characters
<?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