-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcrocodoc.php
68 lines (62 loc) · 1.66 KB
/
crocodoc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
class Crocodoc {
public $api_key = '';
public $api_url = 'https://crocodoc.com/api/v2/';
private function doCurlPost($url, $data){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
private function doCurlGet($url, $dataStr) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url.$dataStr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
public function upload($file, $upload_from_url = true) {
$url = $this->api_url.'document/upload';
$data['token'] = $this->api_key;
if ($upload_from_url)
$data['url'] = $file;
else
$data['file'] = "@".$file;
//this is a POST request
$output = $this->doCurlPost($url, $data);
return $output;
}
public function getStatus($uuids){
$url = $this->api_url.'document/status';
$token = $this->api_key;
$dataStr = '?token='.$token.'&uuids='.$uuids;
// this is a GET request
$output = $this->doCurlGet($url, $dataStr);
return $output;
}
public function delete($uuid) {
$url = $this->api_url.'document/delete';
$data = array(
'token' => $this->api_key,
'uuid' => $uuid
);
//this is a POST request
$output = $this->doCurlPost($url, $data);
return $output;
}
public function createSession($uuid) {
$url = $this->api_url.'session/create';
$data = array(
'token' => $this->api_key,
'uuid' => $uuid);
//this is a POST request
$output = $this->doCurlPost($url, $data);
return $output;
}
}
?>