92
92
*/
93
93
94
94
95
- class parseRestClient {
96
-
95
+ class ParseRestClient {
96
+
97
97
private $ appid = '' ;
98
98
private $ masterkey = '' ;
99
99
private $ parseUrl = 'https://api.parse.com/1/classes/ ' ;
100
-
100
+ private $ enableDebug = '' ;
101
101
102
102
/**
103
103
* When creating a new parseRestClient object
@@ -112,6 +112,10 @@ public function __construct($config){
112
112
else {
113
113
die ('You must include your Application Id and Master Key ' );
114
114
}
115
+
116
+ if (isset ($ config ['enableDebug ' ])) {
117
+ $ this ->enableDebug = $ config ['enableDebug ' ];
118
+ }
115
119
}
116
120
117
121
/*
@@ -129,7 +133,7 @@ private function request($args){
129
133
curl_setopt ($ c , CURLOPT_HTTPHEADER , array ('Content-Type: application/json ' ));
130
134
curl_setopt ($ c , CURLOPT_CUSTOMREQUEST , $ args ['method ' ]);
131
135
curl_setopt ($ c , CURLOPT_URL , $ this ->parseUrl . $ args ['url ' ]);
132
-
136
+
133
137
if ($ args ['method ' ] == 'PUT ' || $ args ['method ' ] == "POST " ){
134
138
$ postData = json_encode ($ args ['payload ' ]);
135
139
curl_setopt ($ c , CURLOPT_POSTFIELDS , $ postData );
@@ -145,6 +149,9 @@ private function request($args){
145
149
if (isset ($ args ['limit ' ])){
146
150
$ postData ['limit ' ] = $ args ['limit ' ];
147
151
}
152
+ if (isset ($ args ['count ' ])){
153
+ $ postData ['count ' ] = $ args ['count ' ];
154
+ }
148
155
if (isset ($ args ['skip ' ])){
149
156
$ postData ['skip ' ] = $ args ['skip ' ];
150
157
}
@@ -155,27 +162,39 @@ private function request($args){
155
162
}
156
163
curl_setopt ($ c , CURLOPT_URL , $ this ->parseUrl . $ args ['url ' ].'? ' .$ query );
157
164
}
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
+
159
173
}
160
174
161
175
$ response = curl_exec ($ c );
162
176
$ httpCode = curl_getinfo ($ c , CURLINFO_HTTP_CODE );
177
+
178
+
179
+ if ($ this ->enableDebug == true ) {
180
+ echo "Response: " .$ response ."\n" ;
181
+ }
163
182
164
183
return array ('code ' =>$ httpCode , 'response ' =>$ response );
165
184
}
166
185
167
-
186
+
168
187
public function create ($ args ){
169
188
$ params = array (
170
189
'url ' => $ args ['className ' ],
171
190
'method ' => 'POST ' ,
172
191
'payload ' => $ args ['object ' ]
173
192
);
174
-
193
+
175
194
$ return = $ this ->request ($ params );
176
195
177
196
return $ this ->checkResponse ($ return ,'201 ' );
178
-
197
+
179
198
}
180
199
181
200
/*
@@ -194,9 +213,9 @@ public function get($args){
194
213
'url ' => $ args ['className ' ].'/ ' .$ args ['objectId ' ],
195
214
'method ' => 'GET '
196
215
);
197
-
216
+
198
217
$ return = $ this ->request ($ params );
199
-
218
+
200
219
return $ this ->checkResponse ($ return ,'200 ' );
201
220
}
202
221
@@ -218,9 +237,9 @@ public function update($args){
218
237
'method ' => 'PUT ' ,
219
238
'payload ' => $ args ['object ' ]
220
239
);
221
-
240
+
222
241
$ return = $ this ->request ($ params );
223
-
242
+
224
243
return $ this ->checkResponse ($ return ,'200 ' );
225
244
}
226
245
@@ -248,9 +267,9 @@ public function query($args){
248
267
if (isset ($ args ['query ' ])){
249
268
$ params ['query ' ] = $ args ['query ' ];
250
269
}
251
- else {
270
+ /* else{
252
271
die('you should use the get method if you are not inluding a query');
253
- }
272
+ }*/
254
273
if (isset ($ args ['order ' ])){
255
274
$ params ['order ' ] = $ args ['order ' ];
256
275
}
@@ -260,11 +279,14 @@ public function query($args){
260
279
if (isset ($ args ['skip ' ])){
261
280
$ params ['skip ' ] = $ args ['skip ' ];
262
281
}
263
-
282
+ if (isset ($ args ['count ' ])){
283
+ $ params ['count ' ] = $ args ['count ' ];
284
+ }
285
+
264
286
$ return = $ this ->request ($ params );
265
-
287
+
266
288
return $ this ->checkResponse ($ return ,'200 ' );
267
-
289
+
268
290
}
269
291
270
292
/*
@@ -283,9 +305,9 @@ public function delete($args){
283
305
'url ' => $ args ['className ' ].'/ ' .$ args ['objectId ' ],
284
306
'method ' => 'DELETE '
285
307
);
286
-
308
+
287
309
$ return = $ this ->request ($ params );
288
-
310
+
289
311
return $ this ->checkResponse ($ return ,'200 ' );
290
312
}
291
313
0 commit comments