1 | <?php
|
---|
2 |
|
---|
3 | Class VServices {
|
---|
4 |
|
---|
5 | private $_apiUrl;
|
---|
6 | private $_curlObj;
|
---|
7 | private $_userId;
|
---|
8 | private $_password;
|
---|
9 |
|
---|
10 | private $_httpUser;
|
---|
11 | private $_httpPasswd;
|
---|
12 |
|
---|
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));
|
---|
35 | $post = $this->_userId ? array('userid' => $this->_userId) : array();
|
---|
36 | $this->_curlObj->post($post);
|
---|
37 | return $this->_curlObj->execute();
|
---|
38 | }
|
---|
39 | public function getPreview ($fileId) {
|
---|
40 | $this->_curlObj->create($this->_apiUrl. 'space/preview/');
|
---|
41 | $this->_curlObj->option(CURLOPT_BUFFERSIZE, 10);
|
---|
42 | $this->_curlObj->options(array(CURLOPT_BUFFERSIZE => 10));
|
---|
43 | $post = $this->_userId ? array('fileId' => $fileId,'userId' => $this->_userId) : array();
|
---|
44 | $this->_curlObj->post($post);
|
---|
45 | return $this->_curlObj->execute();
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * $aryParams
|
---|
50 | *
|
---|
51 | * @param unknown $action
|
---|
52 | * @param unknown $aryParams
|
---|
53 | */
|
---|
54 |
|
---|
55 | public function actionExecute ($action, $aryParams = array(), $module = 'space') {
|
---|
56 | $url = $this->_apiUrl. $module .'/'.$action;
|
---|
57 |
|
---|
58 | $this->_curlObj->create($url);
|
---|
59 | $this->_curlObj->option(CURLOPT_BUFFERSIZE, 10);
|
---|
60 | $this->_curlObj->option(CURLOPT_HEADER, 0);
|
---|
61 | $this->_curlObj->option(CURLOPT_FAILONERROR, FALSE);
|
---|
62 |
|
---|
63 | if ($this->_httpUser && $this->_httpPasswd) {
|
---|
64 | $this->_curlObj->http_login($this->_httpUser, $this->_httpPasswd);
|
---|
65 | }
|
---|
66 |
|
---|
67 | if ($this->_userId) $aryParams['userid'] = $this->_userId;
|
---|
68 | if (count($aryParams) > 0) $this->_curlObj->post($aryParams);
|
---|
69 |
|
---|
70 | $result = $this->_curlObj->execute();
|
---|
71 |
|
---|
72 | $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";
|
---|
73 | write_file('./log/apicalling.log', $logMsg, FOPEN_WRITE_CREATE);
|
---|
74 |
|
---|
75 | return $result;
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 |
|
---|
80 | public function __destruct() {
|
---|
81 |
|
---|
82 | }
|
---|
83 | } |
---|