From 9ac9f9c0a7cfe365e596df892dc6f1dc0abacc70 Mon Sep 17 00:00:00 2001 From: scarstens Date: Tue, 29 Apr 2014 00:13:52 -0700 Subject: [PATCH 1/3] ignore PHPStorm IDE --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a17df00..ad56a77 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ parseConfig.php +.idea/ \ No newline at end of file From 8f70a27717b71b0c778083bf3267e48168671af5 Mon Sep 17 00:00:00 2001 From: scarstens Date: Tue, 29 Apr 2014 00:24:02 -0700 Subject: [PATCH 2/3] add parseObject extension -> parseBatch for bulk requests --- parse.php | 1 + parseBatch.php | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 parseBatch.php diff --git a/parse.php b/parse.php index 554d687..133e2f9 100644 --- a/parse.php +++ b/parse.php @@ -8,6 +8,7 @@ include 'parseGeoPoint.php'; include 'parseACL.php'; include 'parseCloud.php'; +include 'parseBatch.php'; class parseRestClient{ diff --git a/parseBatch.php b/parseBatch.php new file mode 100644 index 0000000..2152f96 --- /dev/null +++ b/parseBatch.php @@ -0,0 +1,63 @@ +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()); + } + +} \ No newline at end of file From f1ce9f3c32920eeb543e998792f29f3d7ae56f93 Mon Sep 17 00:00:00 2001 From: scarstens Date: Tue, 29 Apr 2014 00:46:35 -0700 Subject: [PATCH 3/3] change include function to allow library to be loaded in "modules" instead of all or none --- parse.php | 11 +---------- parseACL.php | 1 + parseBatch.php | 2 ++ parseCloud.php | 1 + parseFile.php | 2 +- parseGeoPoint.php | 2 +- parseObject.php | 2 +- parsePush.php | 2 +- parseQuery.php | 2 +- parseUser.php | 2 +- 10 files changed, 11 insertions(+), 16 deletions(-) diff --git a/parse.php b/parse.php index 133e2f9..f019fe4 100644 --- a/parse.php +++ b/parse.php @@ -1,14 +1,5 @@