<?php

namespace Mijn;

class realmapi {
	
	public function __construct() {
		
		$this->_sMethod = 'GET';
		
	}
	
	/*
	 * Set token
	 * 
	 * @return string
	 */
	
	public function setToken($sToken) {
		
		$this->_sToken = $sToken;
		
	}
	
	/*
	 * Verify user
	 * 
	 * @return object
	 */
	
	public function verifyUser() {
		
		$oReturn = new \stdClass();
		$oReturn->result = false;
		
		if(empty($this->_sToken)) {
			return $oReturn;			
		}
		
		/*
		 * Endpoint
		 */
		
		$sEndpoint = API_ENDPOINT_OVIS . '/user/' . $this->_sToken . '/sso';
		
		/*
		 * Headers
		 */
		
		$aHeaders = [
			'Content-Type: application/json; charset=utf-8', 
			'Authentication: ' . AUTHENTICATION_KEY_OVIS
		];
										
		$oCurl = curl_init();
		curl_setopt($oCurl, CURLOPT_URL, $sEndpoint);
		curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($oCurl, CURLOPT_TIMEOUT, 10);
		curl_setopt($oCurl, CURLOPT_POST, true);
		curl_setopt($oCurl, CURLOPT_CUSTOMREQUEST, 'GET');
		curl_setopt($oCurl, CURLOPT_HTTPHEADER, $aHeaders);
		curl_setopt($oCurl, CURLOPT_HEADER, false);

		$sResult = curl_exec($oCurl);		
		
		$oResult = json_decode($sResult); 

		return !empty($oResult) ? $oResult : $oReturn;
		
	}
	
	
	
}