[289] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | Class VServices {
|
---|
| 4 |
|
---|
| 5 | private $_apiUrl;
|
---|
| 6 | private $_curlObj;
|
---|
| 7 | private $_userId;
|
---|
| 8 | private $_password;
|
---|
| 9 |
|
---|
[418] | 10 | private $_httpUser;
|
---|
| 11 | private $_httpPasswd;
|
---|
| 12 |
|
---|
[289] | 13 | public function __construct() {
|
---|
| 14 | }
|
---|
| 15 | public function setApiUrl($url) {
|
---|
| 16 | $this->_apiUrl = $url;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | public function setConnection($curl) {
|
---|
| 20 | $this->_curlObj = $curl;
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | public function setUserId ($userId) {
|
---|
| 24 | $this->_userId = $userId;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | public function setPassword ($password) {
|
---|
| 28 | $this->_password = $password;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | public function getPrivateTree () {
|
---|
| 32 | $this->_curlObj->create($this->_apiUrl. 'space/dir/isgetall/1');
|
---|
| 33 | $this->_curlObj->option(CURLOPT_BUFFERSIZE, 10);
|
---|
| 34 | $this->_curlObj->options(array(CURLOPT_BUFFERSIZE => 10));
|
---|
[365] | 35 | $post = $this->_userId ? array('userid' => $this->_userId) : array();
|
---|
[289] | 36 | $this->_curlObj->post($post);
|
---|
| 37 | return $this->_curlObj->execute();
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | /**
|
---|
| 41 | * $aryParams
|
---|
| 42 | *
|
---|
| 43 | * @param unknown $action
|
---|
| 44 | * @param unknown $aryParams
|
---|
| 45 | */
|
---|
[418] | 46 |
|
---|
[417] | 47 | public function actionExecute ($action, $aryParams = array(), $module = 'space') {
|
---|
[630] | 48 | $url = $this->_apiUrl. $module .'/'.$action;
|
---|
| 49 |
|
---|
| 50 | $this->_curlObj->create($url);
|
---|
[289] | 51 | $this->_curlObj->option(CURLOPT_BUFFERSIZE, 10);
|
---|
[630] | 52 | $this->_curlObj->option(CURLOPT_HEADER, 0);
|
---|
| 53 | $this->_curlObj->option(CURLOPT_FAILONERROR, FALSE);
|
---|
[289] | 54 |
|
---|
[418] | 55 | if ($this->_httpUser && $this->_httpPasswd) {
|
---|
| 56 | $this->_curlObj->http_login($this->_httpUser, $this->_httpPasswd);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[365] | 59 | if ($this->_userId) $aryParams['userid'] = $this->_userId;
|
---|
[418] | 60 | if (count($aryParams) > 0) $this->_curlObj->post($aryParams);
|
---|
[457] | 61 |
|
---|
[629] | 62 | $result = $this->_curlObj->execute();
|
---|
[457] | 63 |
|
---|
[630] | 64 | $logMsg = date('Y-m-d H:i:s') .' - File: '. __FILE__ . ' - line:'. __LINE__ .' - API Result: '. var_export($result, true). ' - Action: '. var_export($url, true) .' - PARAMS: '. var_export($aryParams, true)."\n";
|
---|
[629] | 65 | write_file('./log/apicalling.log', $logMsg, FOPEN_WRITE_CREATE);
|
---|
[457] | 66 |
|
---|
| 67 | return $result;
|
---|
[418] | 68 | }
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 |
|
---|
[289] | 72 | public function __destruct() {
|
---|
| 73 |
|
---|
| 74 | }
|
---|
| 75 | } |
---|