<?php
/**
 * This file contains the QGoogleDrive class.
 *
 * @author David Maliska
 */

/**
 * Require DocBlock
 */
require_once('google-api-php-client/src/Google_Client.php');
require_once('google-api-php-client/src/contrib/Google_DriveService.php');

/**
 * This class will create objects to comunicate with Google Drive
 *
 * @property Google_Client $client contains Google Client
 * @property Google_DriveService $service contains Google Drive Service API to interact with Drive
 * @property string $error contains error message
 * @property string $errorGoogle contains error message from Google_Exception
 */
class QGoogleDrive {
    ///////////////////////////
    // Private Member Variables
    ///////////////////////////
    
    /** @var Google_Client Google Client API*/
    protected $client;
    
    /** @var Google_DriveService Google Drive Service API to interact with Drive*/
    protected $service;
    
    /** @var string Error message*/
    protected $error;
    
    /** @var string Google error message*/
    protected $errorGoogle;
    
    //////////
    // Methods
    //////////
    /**
     * Create the QGoogleDrive object.
     *
     * @return void
     */
    public function __construct() {
        try {
            $this->client = new Google_Client();
            $this->client->setUseObjects(true);
            $this->client->setAccessToken($_SESSION['accessToken']);
            $this->service = new Google_DriveService($this->client);
        } catch (Google_Exception $eG) {
            $this->errorGoogle = $eG->getMessage();
        } catch (Exception $e) {
            $this->error = $e->getMessage();
        }
    }
    
    
    /////////////////////////
    // Public Properties: GET
    /////////////////////////
    /**
    * PHP Magic __get method implementation.
    * @param string $strName Name of the property to be fetched.
    *
    * @return Google_Client|Google_DriveService|string|null
    */
    public function __get($strName) {
        switch ($strName) {
            case 'Client': return $this->client;
            case 'Service': return $this->service;
            case 'Error': return $this->error;
            case 'ErrorGoogle': return $this->errorGoogle;
                
            default:
                return null;
        }
    }
}
?>

