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

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: andrewscofield/parse.com-php-library
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: alexargo/parse.com-php-library
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Nov 17, 2011

  1. Added count

    alexargo committed Nov 17, 2011
    Copy the full SHA
    f91534e View commit details
Showing with 41 additions and 19 deletions.
  1. +41 −19 parse.php
60 changes: 41 additions & 19 deletions parse.php
Original file line number Diff line number Diff line change
@@ -92,12 +92,12 @@
*/


class parseRestClient{
class ParseRestClient{

private $appid = '';
private $masterkey = '';
private $parseUrl = 'https://api.parse.com/1/classes/';

private $enableDebug = '';

/**
* When creating a new parseRestClient object
@@ -112,6 +112,10 @@ public function __construct($config){
else{
die('You must include your Application Id and Master Key');
}

if(isset($config['enableDebug'])) {
$this->enableDebug = $config['enableDebug'];
}
}

/*
@@ -129,7 +133,7 @@ private function request($args){
curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($c, CURLOPT_CUSTOMREQUEST, $args['method']);
curl_setopt($c, CURLOPT_URL, $this->parseUrl . $args['url']);

if($args['method'] == 'PUT' || $args['method'] == "POST"){
$postData = json_encode($args['payload']);
curl_setopt($c, CURLOPT_POSTFIELDS, $postData );
@@ -145,6 +149,9 @@ private function request($args){
if(isset($args['limit'])){
$postData['limit'] = $args['limit'];
}
if(isset($args['count'])){
$postData['count'] = $args['count'];
}
if(isset($args['skip'])){
$postData['skip'] = $args['skip'];
}
@@ -155,27 +162,39 @@ private function request($args){
}
curl_setopt($c, CURLOPT_URL, $this->parseUrl . $args['url'].'?'.$query);
}


if($this->enableDebug == true) {
echo "PostData: \n";
print_r($postData);
echo "Query:\n";
echo $query."\n";
}

}

$response = curl_exec($c);
$httpCode = curl_getinfo($c, CURLINFO_HTTP_CODE);


if($this->enableDebug == true) {
echo "Response: ".$response."\n";
}

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


public function create($args){
$params = array(
'url' => $args['className'],
'method' => 'POST',
'payload' => $args['object']
);

$return = $this->request($params);

return $this->checkResponse($return,'201');

}

/*
@@ -194,9 +213,9 @@ public function get($args){
'url' => $args['className'].'/'.$args['objectId'],
'method' => 'GET'
);

$return = $this->request($params);

return $this->checkResponse($return,'200');
}

@@ -218,9 +237,9 @@ public function update($args){
'method' => 'PUT',
'payload' => $args['object']
);

$return = $this->request($params);

return $this->checkResponse($return,'200');
}

@@ -248,9 +267,9 @@ public function query($args){
if(isset($args['query'])){
$params['query'] = $args['query'];
}
else{
/* else{
die('you should use the get method if you are not inluding a query');
}
}*/
if(isset($args['order'])){
$params['order'] = $args['order'];
}
@@ -260,11 +279,14 @@ public function query($args){
if(isset($args['skip'])){
$params['skip'] = $args['skip'];
}

if(isset($args['count'])){
$params['count'] = $args['count'];
}

$return = $this->request($params);

return $this->checkResponse($return,'200');

}

/*
@@ -283,9 +305,9 @@ public function delete($args){
'url' => $args['className'].'/'.$args['objectId'],
'method' => 'DELETE'
);

$return = $this->request($params);

return $this->checkResponse($return,'200');
}