Skip to content
This repository was archived by the owner on Feb 25, 2018. It is now read-only.

Commit f91534e

Browse files
committed
Added count
1 parent 5abfc61 commit f91534e

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

parse.php

+41-19
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@
9292
*/
9393

9494

95-
class parseRestClient{
96-
95+
class ParseRestClient{
96+
9797
private $appid = '';
9898
private $masterkey = '';
9999
private $parseUrl = 'https://api.parse.com/1/classes/';
100-
100+
private $enableDebug = '';
101101

102102
/**
103103
* When creating a new parseRestClient object
@@ -112,6 +112,10 @@ public function __construct($config){
112112
else{
113113
die('You must include your Application Id and Master Key');
114114
}
115+
116+
if(isset($config['enableDebug'])) {
117+
$this->enableDebug = $config['enableDebug'];
118+
}
115119
}
116120

117121
/*
@@ -129,7 +133,7 @@ private function request($args){
129133
curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
130134
curl_setopt($c, CURLOPT_CUSTOMREQUEST, $args['method']);
131135
curl_setopt($c, CURLOPT_URL, $this->parseUrl . $args['url']);
132-
136+
133137
if($args['method'] == 'PUT' || $args['method'] == "POST"){
134138
$postData = json_encode($args['payload']);
135139
curl_setopt($c, CURLOPT_POSTFIELDS, $postData );
@@ -145,6 +149,9 @@ private function request($args){
145149
if(isset($args['limit'])){
146150
$postData['limit'] = $args['limit'];
147151
}
152+
if(isset($args['count'])){
153+
$postData['count'] = $args['count'];
154+
}
148155
if(isset($args['skip'])){
149156
$postData['skip'] = $args['skip'];
150157
}
@@ -155,27 +162,39 @@ private function request($args){
155162
}
156163
curl_setopt($c, CURLOPT_URL, $this->parseUrl . $args['url'].'?'.$query);
157164
}
158-
165+
166+
if($this->enableDebug == true) {
167+
echo "PostData: \n";
168+
print_r($postData);
169+
echo "Query:\n";
170+
echo $query."\n";
171+
}
172+
159173
}
160174

161175
$response = curl_exec($c);
162176
$httpCode = curl_getinfo($c, CURLINFO_HTTP_CODE);
177+
178+
179+
if($this->enableDebug == true) {
180+
echo "Response: ".$response."\n";
181+
}
163182

164183
return array('code'=>$httpCode, 'response'=>$response);
165184
}
166185

167-
186+
168187
public function create($args){
169188
$params = array(
170189
'url' => $args['className'],
171190
'method' => 'POST',
172191
'payload' => $args['object']
173192
);
174-
193+
175194
$return = $this->request($params);
176195

177196
return $this->checkResponse($return,'201');
178-
197+
179198
}
180199

181200
/*
@@ -194,9 +213,9 @@ public function get($args){
194213
'url' => $args['className'].'/'.$args['objectId'],
195214
'method' => 'GET'
196215
);
197-
216+
198217
$return = $this->request($params);
199-
218+
200219
return $this->checkResponse($return,'200');
201220
}
202221

@@ -218,9 +237,9 @@ public function update($args){
218237
'method' => 'PUT',
219238
'payload' => $args['object']
220239
);
221-
240+
222241
$return = $this->request($params);
223-
242+
224243
return $this->checkResponse($return,'200');
225244
}
226245

@@ -248,9 +267,9 @@ public function query($args){
248267
if(isset($args['query'])){
249268
$params['query'] = $args['query'];
250269
}
251-
else{
270+
/* else{
252271
die('you should use the get method if you are not inluding a query');
253-
}
272+
}*/
254273
if(isset($args['order'])){
255274
$params['order'] = $args['order'];
256275
}
@@ -260,11 +279,14 @@ public function query($args){
260279
if(isset($args['skip'])){
261280
$params['skip'] = $args['skip'];
262281
}
263-
282+
if(isset($args['count'])){
283+
$params['count'] = $args['count'];
284+
}
285+
264286
$return = $this->request($params);
265-
287+
266288
return $this->checkResponse($return,'200');
267-
289+
268290
}
269291

270292
/*
@@ -283,9 +305,9 @@ public function delete($args){
283305
'url' => $args['className'].'/'.$args['objectId'],
284306
'method' => 'DELETE'
285307
);
286-
308+
287309
$return = $this->request($params);
288-
310+
289311
return $this->checkResponse($return,'200');
290312
}
291313

0 commit comments

Comments
 (0)