-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbeanstalk_api.php
More file actions
273 lines (249 loc) · 7.19 KB
/
beanstalk_api.php
File metadata and controls
273 lines (249 loc) · 7.19 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
class beanstalk_api {
/**
* Beanstalk account configuration
*
* Please enter your account name, username and password below.
*/
private $account_name = 'example'; // Beanstalk account name (first segment of your beanstalk URL - http://example.beanstalkapp.com)
private $username = 'username'; // Beanstalk username
private $password = 'password'; // Beanstalk password
/**
* Returns Beanstalk account details.
*
* @return xml
*/
function get_account_details() {
return $this->_execute_curl("account.xml");
}
/**
* Allows a user to update their account details by sending specific parameters
*
* @param string $name required
* @param string $time_zone required
* @return xml
*/
function update_account_details($name, $time_zone) {
if(empty($name) || empty($time_zone))
return "Name and time zone required";
}
/**
* Returns Beanstalk account plans
*
* @returns xml
*/
function find_all_plans() {
return $this->_execute_curl("plans.xml");
}
/**
* Returns Beanstalk account user list.
*
* @return xml
*/
function find_all_users() {
return $this->_execute_curl("users.xml");
}
/**
* Returns a Beanstalk account user based on a specific user ID
*
* @param integer $user_id required
* @return xml
*/
function find_single_user($user_id) {
if(empty($user_id))
return "User ID required";
else
return $this->_execute_curl("users", $user_id . ".xml");
}
/**
* Returns Beanstalk account repository list
*
* @return xml
*/
function find_all_repositories() {
return $this->_execute_curl("repositories.xml");
}
/**
* Returns a Beanstalk account repository based on a specific repository ID
*
* @param integer $repo_id required
* @return xml
*/
function find_single_repository($repo_id) {
if(empty($repo_id))
return "Repository ID required";
else
return $this->_execute_curl("repositories", $repo_id . ".xml");
}
/**
* Returns Beanstalk account changeset list
*
* @return xml
*/
function find_all_changesets() {
return $this->_execute_curl("changesets.xml");
}
/**
* Returns a Beanstalk repository changeset based on a specific repository ID
*
* @param integer $repo_id required
* @return xml
*/
function find_single_repository_changeset($repo_id) {
if(empty($repo_id))
return "Repository ID required";
else
return $this->_execute_curl("changesets", "repository.xml?repository_id=" . $repo_id);
}
/**
* Returns a Beanstalk repository's specific changeset based on a specific repository ID and changeset ID
*
* @param integer $repo_id required
* @param integer $revision required
* @return xml
*/
function find_single_changeset($repo_id, $revision) {
if(empty($repo_id) || empty($revision))
return "Changeset ID and repository ID required";
else
return $this->_execute_curl("changesets", $revision . ".xml?repository_id=" . $repo_id);
}
/**
* Returns a Beanstalk repository's comment listing
*
* @param integer $repo_id required
* @return xml
*/
function find_all_comments($repo_id) {
if(empty($repo_id))
return "Repository ID required";
else
return $this->_execute_curl($repo_id, "comments.xml");
}
/**
* Returns a Beanstalk repository's comment listing for a specific changeset
*
* @param integer $repo_id required
* @param integer $revision required
* @return xml
*/
function find_all_changeset_comments($repo_id, $revision) {
if(empty($repo_id) || empty($revision))
return "Repository ID and revision ID required";
else
return $this->_execute_curl($repo_id, "comments.xml?revision=" . $revision);
}
/**
* Returns a Beanstalk repository's comment based on a specific comment ID
*
* @param integer $repo_id required
* @param integer $revision required
* @return xml
*/
function find_single_comment($repo_id, $comment_id) {
if(empty($repo_id) || empty($comment_id))
return "Repository ID and comment ID required";
else
return $this->_execute_curl($repo_id, "comments/" . $comment_id . ".xml");
}
/**
* Returns a Beanstalk repository's server environment listing
*
* @param integer $repo_id required
* @return xml
*/
function find_all_server_environments($repo_id) {
if(empty($repo_id))
return "Repository ID required";
else
return $this->_execute_curl($repo_id, "server_environments.xml");
}
/**
* Returns a Beanstalk repository's server environment listing based on a specific environment ID
*
* @param integer $repo_id required
* @param integer $environment_id required
* @return xml
*/
function find_single_server_environment($repo_id, $environment_id) {
if(empty($repo_id) || empty($environment_id))
return "Repository ID required";
else
return $this->_execute_curl($repo_id, "server_environments/" . $environment_id . ".xml");
}
/**
* Returns a Beanstalk repository's release server listing
*
* @param integer $repo_id required
* @param integer $environment_id required
* @return xml
*/
function find_all_release_servers($repo_id, $environment_id) {
if(empty($repo_id) || empty($environment_id))
return "Repository ID and environment ID required";
else
return $this->_execute_curl($repo_id, "release_servers.xml?environment_id=" . $environment_id);
}
/**
* Returns a Beanstalk repository's release server listing based on a specific server ID
*
* @param integer $repo_id required
* @param integer $server_id required
* @return xml
*/
function find_single_release_server($repo_id, $server_id) {
if(empty($repo_id) || empty($server_id))
return "Repository ID and server ID required";
else
return $this->_execute_curl($repo_id, "release_servers/" . $server_id . ".xml");
}
/**
* Returns a Beanstalk repository's successful releases listing
*
* @param integer $repo_id required
* @return xml
*/
function find_all_sucessful_releases($repo_id) {
if(empty($repo_id))
return "Repository ID required";
else
return $this->_execute_curl($repo_id, "releases.xml");
}
/**
* Returns a Beanstalk repository's release based on a specific release id
*
* @param integer $repo_id required
* @param integer $release_id required
* @return xml
*/
function find_single_release($repo_id, $release_id) {
if(empty($repo_id) || empty($release_id))
return "Repository ID and release ID required";
else
return $this->_execute_curl($repo_id, $release_id . ".xml");
}
/**
* Sets up and executes the cURL requests and returns the response
*
* @param string $api_name
* @param null $api_params
* @param null $curl_param
* @return mixed
*/
function _execute_curl($api_name, $api_params = NULL, $curl_param = NULL) {
if( ! isset($api_params))
$ch = curl_init("http://" . $this->account_name . ".beanstalkapp.com/api/" . $api_name);
else
$ch = curl_init("http://" . $this->account_name . ".beanstalkapp.com/api/" . $api_name . "/" . $api_params);
$headers = array('Content-type: application/xml');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->password);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if($curl_param == "PUT")
curl_setopt($ch, CURLOPT_PUT, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
}