<?php

Class VServices {
	
	private $_apiUrl;
	private $_curlObj;
	private $_userId;
	private $_password;
	
	public function __construct() {
		
	}
	
	public function setApiUrl($url) {
		$this->_apiUrl = $url;
	}
	
	public function setConnection($curl) {
		$this->_curlObj = $curl;
	}
	
	public function setUserId ($userId) {
		$this->_userId = $userId;
	}
	
	public function setPassword ($password) {
		$this->_password = $password;
	}
	
	public function getPrivateTree () {
		$this->_curlObj->create($this->_apiUrl. 'space/dir/isgetall/1');
		$this->_curlObj->option(CURLOPT_BUFFERSIZE, 10);
		$this->_curlObj->options(array(CURLOPT_BUFFERSIZE => 10));
		
		$post = array('userid' => $this->_userId);
		$this->_curlObj->post($post);
		return $this->_curlObj->execute();
	}
	
	/**
	 * $aryParams
	 * 
	 * @param unknown $action
	 * @param unknown $aryParams
	 */
	public function actionExecute ($action, $aryParams = array()) {
		$this->_curlObj->create($this->_apiUrl. 'space/'.$action);
		$this->_curlObj->option(CURLOPT_BUFFERSIZE, 10);
		$this->_curlObj->options(array(CURLOPT_BUFFERSIZE => 10));
		
		$aryParams['userid'] = $this->_userId;
		$this->_curlObj->post($aryParams);
		return $this->_curlObj->execute();
	}
	
	public function createDir ($dirName, $parentId) {
		$this->_curlObj->create($this->_apiUrl. 'space/mkdir');
		$this->_curlObj->option(CURLOPT_BUFFERSIZE, 10);
		$this->_curlObj->options(array(CURLOPT_BUFFERSIZE => 10));
		
		$post = array('userid' => $this->_userId, 'parent_id' => $parentId, 'name' => $dirName);
		$this->_curlObj->post($post);
		return $this->_curlObj->execute();
	}
	
	public function deleteDir ($dirId) {
		$this->_curlObj->create($this->_apiUrl. 'space/delete');
		$this->_curlObj->option(CURLOPT_BUFFERSIZE, 10);
		$this->_curlObj->options(array(CURLOPT_BUFFERSIZE => 10));
		
		$post = array('userid' => $this->_userId, 'type' => 'folder', 'id' => $dirId);
		$this->_curlObj->post($post);
		return $this->_curlObj->execute();
	}
		
	public function __destruct() {
		
	}
}