...
 
Commits (3)
......@@ -40,7 +40,7 @@ class APIController extends Controller
{
return response()->json([
'status' => true,
'message' => 'Authorised'
'message' => 'Authorised'
]);
}
return response()->json([
......@@ -57,8 +57,7 @@ class APIController extends Controller
public function validateTwitchAuth(Request $r)
{
$r->validate([
'apikey' => 'required',
'appkey' => 'required'
'apikey' => 'required'
]);
$user = User::where('apikey', $r->input('apikey'))->first();
......@@ -278,4 +277,24 @@ class APIController extends Controller
$contents = json_decode($body->getContents());
return $contents->data[0]->display_name;
}
public function latestStatistics(Request $r){
$user = User::where('apikey', $r->input('apikey'))->firstOrFail();
$follower = $user->userFollows()->first();
$client = new \GuzzleHttp\Client();
$res = $client->request('GET', 'https://api.twitch.tv/helix/users?id=' . $follower->from_id,
[
'headers' => [
'Client-ID' => $_ENV['TWITCH_KEY'],
]]);
$body = $res->getBody();
$contents = json_decode($body->getContents());
return response()->json([
'success' => true,
'latest_follower' => $contents->data[0]->display_name,
'latest_bits' => 'KaibaSean - 400',
'latest_donation' => 'KaibaSean - £4.00'
])
}
}
......@@ -56,6 +56,7 @@ use Carbon\Carbon;
Route::get('user/{apikey}', 'User\APIController@getUser');
Route::get('user/latestfollower/{username}', 'API\APIController@latestFollower');
Route::get('user/statistics', 'API\APIController@latestStatistics');
/**
* Process any incoming processes data we get from the app
......