Skip to content
This repository was archived by the owner on Feb 25, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified EnhanceTestFramework.php
100644 → 100755
Empty file.
88 changes: 49 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,78 @@
PHP parse.com API library
===========================
More on the parse.com api here: https://www.parse.com/docs/rest

### V1 is still available ###
Availalbe here: https://github.com/apotropaic/parse.com-php-library/blob/parse.com-php-library_v1/README.md

I wrote tests not for testing sake, but really just to see how I liked how the library worked!

### Feedback Wanted ###

This is a work in progress and is a drasticly different then v1 of this library.

Let me know what you think and suggestions and ideas

## Original Version ##
Availalbe here: https://github.com/apotropaic/parse.com-php-library

SETUP
=========================

**Instructions** after cloning this repository you have to create a file in the root of it called **parseConfig.php**

### sample of parseConfig.php ###
## sample of parseConfig.php ##

Below is what you want parseConfig.php to look like, just fill in your IDs and KEYs to get started.

```
<?php

class parseConfig{

const APPID = '';
const MASTERKEY = '';
const RESTKEY = '';
const PARSEURL = 'https://api.parse.com/1/';
}

?>

```

SAMPLE CODE
=========================

## Adding/Removing Relations ##

EXAMPLE
=========================
### Sample of creating a relation ###

```
<?php
// addRelation($field,$class,$objectID);

// ObjectID is the object ID of the row you would like to become a relation
$relation_objectID = "ABBBBBBC";
// Name of the class where the object ID is found
$relation_className = "Book";
// The id of row you would like to update
$id = "BCCCCCCD";

$parseObject = new parseObject("_User");
$parseObject->addRelation('books',$relation_className,$relation_objectID);
$parseObject->update($id);

// For example the above would add the row with the objectID: ABBBBBBC
// Found in the Class called: Book
// To the class '_User' (the user class)
// With an objectID of: BCCCCCCD in the column called books
?>
```

### sample of upload.php ###

### Sample of removing a relation ###

```
<?php
//This example is a sample video upload stored in parse
$parse = new parseObject('Videos');
$parse->title = $data['upload_data']['title'];
$parse->description = $data['upload_data']['description'];
$parse->tags = $data['upload_data']['tags'];
//create new geo
$geo = new parseGeoPoint($data['upload_data']['lat'],$data['upload_data']['lng']);
$parse->location = $geo->location;
//use pointer to other class
$parse->userid = array("__type" => "Pointer", "className" => "_User", "objectId" => $data['upload_data']['userid']);
//create acl
$parse->ACL = array("*" => array("write" => true, "read" => true));
$r = $parse->save();
?>
// removeRelation($field,$class,$objectID);

// ObjectID is the object ID of the row you would like to become a relation
$relation_objectID = "ABBBBBBC";
// Name of the class where the object ID is found
$relation_className = "Book";
// The id of row you would like to update
$id = "BCCCCCCD";

$parseObject = new parseObject("_User");
$parseObject->removeRelation('books',$relation_className,$relation_objectID);
$parseObject->update($id);

// For example the above would remove the row with the objectID: ABBBBBBC
// Found in the Class called: Book
// To the class '_User' (the user class)
// With an objectID of: BCCCCCCD in the column called books
?>
```
34 changes: 27 additions & 7 deletions parse.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function request($args){
curl_setopt($c, CURLOPT_TIMEOUT, 30);
curl_setopt($c, CURLOPT_USERAGENT, 'parse.com-php-library/2.0');
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLINFO_HEADER_OUT, true);
if(substr($args['requestUrl'],0,5) == 'files'){
curl_setopt($c, CURLOPT_HTTPHEADER, array(
Expand Down Expand Up @@ -112,17 +113,21 @@ public function request($args){
}
}


//BELOW HELPS WITH DEBUGGING
/*
if(!in_array($responseCode,$expectedCode)){
//print_r($response);
//print_r($args);
}
*/

// if(!in_array($responseCode,$expectedCode)){
//print("<pre>");
//print_r($response);
//print_r($args);
//print("</pre>");
// }

return $this->checkResponse($response,$responseCode,$expectedCode);
}

public function dataType($type,$params){
date_default_timezone_set("UTC");
if($type != ''){
switch($type){
case 'date':
Expand Down Expand Up @@ -151,6 +156,18 @@ public function dataType($type,$params){
"longitude" => floatval($params[1])
);
break;
case 'addRelation':
$return = array(
"__op" => "AddRelation",
"objects" => array($params[0])
);
break;
case 'addRelation':
$return = array(
"__op" => "RemoveRelation",
"objects" => array($params[0])
);
break;
case 'file':
$return = array(
"__type" => "File",
Expand Down Expand Up @@ -179,14 +196,17 @@ public function dataType($type,$params){
}

public function throwError($msg,$code=0){
if($code == "101"){return "101";}
throw new ParseLibraryException($msg,$code);
}

private function checkResponse($response,$responseCode,$expectedCode){
//TODO: Need to also check for response for a correct result from parse.com
if(!in_array($responseCode,$expectedCode)){
$error = json_decode($response);
$this->throwError($error->error,$error->code);
$error_text = isset($error->error) ? $error->error : false;
$error_code = isset($error->code) ? $error->code : false;
return $this->throwError($error_text,$error_code);
}
else{
//check for empty return
Expand Down
Empty file modified parseACL.php
100644 → 100755
Empty file.
Empty file modified parseCloud.php
100644 → 100755
Empty file.
Empty file modified parseFile.php
100644 → 100755
Empty file.
Empty file modified parseGeoPoint.php
100644 → 100755
Empty file.
14 changes: 12 additions & 2 deletions parseObject.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,20 @@ public function increment($field,$amount){
$this->data[$field] = $this->dataType('increment', $amount);
}

public function decrement($id){
public function decrement($field,$amount){
$this->data[$field] = $this->dataType('decrement', $amount);
}


public function addRelation($field,$class,$objectID){
$pointer = array($this->dataType('pointer',array($class,$objectID)));
$this->data[$field] = $this->dataType('addRelation',$pointer);
}

public function removeRelation($field,$class,$objectID){
$pointer = array($this->dataType('pointer',array($class,$objectID)));
$this->data[$field] = $this->dataType('removeRelation', $pointer);
}


public function delete($id){
if($this->_className != '' || !empty($id)){
Expand Down
Empty file modified parsePush.php
100644 → 100755
Empty file.
34 changes: 32 additions & 2 deletions parseQuery.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public function find(){

return $request;

}
else{
}else{
$urlParams = array(
'where' => json_encode( $this->_query )
);
Expand Down Expand Up @@ -148,6 +147,7 @@ public function whereNotEqualTo($key,$value){
}
}


public function whereGreaterThan($key,$value){
if(isset($key) && isset($value)){
$this->_query[$key] = array(
Expand Down Expand Up @@ -195,6 +195,36 @@ public function whereLessThanOrEqualTo($key,$value){
}

}

public function whereGreaterThanAndLessThan($key,$value1,$value2){
if(isset($key) && isset($value1) && isset($value2)){
$this->_query[$key] = array(
'$gte' => $value1,
'$lte' => $value2
);
}
else{
$this->throwError('the $key and $value parameters must be set when setting a "where" query method');
}
}

public function whereAll($key,$value){
if(isset($key) && isset($value)){
if(is_array($value)){
$this->_query[$key] = array(
'$all' => $value
);
}
else{
$this->throwError('$value must be an array to check through');
}
}
else{
$this->throwError('the $key and $value parameters must be set when setting a "where" query method');
}

}


public function whereContainedIn($key,$value){
if(isset($key) && isset($value)){
Expand Down
Empty file modified parseUser.php
100644 → 100755
Empty file.