-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMinusAPI.php
More file actions
91 lines (81 loc) · 1.92 KB
/
MinusAPI.php
File metadata and controls
91 lines (81 loc) · 1.92 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* MinusAPI class, a simple cURL-based PHP wrapper for the min.us API.
* Feel free to use and modify.
*
* @author Rodrigo Ferreira <[email protected]>
*/
class MinusAPI
{
private $_cookies;
public function __construct()
{
$this->_cookies=tempnam(sys_get_temp_dir(),'minus');
if($this->_cookies===false)
throw new Exception('Error creating temporary file.');
}
protected function call($service,$postfields=array())
{
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,'http://min.us/api/'.$service);
curl_setopt($ch,CURLOPT_COOKIEJAR,$this->_cookies);
curl_setopt($ch,CURLOPT_COOKIEFILE,$this->_cookies);
curl_setopt($ch,CURLOPT_HEADER,false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_VERBOSE,false);
if(count($postfields)>0)
{
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postfields);
}
$retval=curl_exec($ch);
$errno=curl_errno($ch);
$error=curl_error($ch);
curl_close($ch);
if($errno!=0)
throw new Exception($error);
return json_decode($retval);
}
public function CreateGallery()
{
return $this->call(__FUNCTION__);
}
public function GetItems($id)
{
return $this->call(__FUNCTION__.'/m'.$id);
}
public function MyGalleries()
{
return $this->call(__FUNCTION__.'.json');
}
public function SaveGallery($id,$name,$items,$key='OK')
{
return $this->call(__FUNCTION__,array(
'id'=>$id,
'name'=>$name,
'key'=>$key,
'items'=>json_encode($items),
));
}
public function SignIn($username,$password)
{
return $this->call(__FUNCTION__,array(
'username'=>$username,
'password1'=>$password,
));
}
public function SignOut()
{
return $this->call(__FUNCTION__);
}
public function UploadItem($id,$name,$path,$key='OK')
{
return $this->call(__FUNCTION__.'?'.http_build_query(array(
'editor_id'=>$id,
'filename'=>$name,
'key'=>$key,
)),array(
'file'=>"@{$path}",
));
}
}