@@ -2,7 +2,7 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace SugarAPI\SDK\Exception; |
| 4 | 4 | |
| 5 | -class SDKException extends \Exception{ |
|
| 5 | +class SDKException extends \Exception { |
|
| 6 | 6 | |
| 7 | 7 | public function __construct($message = 'Unknown SugarAPI SDK Exception Occurred.') { |
| 8 | 8 | parent::__construct($message); |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | public function setBody($body) { |
| 19 | 19 | $this->body = $body; |
| 20 | - $this->setOption(CURLOPT_POSTFIELDS,$this->body); |
|
| 20 | + $this->setOption(CURLOPT_POSTFIELDS, $this->body); |
|
| 21 | 21 | return $this; |
| 22 | 22 | } |
| 23 | 23 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * |
| 18 | 18 | * Convert Body to Query String |
| 19 | 19 | */ |
| 20 | - public function setBody($body){ |
|
| 20 | + public function setBody($body) { |
|
| 21 | 21 | $this->body = http_build_query($body); |
| 22 | 22 | return $this; |
| 23 | 23 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * |
| 28 | 28 | * Configure the URL with Body since Payload is sent via Query String |
| 29 | 29 | */ |
| 30 | - public function send(){ |
|
| 30 | + public function send() { |
|
| 31 | 31 | $this->setURL($this->url."?".$this->body); |
| 32 | 32 | return parent::send(); |
| 33 | 33 | } |
@@ -26,38 +26,38 @@ |
||
| 26 | 26 | * Set Temp File for File Response |
| 27 | 27 | * @inheritdoc |
| 28 | 28 | */ |
| 29 | - public function send(){ |
|
| 29 | + public function send() { |
|
| 30 | 30 | //$this->initFile(); |
| 31 | 31 | return parent::send(); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - public function setFile($filePath){ |
|
| 35 | - if ($this->status == self::STATUS_INIT) { |
|
| 34 | + public function setFile($filePath) { |
|
| 35 | + if ($this->status==self::STATUS_INIT) { |
|
| 36 | 36 | $this->filePath = fopen($filePath, 'w+'); |
| 37 | 37 | } |
| 38 | 38 | return $this; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - protected function initFile(){ |
|
| 42 | - if ($this->status == self::STATUS_INIT) { |
|
| 43 | - if ($this->filePath == NULL) { |
|
| 41 | + protected function initFile() { |
|
| 42 | + if ($this->status==self::STATUS_INIT) { |
|
| 43 | + if ($this->filePath==NULL) { |
|
| 44 | 44 | $this->filePath = tempnam(sys_get_temp_dir(), 'SugarAP_SDK_Response_'); |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | - $this->fileHandle = fopen($this->filePath,'w+'); |
|
| 47 | + $this->fileHandle = fopen($this->filePath, 'w+'); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - protected function closeFile(){ |
|
| 51 | - if ($this->status !== self::STATUS_INIT) { |
|
| 50 | + protected function closeFile() { |
|
| 51 | + if ($this->status!==self::STATUS_INIT) { |
|
| 52 | 52 | fclose($this->fileHandle); |
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - public function getFile(){ |
|
| 56 | + public function getFile() { |
|
| 57 | 57 | return $this->filePath; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - public function close(){ |
|
| 60 | + public function close() { |
|
| 61 | 61 | $this->closeFile(); |
| 62 | 62 | return parent::close(); |
| 63 | 63 | } |
@@ -1,21 +1,21 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -require_once __DIR__ . '/../vendor/autoload.php'; |
|
| 3 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
| 4 | 4 | |
| 5 | 5 | $record_id = '436dcb0b-14a9-c0d4-3046-5706b186b9b8'; |
| 6 | 6 | |
| 7 | -try{ |
|
| 8 | - $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Pro/7621/',array('username' => 'admin','password'=>'asdf')); |
|
| 7 | +try { |
|
| 8 | + $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Pro/7621/', array('username' => 'admin', 'password'=>'asdf')); |
|
| 9 | 9 | $SugarAPI->login(); |
| 10 | - $EP = $SugarAPI->updateRecord('Accounts',$record_id); |
|
| 10 | + $EP = $SugarAPI->updateRecord('Accounts', $record_id); |
|
| 11 | 11 | $EP->getRequest()->setOption(); |
| 12 | - $record = $SugarAPI->updateRecord('Accounts',$record_id)->data(array( |
|
| 12 | + $record = $SugarAPI->updateRecord('Accounts', $record_id)->data(array( |
|
| 13 | 13 | 'name' => 'Test Record 5', |
| 14 | 14 | 'email1' => '[email protected]' |
| 15 | 15 | ))->execute()->getResponse()->getBody(); |
| 16 | 16 | echo "Updated Record: ".$record->id; |
| 17 | 17 | |
| 18 | -}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
| 18 | +}catch (\SugarAPI\SDK\Exception\AuthenticationException $ex) { |
|
| 19 | 19 | print $ex->getMessage(); |
| 20 | 20 | } |
| 21 | 21 | |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | ))->execute()->getResponse()->getBody(); |
| 16 | 16 | echo "Updated Record: ".$record->id; |
| 17 | 17 | |
| 18 | -}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
| 18 | +} catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
| 19 | 19 | print $ex->getMessage(); |
| 20 | 20 | } |
| 21 | 21 | |
@@ -1,18 +1,18 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -require_once __DIR__ . '/../vendor/autoload.php'; |
|
| 3 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
| 4 | 4 | |
| 5 | 5 | $record_id = 'a887c75b-b89a-852e-8e67-56f1ccdee355'; |
| 6 | 6 | |
| 7 | -try{ |
|
| 8 | - $SugarAPI = new \SugarAPI\SDK\SugarAPI('localhost/ent77',array('username' => 'admin','password'=>'admin123')); |
|
| 7 | +try { |
|
| 8 | + $SugarAPI = new \SugarAPI\SDK\SugarAPI('localhost/ent77', array('username' => 'admin', 'password'=>'admin123')); |
|
| 9 | 9 | $SugarAPI->login(); |
| 10 | - $EP = $SugarAPI->favorite('Accounts',$record_id); |
|
| 10 | + $EP = $SugarAPI->favorite('Accounts', $record_id); |
|
| 11 | 11 | $response = $EP->execute()->getResponse()->getBody(); |
| 12 | 12 | |
| 13 | 13 | print_r($response); |
| 14 | 14 | |
| 15 | -}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
| 15 | +}catch (\SugarAPI\SDK\Exception\AuthenticationException $ex) { |
|
| 16 | 16 | print $ex->getMessage(); |
| 17 | 17 | } |
| 18 | 18 | |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | |
| 13 | 13 | print_r($response); |
| 14 | 14 | |
| 15 | -}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
| 15 | +} catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
| 16 | 16 | print $ex->getMessage(); |
| 17 | 17 | } |
| 18 | 18 | |
@@ -1,13 +1,13 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -require_once __DIR__ . '/../vendor/autoload.php'; |
|
| 3 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
| 4 | 4 | |
| 5 | -try{ |
|
| 6 | - $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7700/',array('username' => 'admin','password'=>'asdf')); |
|
| 5 | +try { |
|
| 6 | + $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7700/', array('username' => 'admin', 'password'=>'asdf')); |
|
| 7 | 7 | $SugarAPI->login(); |
| 8 | 8 | $EP = $SugarAPI->createRecord('Notes')->data(array('name' => 'Test Note'))->execute(); |
| 9 | 9 | $response = $EP->getResponse(); |
| 10 | - if ($response->getStatus()=='200'){ |
|
| 10 | + if ($response->getStatus()=='200') { |
|
| 11 | 11 | $record = $response->getBody(); |
| 12 | 12 | |
| 13 | 13 | $uplaodFileParams = array( |
@@ -16,23 +16,23 @@ discard block |
||
| 16 | 16 | "oauth_token" => $SugarAPI->getToken()->access_token, |
| 17 | 17 | 'filename' => '@'.__DIR__.'/testfile.txt;filename=testfile.txt' |
| 18 | 18 | ); |
| 19 | - $upload = $SugarAPI->attachFile('Notes',$record->id,'filename')->data($uplaodFileParams)->execute(); |
|
| 19 | + $upload = $SugarAPI->attachFile('Notes', $record->id, 'filename')->data($uplaodFileParams)->execute(); |
|
| 20 | 20 | $response = $upload->getResponse(); |
| 21 | - if ($response->getStatus()=='200'){ |
|
| 21 | + if ($response->getStatus()=='200') { |
|
| 22 | 22 | $record = $response->getBody(); |
| 23 | 23 | print_r($response); |
| 24 | - }else{ |
|
| 24 | + }else { |
|
| 25 | 25 | print_r($upload->getRequest()); |
| 26 | 26 | echo "Failed to Update Note with File<br>"; |
| 27 | 27 | echo "Response: ".$response->getStatus()."<br>"; |
| 28 | 28 | print_r($response->getBody()); |
| 29 | 29 | } |
| 30 | - }else{ |
|
| 30 | + }else { |
|
| 31 | 31 | echo "Failed to create Note<br>"; |
| 32 | 32 | echo "Response: ".$response->getStatus()."<br>"; |
| 33 | 33 | print_r($response->getBody()); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | -}catch(\SugarAPI\SDK\Exception\SDKException $ex){ |
|
| 36 | +}catch (\SugarAPI\SDK\Exception\SDKException $ex) { |
|
| 37 | 37 | print $ex->getMessage(); |
| 38 | 38 | } |
| 39 | 39 | \ No newline at end of file |
@@ -21,18 +21,18 @@ |
||
| 21 | 21 | if ($response->getStatus()=='200'){ |
| 22 | 22 | $record = $response->getBody(); |
| 23 | 23 | print_r($response); |
| 24 | - }else{ |
|
| 24 | + } else{ |
|
| 25 | 25 | print_r($upload->getRequest()); |
| 26 | 26 | echo "Failed to Update Note with File<br>"; |
| 27 | 27 | echo "Response: ".$response->getStatus()."<br>"; |
| 28 | 28 | print_r($response->getBody()); |
| 29 | 29 | } |
| 30 | - }else{ |
|
| 30 | + } else{ |
|
| 31 | 31 | echo "Failed to create Note<br>"; |
| 32 | 32 | echo "Response: ".$response->getStatus()."<br>"; |
| 33 | 33 | print_r($response->getBody()); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | -}catch(\SugarAPI\SDK\Exception\SDKException $ex){ |
|
| 36 | +} catch(\SugarAPI\SDK\Exception\SDKException $ex){ |
|
| 37 | 37 | print $ex->getMessage(); |
| 38 | 38 | } |
| 39 | 39 | \ No newline at end of file |
@@ -1,69 +1,69 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -require_once __DIR__ . '/../vendor/autoload.php'; |
|
| 4 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
| 5 | 5 | |
| 6 | -try{ |
|
| 7 | - $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Pro/7700/',array('username' => 'admin','password'=>'asdf')); |
|
| 6 | +try { |
|
| 7 | + $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Pro/7700/', array('username' => 'admin', 'password'=>'asdf')); |
|
| 8 | 8 | $SugarAPI->login(); |
| 9 | 9 | $EP = $SugarAPI->filterRecords('Accounts'); |
| 10 | 10 | $response = $EP->execute()->getResponse(); |
| 11 | - if ($response->getStatus()=='200'){ |
|
| 11 | + if ($response->getStatus()=='200') { |
|
| 12 | 12 | $recordList = $response->getBody(); |
| 13 | - $max=count($recordList->records); |
|
| 13 | + $max = count($recordList->records); |
|
| 14 | 14 | echo "Found $max records from Filter Records request. <br>"; |
| 15 | - $number = rand(0,$max); |
|
| 15 | + $number = rand(0, $max); |
|
| 16 | 16 | $randomRecord = $recordList->records[$number]; |
| 17 | 17 | echo "Choose random record #$number, with ID: ".$randomRecord->id." <br>"; |
| 18 | 18 | |
| 19 | - $getRecord = $SugarAPI->getRecord('Accounts',$randomRecord->id)->data(array( |
|
| 19 | + $getRecord = $SugarAPI->getRecord('Accounts', $randomRecord->id)->data(array( |
|
| 20 | 20 | 'fields' => 'name' |
| 21 | 21 | ))->execute(); |
| 22 | 22 | $response = $getRecord->getResponse(); |
| 23 | - if ($response->getStatus()=='200'){ |
|
| 23 | + if ($response->getStatus()=='200') { |
|
| 24 | 24 | echo "Retrieved Record <br>"; |
| 25 | 25 | $randomRecord = $getRecord->getResponse()->getBody(); |
| 26 | 26 | |
| 27 | - $updateRecord = $SugarAPI->updateRecord('Accounts',$randomRecord->id)->data(array( |
|
| 27 | + $updateRecord = $SugarAPI->updateRecord('Accounts', $randomRecord->id)->data(array( |
|
| 28 | 28 | 'name' => 'Updated Record Name' |
| 29 | 29 | ))->execute(); |
| 30 | 30 | $response = $updateRecord->getResponse(); |
| 31 | - if ($response->getStatus()=='200'){ |
|
| 31 | + if ($response->getStatus()=='200') { |
|
| 32 | 32 | $randomRecord = $updateRecord->getResponse()->getBody(); |
| 33 | 33 | echo "Updated Record <br>"; |
| 34 | 34 | print_r($randomRecord); |
| 35 | 35 | |
| 36 | - $deleteRecord = $SugarAPI->deleteRecord('Accounts',$randomRecord->id)->execute(); |
|
| 36 | + $deleteRecord = $SugarAPI->deleteRecord('Accounts', $randomRecord->id)->execute(); |
|
| 37 | 37 | $response = $deleteRecord->getResponse(); |
| 38 | - if ($response->getStatus()=='200'){ |
|
| 38 | + if ($response->getStatus()=='200') { |
|
| 39 | 39 | $response = $deleteRecord->getResponse()->getBody(); |
| 40 | 40 | echo "Deleted Record <br>"; |
| 41 | 41 | print_r($response); |
| 42 | - }else{ |
|
| 42 | + }else { |
|
| 43 | 43 | echo "Failed to Delete record<br>"; |
| 44 | 44 | echo "Response: ".$response->getStatus()."<br>"; |
| 45 | 45 | print_r($response->getBody()); |
| 46 | 46 | } |
| 47 | - }else{ |
|
| 47 | + }else { |
|
| 48 | 48 | print_r($updateRecord->getRequest()); |
| 49 | 49 | echo "Failed to Update record<br>"; |
| 50 | 50 | echo "Response: ".$response->getStatus()."<br>"; |
| 51 | 51 | print_r($response->getBody()); |
| 52 | 52 | } |
| 53 | - }else{ |
|
| 53 | + }else { |
|
| 54 | 54 | echo "Failed to retrieve record<br>"; |
| 55 | 55 | echo "Response: ".$response->getStatus()."<br>"; |
| 56 | 56 | print_r($response->getBody()); |
| 57 | 57 | } |
| 58 | - }else{ |
|
| 58 | + }else { |
|
| 59 | 59 | echo "Response: ".$response->getStatus(); |
| 60 | 60 | print_r($response->getBody()); |
| 61 | 61 | } |
| 62 | -}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
| 62 | +}catch (\SugarAPI\SDK\Exception\AuthenticationException $ex) { |
|
| 63 | 63 | echo "Auth Options:<pre>"; |
| 64 | 64 | print_r($SugarAPI->getAuthOptions()); |
| 65 | 65 | echo "</pre> Error Message: "; |
| 66 | 66 | print $ex->getMessage(); |
| 67 | -}catch(\SugarAPI\SDK\Exception\SDKException $ex){ |
|
| 67 | +}catch (\SugarAPI\SDK\Exception\SDKException $ex) { |
|
| 68 | 68 | echo $ex->__toString(); |
| 69 | 69 | } |
@@ -39,31 +39,31 @@ |
||
| 39 | 39 | $response = $deleteRecord->getResponse()->getBody(); |
| 40 | 40 | echo "Deleted Record <br>"; |
| 41 | 41 | print_r($response); |
| 42 | - }else{ |
|
| 42 | + } else{ |
|
| 43 | 43 | echo "Failed to Delete record<br>"; |
| 44 | 44 | echo "Response: ".$response->getStatus()."<br>"; |
| 45 | 45 | print_r($response->getBody()); |
| 46 | 46 | } |
| 47 | - }else{ |
|
| 47 | + } else{ |
|
| 48 | 48 | print_r($updateRecord->getRequest()); |
| 49 | 49 | echo "Failed to Update record<br>"; |
| 50 | 50 | echo "Response: ".$response->getStatus()."<br>"; |
| 51 | 51 | print_r($response->getBody()); |
| 52 | 52 | } |
| 53 | - }else{ |
|
| 53 | + } else{ |
|
| 54 | 54 | echo "Failed to retrieve record<br>"; |
| 55 | 55 | echo "Response: ".$response->getStatus()."<br>"; |
| 56 | 56 | print_r($response->getBody()); |
| 57 | 57 | } |
| 58 | - }else{ |
|
| 58 | + } else{ |
|
| 59 | 59 | echo "Response: ".$response->getStatus(); |
| 60 | 60 | print_r($response->getBody()); |
| 61 | 61 | } |
| 62 | -}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
| 62 | +} catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
| 63 | 63 | echo "Auth Options:<pre>"; |
| 64 | 64 | print_r($SugarAPI->getAuthOptions()); |
| 65 | 65 | echo "</pre> Error Message: "; |
| 66 | 66 | print $ex->getMessage(); |
| 67 | -}catch(\SugarAPI\SDK\Exception\SDKException $ex){ |
|
| 67 | +} catch(\SugarAPI\SDK\Exception\SDKException $ex){ |
|
| 68 | 68 | echo $ex->__toString(); |
| 69 | 69 | } |
@@ -1,9 +1,9 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -require_once __DIR__ . '/../vendor/autoload.php'; |
|
| 3 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
| 4 | 4 | |
| 5 | -try{ |
|
| 6 | - $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Pro/7621/',array('username' => 'admin','password'=>'asdf')); |
|
| 5 | +try { |
|
| 6 | + $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Pro/7621/', array('username' => 'admin', 'password'=>'asdf')); |
|
| 7 | 7 | $SugarAPI->login(); |
| 8 | 8 | $EP = $SugarAPI->createRecord('Accounts'); |
| 9 | 9 | $EP->data(array( |
@@ -11,14 +11,14 @@ discard block |
||
| 11 | 11 | 'email1' => '[email protected]' |
| 12 | 12 | )); |
| 13 | 13 | $response = $EP->execute()->getResponse(); |
| 14 | - if ($response->getStatus()=='200'){ |
|
| 14 | + if ($response->getStatus()=='200') { |
|
| 15 | 15 | $record = $response->getBody(); |
| 16 | - $EP2 = $SugarAPI->getRecord('Accounts',$record->id)->data(array('fields' => 'name,email1')); |
|
| 16 | + $EP2 = $SugarAPI->getRecord('Accounts', $record->id)->data(array('fields' => 'name,email1')); |
|
| 17 | 17 | $getResponse = $EP2->execute()->getResponse(); |
| 18 | 18 | print $EP2->getUrl(); |
| 19 | 19 | print_r($getResponse->getBody()); |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | -}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
| 22 | +}catch (\SugarAPI\SDK\Exception\AuthenticationException $ex) { |
|
| 23 | 23 | print $ex->getMessage(); |
| 24 | 24 | } |
| 25 | 25 | \ No newline at end of file |
@@ -19,6 +19,6 @@ |
||
| 19 | 19 | print_r($getResponse->getBody()); |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | -}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
| 22 | +} catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
| 23 | 23 | print $ex->getMessage(); |
| 24 | 24 | } |
| 25 | 25 | \ No newline at end of file |