-
Notifications
You must be signed in to change notification settings - Fork 5
/
phonagap.php
103 lines (88 loc) · 2.83 KB
/
phonagap.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* Author: Vitaliy Pitvalo
* Email: av.tehnik@gmail.com
* License: GPL
*
*/
class PhoneagpApi {
private $ch;
public function __construct($name, $password) {
$this->ch = curl_init();
curl_setopt($this->ch, CURLOPT_USERPWD, "$name:$password");
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
}
public function getApps() {
$url = "https://build.phonegap.com/api/v1/apps";
curl_setopt($this->ch, CURLOPT_URL, $url);
$output = curl_exec($this->ch);
$obj = json_decode($output);
return $obj->apps;
}
public function uploadApp($file, $title, $createMethod = 'file') {
$url = "https://build.phonegap.com/api/v1/apps?create_method=file";
curl_setopt($this->ch, CURLOPT_POST, 1);
curl_setopt($this->ch, CURLOPT_URL, $url);
$post = array(
"data" => json_encode(array('create_method' => $createMethod, 'title' => $title)),
"file" => "@" . $file
);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post);
$output = curl_exec($this->ch);
$obj = json_decode($output);
if (is_object($obj) && isset($obj->id)) {
return $obj->id;
} else {
return false;
}
}
public function checkApp($id) {
$app = $this->getApp($id);
if ($app) {
return $app->status;
} else {
return false;
}
}
public function getApp($id) {
$url = "https://build.phonegap.com/api/v1/apps/" . $id;
curl_setopt($this->ch, CURLOPT_URL, $url);
$output = curl_exec($this->ch);
$out = json_decode($output);
if (is_object($out)) {
return $out;
} else {
return false;
}
}
public function getDownloadLink($id, $platform) {
$app = $this->getApp($id);
if ($app->status->{$platform} == 'complete') {
$url = "https://build.phonegap.com" . $app->download->{$platform};
curl_setopt($this->ch, CURLOPT_URL, $url);
$data = curl_exec($this->ch);
if (is_object($data) && isset($data->location)) {
return $data->location;
} else {
false;
}
}
}
public function deleteApp($id) {
$url = "https://build.phonegap.com/api/v1/apps/" . $id;
curl_setopt($this->ch, CURLOPT_URL, $url);
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
$r = curl_exec($this->ch);
return $r;
}
public function deleteApps() {
$apps = $this->getApps();
foreach ($apps as $app) {
$this->deleteApp($app->id);
}
}
public function __destruct() {
curl_close($this->ch);
}
}