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 diff --git a/parse.php b/parse.php index 554d687..f019fe4 100644 --- a/parse.php +++ b/parse.php @@ -1,13 +1,5 @@ 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 diff --git a/parseCloud.php b/parseCloud.php index 76745a4..e228bab 100644 --- a/parseCloud.php +++ b/parseCloud.php @@ -1,4 +1,5 @@