<?php

namespace App\Http\Controllers;

use Exception;
use Illuminate\Http\Request;
use GuzzleHttp\Client;

class GetDataApiController extends Controller
{
    const URL   = 'https://siakadu.unesa.ac.id/api/apiunggun';
    const URLS  = 'https://siakadu.unesa.ac.id/api/dashboard';

    //
    public static function getDosen()
    {
        $client = new Client();

        $apiRequest = $client->request('POST', GetDataApiController::URLS, [
            'form_params' =>
            [
                'kondisi' => 'dosen_aktif',
            ]
        ]);

        return json_decode($apiRequest->getBody()->getContents(), true);
    }

    public static function getAccount($nim)
    {
        $client = new Client();

        $apiRequest = $client->request('POST', GetDataApiController::URL, [
            'form_params' =>
            [
                'username'  => $nim,
                'kondisi'   => 'cekhakakses'
            ]
        ]);

        $gcon = utf8_encode($apiRequest->getBody()->getContents());
        $data = unserialize($gcon);

        return $data;
    }

}
