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

Added Parse Batch Library File #149

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
parseConfig.php
.idea/
10 changes: 1 addition & 9 deletions parse.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?php
include 'parseConfig.php';
include 'parseObject.php';
include 'parseQuery.php';
include 'parseUser.php';
include 'parseFile.php';
include 'parsePush.php';
include 'parseGeoPoint.php';
include 'parseACL.php';
include 'parseCloud.php';
include_once 'parseConfig.php';

class parseRestClient{

Expand Down
1 change: 1 addition & 0 deletions parseACL.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
include_once 'parse.php';
/*
// example:
$object = new parseObject();
Expand Down
65 changes: 65 additions & 0 deletions parseBatch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
include_once 'parse.php';
include_once 'parseObject.php';
/*
* Example Usage:
//NOTES: In Parse.com, create "TestBatch" class, then 1 column names "Notes", and 2 rows.
//Get the objectId from each row and insert into the code below
$b = new parseBatch();
$b->add_update_request('TestBatch', 'INSERT_ID', array('Notes'=>'Custom Note: '.$csv_file_location.'.Update via API on PHP Server Time Seconds: '.time()));
$b->add_update_request('TestBatch', 'INSERT_ID', array('Notes'=>'Custom Note: '.$csv_file_location.'.Second Record Update via API on PHP Server Time Seconds: '.time()));
$results = $b->batch_request();
*/
class parseBatch extends parseObject{

public function __construct(){
//API VERSION IS REQUIRED
if(!defined('PARSE_API_VERSION')){
define('PARSE_API_VERSION', '1');
}
//batch is the class name for batch updates
$this->_className = 'batch';
$this->data = array('requests'=>array());
parent::__construct('batch');
}

public function batch_request(){
$requestBatch = array(
'method' => 'POST',
'requestUrl' => 'batch',
'data' => $this->data,
);
$request = $this->request($requestBatch);
return $request;
}

public function add_request($method, $path, $body){
if(!is_array($body) && $method != 'DELETE'){
return array('error'=>'body is not properly formatted as an array');
}
elseif(count($this->data['requests']) >= 50){
return array('error'=>'limit exceeded, batch requests limited to 50 requests');
}
elseif($method == 'DELETE') {
$this->data['requests'][] = array('method'=>$method, 'path'=>$path);
return true;
}
else {
$this->data['requests'][] = array('method'=>$method, 'path'=>$path, 'body'=>$body);
return true;
}
}

public function add_update_request($class, $objId, $data){
$this->add_request('PUT', '/'.PARSE_API_VERSION.'/classes/'.$class.'/'.$objId, $data);
}

public function add_create_request($class, $data){
$this->add_request('POST', '/'.PARSE_API_VERSION.'/classes/'.$class,$data);
}

public function add_delete_request($class, $objId){
$this->add_request('DELETE', '/'.PARSE_API_VERSION.'/classes/'.$class.'/'.$objId, array());
}

}
1 change: 1 addition & 0 deletions parseCloud.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
include_once 'parse.php';
/*
// Adding the possibility to run parse cloud code functions
$cloud = new parseCloud("functionName");
Expand Down
2 changes: 1 addition & 1 deletion parseFile.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

include_once 'parse.php';
class parseFile extends parseRestClient{

private $_fileName;
Expand Down
2 changes: 1 addition & 1 deletion parseGeoPoint.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

include_once 'parse.php';
class parseGeoPoint extends parseRestClient{

public $lat;
Expand Down
2 changes: 1 addition & 1 deletion parseObject.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

include_once 'parse.php';
class parseObject extends parseRestClient{
public $_includes = array();
private $_className = '';
Expand Down
2 changes: 1 addition & 1 deletion parsePush.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

include_once 'parse.php';
class parsePush extends parseRestClient{

public $channels;
Expand Down
2 changes: 1 addition & 1 deletion parseQuery.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

include_once 'parse.php';
class parseQuery extends parseRestClient{
private $_limit = 100;
private $_skip = 0;
Expand Down
2 changes: 1 addition & 1 deletion parseUser.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

include_once 'parse.php';
class parseUser extends parseRestClient{

public $authData;
Expand Down