# Example usage: Client

You have to generate a : Client ID for web application
class TestController
{
    private function getConfig(){
        $config = [
            'APP_NAME' => 'Calendar',
            'CREDENTIALS_PATH' => "calendar-api-quickstart.json",
            'CLIENT_SECRET_PATH' => "client_secret.json",
            'REDIRECT_URL' => 'http://localhost/test/callback',
            'CLIENT_TYPE' => 'client',
            'PERMISSIONS' => 'calendar'
        ];
        return $config;
    }
    public function index()
    {
        $MGoogle = \MGoogle\MGoogle::Init( $this->getConfig() );

        if( $MGoogle->isConnected() )
        {
            echo "index: is connected";
            $connection = $MGoogle->Connect();
            // Pass $connection to API class
        }
        else
        {
            $connection = $MGoogle->Connect();
            if(!$connection){
                $MGoogle->doConnect();
            }
        }
    }

    /**
     * Request is a class from Laravel
     * You can replace the $request->get('code') with $_GET['code']
     * @param Request $request
     * @return mixed
     */
    public function callback(Request $request){
        if( $request->get('code') ){

            $MGoogle = \MGoogle\MGoogle::Init( $this->getConfig(), $request->get('code') );

            if( $MGoogle->isConnected() ){
                return redirect('/test');
            }
            else if( $connection = $MGoogle->connect())
            {
                return redirect('/test');
            }
            else
            {
                echo "not handled";
            }
        }
    }

}